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 <sys/types.h>
00024 #include <unistd.h>
00025 #include <time.h>
00026 #include <qstring.h>
00027 #include <qvaluelist.h>
00028 #include <qsocketnotifier.h>
00029 #include <qptrlist.h>
00030 #include <qtimer.h>
00031
00032 #include <dcopclient.h>
00033 #include <kio/connection.h>
00034 #include <ksock.h>
00035 #include <kurl.h>
00036 #include <kuniqueapplication.h>
00037
00038 #include <kservice.h>
00039
00040 #include "autostart.h"
00041
00042 class IdleSlave : public QObject
00043 {
00044 Q_OBJECT
00045 public:
00046 IdleSlave(KSocket *socket);
00047 bool match( const QString &protocol, const QString &host, bool connected);
00048 void connect( const QString &app_socket);
00049 pid_t pid() const { return mPid;}
00050 int age(time_t now);
00051 void reparseConfiguration();
00052 bool onHold(const KURL &url);
00053 QString protocol() const {return mProtocol;}
00054
00055 signals:
00056 void statusUpdate(IdleSlave *);
00057
00058 protected slots:
00059 void gotInput();
00060
00061 protected:
00062 KIO::Connection mConn;
00063 QString mProtocol;
00064 QString mHost;
00065 bool mConnected;
00066 pid_t mPid;
00067 time_t mBirthDate;
00068 bool mOnHold;
00069 KURL mUrl;
00070 };
00071
00072 class SlaveWaitRequest
00073 {
00074 public:
00075 pid_t pid;
00076 DCOPClientTransaction *transaction;
00077 };
00078
00079 class KLaunchRequest
00080 {
00081 public:
00082 QCString name;
00083 QValueList<QCString> arg_list;
00084 QCString dcop_name;
00085 enum status_t { Init = 0, Launching, Running, Error, Done };
00086 pid_t pid;
00087 status_t status;
00088 DCOPClientTransaction *transaction;
00089 KService::DCOPServiceType_t dcop_service_type;
00090 bool autoStart;
00091 QString errorMsg;
00092 #ifdef Q_WS_X11
00093 QCString startup_id;
00094 QCString startup_dpy;
00095 #endif
00096 QValueList<QCString> envs;
00097 QCString cwd;
00098 };
00099
00100 struct serviceResult
00101 {
00102 int result;
00103 QCString dcopName;
00104 QString error;
00105 pid_t pid;
00106 };
00107
00108 class KLauncher : public KApplication, public DCOPObject
00109 {
00110 Q_OBJECT
00111
00112 public:
00113 KLauncher(int _kdeinitSocket, bool new_startup);
00114
00115 ~KLauncher();
00116
00117 void close();
00118 static void destruct(int exit_code);
00119
00120
00121 virtual bool process(const QCString &fun, const QByteArray &data,
00122 QCString &replyType, QByteArray &replyData);
00123 virtual QCStringList functions();
00124 virtual QCStringList interfaces();
00125
00126 protected:
00127 void processDied(pid_t pid, long exitStatus);
00128
00129 void requestStart(KLaunchRequest *request);
00130 void requestDone(KLaunchRequest *request);
00131
00132 void setLaunchEnv(const QCString &name, const QCString &value);
00133 void exec_blind(const QCString &name, const QValueList<QCString> &arg_list,
00134 const QValueList<QCString> &envs, const QCString& startup_id = "" );
00135 bool start_service(KService::Ptr service, const QStringList &urls,
00136 const QValueList<QCString> &envs, const QCString& startup_id = "",
00137 bool blind = false, bool autoStart = false );
00138 bool start_service_by_name(const QString &serviceName, const QStringList &urls,
00139 const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
00140 bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls,
00141 const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
00142 bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls,
00143 const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
00144 bool kdeinit_exec(const QString &app, const QStringList &args,
00145 const QValueList<QCString> &envs, QCString startup_id, bool wait);
00146
00147 void waitForSlave(pid_t pid);
00148
00149 void autoStart(int phase);
00150
00151 void createArgs( KLaunchRequest *request, const KService::Ptr service,
00152 const QStringList &url);
00153
00154 pid_t requestHoldSlave(const KURL &url, const QString &app_socket);
00155 pid_t requestSlave(const QString &protocol, const QString &host,
00156 const QString &app_socket, QString &error);
00157
00158
00159 void queueRequest(KLaunchRequest *);
00160
00161 void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QCString& startup_id,
00162 const QValueList<QCString> &envs );
00163 void cancel_service_startup_info( KLaunchRequest *request, const QCString& startup_id,
00164 const QValueList<QCString> &envs );
00165
00166 public slots:
00167 void slotAutoStart();
00168 void slotDequeue();
00169 void slotKDEInitData(int);
00170 void slotAppRegistered(const QCString &appId);
00171 void slotSlaveStatus(IdleSlave *);
00172 void acceptSlave( KSocket *);
00173 void slotSlaveGone();
00174 void idleTimeout();
00175
00176 protected:
00177 QPtrList<KLaunchRequest> requestList;
00178 QPtrList<KLaunchRequest> requestQueue;
00179 int kdeinitSocket;
00180 QSocketNotifier *kdeinitNotifier;
00181 serviceResult DCOPresult;
00182 KLaunchRequest *lastRequest;
00183 QPtrList<SlaveWaitRequest> mSlaveWaitRequest;
00184 QString mPoolSocketName;
00185 KServerSocket *mPoolSocket;
00186 QPtrList<IdleSlave> mSlaveList;
00187 QTimer mTimer;
00188 QTimer mAutoTimer;
00189 bool bProcessingQueue;
00190 AutoStart mAutoStart;
00191 QCString mSlaveDebug;
00192 QCString mSlaveValgrind;
00193 QCString mSlaveValgrindSkin;
00194 bool dontBlockReading;
00195 bool newStartup;
00196 #ifdef Q_WS_X11
00197 Display *mCached_dpy;
00198 #endif
00199 };
00200 #endif