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 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) 00035 #define USE_KPROCESS_FOR_KIOSLAVES 00036 #endif 00037 00038 #include <QtCore/QString> 00039 #include <QtCore/QSocketNotifier> 00040 #include <QtCore/QTimer> 00041 #include <QtCore/QList> 00042 #include <QtCore/QObject> 00043 #include <QtDBus/QtDBus> 00044 00045 #include <kservice.h> 00046 #include <kprocess.h> 00047 #include <kurl.h> 00048 #include <kio/connection.h> 00049 00050 class IdleSlave : public QObject 00051 { 00052 Q_OBJECT 00053 public: 00054 explicit IdleSlave(QObject *parent); 00055 bool match( const QString &protocol, const QString &host, bool connected); 00056 void connect( const QString &app_socket); 00057 pid_t pid() const { return mPid;} 00058 int age(time_t now); 00059 void reparseConfiguration(); 00060 bool onHold(const KUrl &url); 00061 QString protocol() const {return mProtocol;} 00062 00063 Q_SIGNALS: 00064 void statusUpdate(IdleSlave *); 00065 00066 protected Q_SLOTS: 00067 void gotInput(); 00068 00069 public: 00070 KIO::Connection mConn; 00071 protected: 00072 QString mProtocol; 00073 QString mHost; 00074 bool mConnected; 00075 pid_t mPid; 00076 time_t mBirthDate; 00077 bool mOnHold; 00078 KUrl mUrl; 00079 }; 00080 00081 class SlaveWaitRequest 00082 { 00083 public: 00084 pid_t pid; 00085 QDBusMessage transaction; 00086 }; 00087 00088 class KLaunchRequest 00089 { 00090 public: 00091 QString name; 00092 QStringList arg_list; 00093 QString dbus_name; 00094 QString tolerant_dbus_name; 00095 enum status_t { Init = 0, Launching, Running, Error, Done }; 00096 pid_t pid; 00097 status_t status; 00098 QDBusMessage transaction; 00099 KService::DBusStartupType dbus_startup_type; 00100 bool autoStart; 00101 QString errorMsg; 00102 #ifdef Q_WS_X11 00103 QByteArray startup_id; // "" is the default, "0" for none 00104 QByteArray startup_dpy; // Display to send startup notification to. 00105 #endif 00106 QStringList envs; // env. variables to be app's environment 00107 QString cwd; 00108 #ifdef USE_KPROCESS_FOR_KIOSLAVES 00109 protected: 00110 KProcess *process; 00111 friend class KLauncher; 00112 #endif 00113 }; 00114 00115 struct serviceResult 00116 { 00117 int result; // 0 means success. > 0 means error (-1 means pending) 00118 QString dbusName; // Contains DBUS name on success 00119 QString error; // Contains error description on failure. 00120 pid_t pid; 00121 }; 00122 00123 class KLauncher : public QObject 00124 { 00125 Q_OBJECT 00126 00127 public: 00128 #ifndef USE_KPROCESS_FOR_KIOSLAVES 00129 KLauncher(int kdeinitSocket); 00130 #else 00131 KLauncher(); 00132 #endif 00133 00134 ~KLauncher(); 00135 00136 void close(); 00137 00138 public slots: 00139 void destruct(); // exit! 00140 00141 protected: 00142 void processDied(pid_t pid, long exitStatus); 00143 00144 void requestStart(KLaunchRequest *request); 00145 void requestDone(KLaunchRequest *request); 00146 00147 bool start_service(KService::Ptr service, const QStringList &urls, 00148 const QStringList &envs, const QByteArray &startup_id, 00149 bool blind, bool autoStart, const QDBusMessage &msg ); 00150 00151 void createArgs( KLaunchRequest *request, const KService::Ptr service, 00152 const QStringList &url); 00153 00154 void queueRequest(KLaunchRequest *); 00155 00156 void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QByteArray &startup_id, 00157 const QStringList &envs ); 00158 void cancel_service_startup_info( KLaunchRequest *request, const QByteArray& startup_id, 00159 const QStringList &envs ); 00160 00161 Q_SIGNALS: 00162 void autoStart0Done(); 00163 void autoStart1Done(); 00164 void autoStart2Done(); 00165 00166 public: // remote methods, called by KLauncherAdaptor 00167 void autoStart(int phase = 1); 00168 00176 void exec_blind(const QString &name, const QStringList &arg_list, const QStringList &envs, const QString &startup_id); 00177 inline void exec_blind(const QString &name, const QStringList &arg_list) 00178 { exec_blind(name, arg_list, QStringList(), QLatin1String("0")); } 00179 00180 bool kdeinit_exec(const QString &app, const QStringList &args, 00181 const QString& workdir, const QStringList &envs, 00182 const QString &startup_id, bool wait, const QDBusMessage &msg); 00183 00184 void reparseConfiguration(); 00185 void setLaunchEnv(const QString &name, const QString &value); 00186 00204 bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg); 00205 00226 bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg); 00227 00245 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 00246 00247 pid_t requestHoldSlave(const KUrl &url, const QString &app_socket); 00248 00249 pid_t requestSlave(const QString &protocol, const QString &host, 00250 const QString &app_socket, QString &error); 00251 void waitForSlave(int pid, const QDBusMessage &msg); 00252 void terminate_kdeinit(); 00253 00254 public Q_SLOTS: 00255 void slotAutoStart(); 00256 void slotDequeue(); 00257 void slotKDEInitData(int); 00258 void slotNameOwnerChanged(const QString &name, const QString &oldOnwer, const QString &newOwner); 00259 void slotSlaveStatus(IdleSlave *); 00260 void acceptSlave(); 00261 void slotSlaveGone(); 00262 void idleTimeout(); 00263 00264 public: 00265 serviceResult requestResult; // accessed by the adaptor 00266 protected: 00267 QList<KLaunchRequest*> requestList; // Requests being handled 00268 QList<KLaunchRequest*> requestQueue; // Requests waiting to being handled 00269 KLaunchRequest *lastRequest; 00270 QList<SlaveWaitRequest*> mSlaveWaitRequest; 00271 #ifndef USE_KPROCESS_FOR_KIOSLAVES 00272 int kdeinitSocket; 00273 QSocketNotifier *kdeinitNotifier; 00274 #endif 00275 KIO::ConnectionServer mConnectionServer; 00276 QList<IdleSlave*> mSlaveList; 00277 QTimer mTimer; 00278 QTimer mAutoTimer; 00279 bool bProcessingQueue; 00280 AutoStart mAutoStart; 00281 QString mSlaveDebug; 00282 QString mSlaveValgrind; 00283 QString mSlaveValgrindSkin; 00284 bool dontBlockReading; 00285 #ifdef Q_WS_X11 00286 Display *mCached_dpy; 00287 #endif 00288 void processRequestReturn(int status, const QByteArray &requestData); 00289 00290 protected Q_SLOTS: 00291 void slotGotOutput(); 00292 void slotFinished(int exitCode, QProcess::ExitStatus exitStatus); 00293 }; 00294 #endif
KDE 4.6 API Reference