KInit
klauncher.h
Go to the documentation of this file.
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (c) 1999 Waldo Bastian <bastian@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 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 QString tolerant_dbus_name; 00091 enum status_t { Init = 0, Launching, Running, Error, Done }; 00092 pid_t pid; 00093 status_t status; 00094 QDBusMessage transaction; 00095 KService::DBusStartupType dbus_startup_type; 00096 bool autoStart; 00097 QString errorMsg; 00098 #ifdef Q_WS_X11 00099 QByteArray startup_id; // "" is the default, "0" for none 00100 QByteArray startup_dpy; // Display to send startup notification to. 00101 #endif 00102 QStringList envs; // env. variables to be app's environment 00103 QString cwd; 00104 #ifdef Q_WS_WIN 00105 protected: 00106 KProcess *process; 00107 friend class KLauncher; 00108 #endif 00109 }; 00110 00111 struct serviceResult 00112 { 00113 int result; // 0 means success. > 0 means error (-1 means pending) 00114 QString dbusName; // Contains DBUS name on success 00115 QString error; // Contains error description on failure. 00116 pid_t pid; 00117 }; 00118 00119 class KLauncher : public QObject 00120 { 00121 Q_OBJECT 00122 00123 public: 00124 #ifndef Q_WS_WIN 00125 KLauncher(int kdeinitSocket); 00126 #else 00127 KLauncher(); 00128 #endif 00129 00130 ~KLauncher(); 00131 00132 void close(); 00133 00134 public slots: 00135 void destruct(); // exit! 00136 00137 protected: 00138 void processDied(pid_t pid, long exitStatus); 00139 00140 void requestStart(KLaunchRequest *request); 00141 void requestDone(KLaunchRequest *request); 00142 00143 bool start_service(KService::Ptr service, const QStringList &urls, 00144 const QStringList &envs, const QByteArray &startup_id, 00145 bool blind, bool autoStart, const QDBusMessage &msg ); 00146 00147 void createArgs( KLaunchRequest *request, const KService::Ptr service, 00148 const QStringList &url); 00149 00150 void queueRequest(KLaunchRequest *); 00151 00152 void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QByteArray &startup_id, 00153 const QStringList &envs ); 00154 void cancel_service_startup_info( KLaunchRequest *request, const QByteArray& startup_id, 00155 const QStringList &envs ); 00156 00157 Q_SIGNALS: 00158 void autoStart0Done(); 00159 void autoStart1Done(); 00160 void autoStart2Done(); 00161 00162 public: // remote methods, called by KLauncherAdaptor 00163 void autoStart(int phase = 1); 00164 00172 void exec_blind(const QString &name, const QStringList &arg_list, const QStringList &envs, const QString &startup_id); 00173 inline void exec_blind(const QString &name, const QStringList &arg_list) 00174 { exec_blind(name, arg_list, QStringList(), QLatin1String("0")); } 00175 00176 bool kdeinit_exec(const QString &app, const QStringList &args, 00177 const QString& workdir, const QStringList &envs, 00178 const QString &startup_id, bool wait, const QDBusMessage &msg); 00179 00180 void reparseConfiguration(); 00181 void setLaunchEnv(const QString &name, const QString &value); 00182 00200 bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg); 00201 00222 bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg); 00223 00241 bool start_service_by_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg); // KDE5: remove 00242 00243 pid_t requestHoldSlave(const KUrl &url, const QString &app_socket); 00244 00245 pid_t requestSlave(const QString &protocol, const QString &host, 00246 const QString &app_socket, QString &error); 00247 void waitForSlave(int pid, const QDBusMessage &msg); 00248 void terminate_kdeinit(); 00249 00250 public Q_SLOTS: 00251 void slotAutoStart(); 00252 void slotDequeue(); 00253 #ifndef Q_WS_WIN 00254 void slotKDEInitData(int); 00255 #endif 00256 void slotNameOwnerChanged(const QString &name, const QString &oldOnwer, const QString &newOwner); 00257 void slotSlaveStatus(IdleSlave *); 00258 void acceptSlave(); 00259 void slotSlaveGone(); 00260 void idleTimeout(); 00261 00262 public: 00263 serviceResult requestResult; // accessed by the adaptor 00264 protected: 00265 QList<KLaunchRequest*> requestList; // Requests being handled 00266 QList<KLaunchRequest*> requestQueue; // Requests waiting to being handled 00267 KLaunchRequest *lastRequest; 00268 QList<SlaveWaitRequest*> mSlaveWaitRequest; 00269 #ifndef Q_WS_WIN 00270 int kdeinitSocket; 00271 QSocketNotifier *kdeinitNotifier; 00272 #endif 00273 KIO::ConnectionServer mConnectionServer; 00274 QList<IdleSlave*> mSlaveList; 00275 QTimer mTimer; 00276 QTimer mAutoTimer; 00277 bool bProcessingQueue; 00278 AutoStart mAutoStart; 00279 QString mSlaveDebug; 00280 QString mSlaveValgrind; 00281 QString mSlaveValgrindSkin; 00282 bool dontBlockReading; 00283 #ifdef Q_WS_X11 00284 Display *mCached_dpy; 00285 #endif 00286 void processRequestReturn(int status, const QByteArray &requestData); 00287 00288 protected Q_SLOTS: 00289 #ifdef Q_WS_WIN 00290 void slotGotOutput(); 00291 void slotFinished(int exitCode, QProcess::ExitStatus exitStatus); 00292 #endif 00293 }; 00294 #endif
KDE 4.6 API Reference