00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _KLAUNCHER_H_
00021 #define _KLAUNCHER_H_
00022
00023 #include "autostart.h"
00024
00025 #include <sys/types.h>
00026 #include <unistd.h>
00027 #include <time.h>
00028
00029 #ifdef Q_WS_X11
00030 #include <X11/Xlib.h>
00031 #include <fixx11h.h>
00032 #endif
00033
00034 #include <QtCore/QString>
00035 #include <QtCore/QSocketNotifier>
00036 #include <QtCore/QTimer>
00037 #include <QtCore/QList>
00038 #include <QtCore/QObject>
00039 #include <QtDBus/QtDBus>
00040
00041 #include <kservice.h>
00042 #include <kprocess.h>
00043 #include <kurl.h>
00044 #include <kio/connection.h>
00045
00046 class IdleSlave : public QObject
00047 {
00048 Q_OBJECT
00049 public:
00050 explicit IdleSlave(QObject *parent);
00051 bool match( const QString &protocol, const QString &host, bool connected);
00052 void connect( const QString &app_socket);
00053 pid_t pid() const { return mPid;}
00054 int age(time_t now);
00055 void reparseConfiguration();
00056 bool onHold(const KUrl &url);
00057 QString protocol() const {return mProtocol;}
00058
00059 Q_SIGNALS:
00060 void statusUpdate(IdleSlave *);
00061
00062 protected Q_SLOTS:
00063 void gotInput();
00064
00065 public:
00066 KIO::Connection mConn;
00067 protected:
00068 QString mProtocol;
00069 QString mHost;
00070 bool mConnected;
00071 pid_t mPid;
00072 time_t mBirthDate;
00073 bool mOnHold;
00074 KUrl mUrl;
00075 };
00076
00077 class SlaveWaitRequest
00078 {
00079 public:
00080 pid_t pid;
00081 QDBusMessage transaction;
00082 };
00083
00084 class KLaunchRequest
00085 {
00086 public:
00087 QString name;
00088 QStringList arg_list;
00089 QString dbus_name;
00090 enum status_t { Init = 0, Launching, Running, Error, Done };
00091 pid_t pid;
00092 status_t status;
00093 QDBusMessage transaction;
00094 KService::DBusStartupType dbus_startup_type;
00095 bool autoStart;
00096 QString errorMsg;
00097 #ifdef Q_WS_X11
00098 QString startup_id;
00099 QString startup_dpy;
00100 #endif
00101 QStringList envs;
00102 QString cwd;
00103 #ifdef Q_WS_WIN
00104 protected:
00105 KProcess *process;
00106 friend class KLauncher;
00107 #endif
00108 };
00109
00110 struct serviceResult
00111 {
00112 int result;
00113 QString dbusName;
00114 QString error;
00115 pid_t pid;
00116 };
00117
00118 class KLauncher : public QObject
00119 {
00120 Q_OBJECT
00121
00122 public:
00123 KLauncher(int kdeinitSocket);
00124
00125 ~KLauncher();
00126
00127 void close();
00128
00129 public slots:
00130 void destruct();
00131
00132 protected:
00133 void processDied(pid_t pid, long exitStatus);
00134
00135 void requestStart(KLaunchRequest *request);
00136 void requestDone(KLaunchRequest *request);
00137
00138 bool start_service(KService::Ptr service, const QStringList &urls,
00139 const QStringList &envs, const QString &startup_id,
00140 bool blind, bool autoStart, const QDBusMessage &msg );
00141
00142 void createArgs( KLaunchRequest *request, const KService::Ptr service,
00143 const QStringList &url);
00144
00145 void queueRequest(KLaunchRequest *);
00146
00147 void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QString &startup_id,
00148 const QStringList &envs );
00149 void cancel_service_startup_info( KLaunchRequest *request, const QString& startup_id,
00150 const QStringList &envs );
00151
00152 Q_SIGNALS:
00153 void autoStart0Done();
00154 void autoStart1Done();
00155 void autoStart2Done();
00156
00157 public:
00158 void autoStart(int phase = 1);
00159
00167 void exec_blind(const QString &name, const QStringList &arg_list, const QStringList &envs, const QString &startup_id);
00168 inline void exec_blind(const QString &name, const QStringList &arg_list)
00169 { exec_blind(name, arg_list, QStringList(), QLatin1String("0")); }
00170
00171 bool kdeinit_exec(const QString &app, const QStringList &args,
00172 const QString& workdir, const QStringList &envs,
00173 const QString &startup_id, bool wait, const QDBusMessage &msg);
00174
00175 void reparseConfiguration();
00176 void setLaunchEnv(const QString &name, const QString &value);
00177
00195 bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg);
00196
00215 bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg);
00216
00234 bool start_service_by_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg);
00235
00236 pid_t requestHoldSlave(const KUrl &url, const QString &app_socket);
00237
00238 pid_t requestSlave(const QString &protocol, const QString &host,
00239 const QString &app_socket, QString &error);
00240 void waitForSlave(int pid, const QDBusMessage &msg);
00241
00242 public Q_SLOTS:
00243 void slotAutoStart();
00244 void slotDequeue();
00245 #ifndef Q_WS_WIN
00246 void slotKDEInitData(int);
00247 #endif
00248 void slotNameOwnerChanged(const QString &name, const QString &oldOnwer, const QString &newOwner);
00249 void slotSlaveStatus(IdleSlave *);
00250 void acceptSlave();
00251 void slotSlaveGone();
00252 void idleTimeout();
00253
00254 public:
00255 serviceResult requestResult;
00256 protected:
00257 QList<KLaunchRequest*> requestList;
00258 QList<KLaunchRequest*> requestQueue;
00259 KLaunchRequest *lastRequest;
00260 QList<SlaveWaitRequest*> mSlaveWaitRequest;
00261 int kdeinitSocket;
00262 #ifndef Q_WS_WIN
00263 QSocketNotifier *kdeinitNotifier;
00264 #endif
00265 KIO::ConnectionServer mConnectionServer;
00266 QList<IdleSlave*> mSlaveList;
00267 QTimer mTimer;
00268 QTimer mAutoTimer;
00269 bool bProcessingQueue;
00270 AutoStart mAutoStart;
00271 QString mSlaveDebug;
00272 QString mSlaveValgrind;
00273 QString mSlaveValgrindSkin;
00274 bool dontBlockReading;
00275 #ifdef Q_WS_X11
00276 Display *mCached_dpy;
00277 #endif
00278 void processRequestReturn(int status, const QByteArray &requestData);
00279
00280 protected Q_SLOTS:
00281 #ifdef Q_WS_WIN
00282 void slotGotOutput();
00283 void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
00284 #endif
00285 };
00286 #endif