fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kinit / klauncher.h
blob4ccd3c7509e6a3d9992ed6be442e54239bff1add
1 /*
2 This file is part of the KDE libraries
3 Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef _KLAUNCHER_H_
21 #define _KLAUNCHER_H_
23 #include "autostart.h"
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <time.h>
29 #ifdef Q_WS_X11
30 #include <X11/Xlib.h>
31 #include <fixx11h.h>
32 #endif
34 #include <QtCore/QString>
35 #include <QtCore/QSocketNotifier>
36 #include <QtCore/QTimer>
37 #include <QtCore/QList>
38 #include <QtCore/QObject>
39 #include <QtDBus/QtDBus>
41 #include <kservice.h>
42 #include <kprocess.h>
43 #include <kurl.h>
44 #include <kio/connection.h>
46 class IdleSlave : public QObject
48 Q_OBJECT
49 public:
50 explicit IdleSlave(QObject *parent);
51 bool match( const QString &protocol, const QString &host, bool connected);
52 void connect( const QString &app_socket);
53 pid_t pid() const { return mPid;}
54 int age(time_t now);
55 void reparseConfiguration();
56 bool onHold(const KUrl &url);
57 QString protocol() const {return mProtocol;}
59 Q_SIGNALS:
60 void statusUpdate(IdleSlave *);
62 protected Q_SLOTS:
63 void gotInput();
65 public:
66 KIO::Connection mConn;
67 protected:
68 QString mProtocol;
69 QString mHost;
70 bool mConnected;
71 pid_t mPid;
72 time_t mBirthDate;
73 bool mOnHold;
74 KUrl mUrl;
77 class SlaveWaitRequest
79 public:
80 pid_t pid;
81 QDBusMessage transaction;
84 class KLaunchRequest
86 public:
87 QString name;
88 QStringList arg_list;
89 QString dbus_name;
90 QString tolerant_dbus_name;
91 enum status_t { Init = 0, Launching, Running, Error, Done };
92 pid_t pid;
93 status_t status;
94 QDBusMessage transaction;
95 KService::DBusStartupType dbus_startup_type;
96 bool autoStart;
97 QString errorMsg;
98 #ifdef Q_WS_X11
99 QByteArray startup_id; // "" is the default, "0" for none
100 QByteArray startup_dpy; // Display to send startup notification to.
101 #endif
102 QStringList envs; // env. variables to be app's environment
103 QString cwd;
104 #ifdef Q_WS_WIN
105 protected:
106 KProcess *process;
107 friend class KLauncher;
108 #endif
111 struct serviceResult
113 int result; // 0 means success. > 0 means error (-1 means pending)
114 QString dbusName; // Contains DBUS name on success
115 QString error; // Contains error description on failure.
116 pid_t pid;
119 class KLauncher : public QObject
121 Q_OBJECT
123 public:
124 KLauncher(int kdeinitSocket);
126 ~KLauncher();
128 void close();
130 public slots:
131 void destruct(); // exit!
133 protected:
134 void processDied(pid_t pid, long exitStatus);
136 void requestStart(KLaunchRequest *request);
137 void requestDone(KLaunchRequest *request);
139 bool start_service(KService::Ptr service, const QStringList &urls,
140 const QStringList &envs, const QByteArray &startup_id,
141 bool blind, bool autoStart, const QDBusMessage &msg );
143 void createArgs( KLaunchRequest *request, const KService::Ptr service,
144 const QStringList &url);
146 void queueRequest(KLaunchRequest *);
148 void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QByteArray &startup_id,
149 const QStringList &envs );
150 void cancel_service_startup_info( KLaunchRequest *request, const QByteArray& startup_id,
151 const QStringList &envs );
153 Q_SIGNALS:
154 void autoStart0Done();
155 void autoStart1Done();
156 void autoStart2Done();
158 public: // remote methods, called by KLauncherAdaptor
159 void autoStart(int phase = 1);
162 * Starts a program.
163 * 'envs' are environment variables that will be added
164 * to this program's environment before starting it
165 * 'startup_id' is for application startup notification,
166 * "" is the default, "0" for none
168 void exec_blind(const QString &name, const QStringList &arg_list, const QStringList &envs, const QString &startup_id);
169 inline void exec_blind(const QString &name, const QStringList &arg_list)
170 { exec_blind(name, arg_list, QStringList(), QLatin1String("0")); }
172 bool kdeinit_exec(const QString &app, const QStringList &args,
173 const QString& workdir, const QStringList &envs,
174 const QString &startup_id, bool wait, const QDBusMessage &msg);
176 void reparseConfiguration();
177 void setLaunchEnv(const QString &name, const QString &value);
180 * Start a service by desktop name.
182 * 'serviceName' refers to a desktop file describing the service.
183 * The service is looked up anywhere in $KDEDIR/applnk and/or
184 * $KDEDIR/services.
185 * E.g. it should have the form "korganizer".
187 * 'url', if not empty, will be passed to the service as
188 * argument.
190 * 'envs' are environment variables that will be added
191 * to this program's environment before starting it
193 * 'startup_id' is for application startup notification,
194 * "" is the default, "0" for none
196 bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg);
199 * Start a service by desktop path.
201 * 'serviceName' refers to a desktop file describing the service.
202 * This may be an absolute path or a path relative to $KDEDIRS/applnk
203 * and/or $KDEDIRS/services
204 * E.g. it should have the form "Applications/korganizer.desktop" or
205 * "/opt/kde/share/applnk/Applications/korganizer.desktop".
206 * Note that for absolute paths the restrictions of
207 * KDesktopFile::isAuthorizedDesktopFile() are obeyed for security.
209 * 'url', if not empty, will be passed to the service as
210 * argument.
212 * 'envs' are environment variables that will be added
213 * to this program's environment before starting it
215 * 'startup_id' is for application startup notification,
216 * "" is the default, "0" for none
218 bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls, const QStringList &envs, const QString &startup_id, bool blind, const QDBusMessage &msg);
221 * Start a service by (translated) name - deprecated
223 * 'serviceName' refers to the service name as given by·
224 * the Name field in the desktop file describing the service.
226 * 'url', if not empty, will be passed to the service as
227 * argument.
229 * 'envs' are environment variables that will be added
230 * to this program's environment before starting it
232 * 'startup_id' is for application startup notification,
233 * "" is the default, "0" for none
235 * @deprecated use start_service_by_desktop_path
237 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
239 pid_t requestHoldSlave(const KUrl &url, const QString &app_socket);
241 pid_t requestSlave(const QString &protocol, const QString &host,
242 const QString &app_socket, QString &error);
243 void waitForSlave(int pid, const QDBusMessage &msg);
245 public Q_SLOTS:
246 void slotAutoStart();
247 void slotDequeue();
248 #ifndef Q_WS_WIN
249 void slotKDEInitData(int);
250 #endif
251 void slotNameOwnerChanged(const QString &name, const QString &oldOnwer, const QString &newOwner);
252 void slotSlaveStatus(IdleSlave *);
253 void acceptSlave();
254 void slotSlaveGone();
255 void idleTimeout();
257 public:
258 serviceResult requestResult; // accessed by the adaptor
259 protected:
260 QList<KLaunchRequest*> requestList; // Requests being handled
261 QList<KLaunchRequest*> requestQueue; // Requests waiting to being handled
262 KLaunchRequest *lastRequest;
263 QList<SlaveWaitRequest*> mSlaveWaitRequest;
264 int kdeinitSocket;
265 #ifndef Q_WS_WIN
266 QSocketNotifier *kdeinitNotifier;
267 #endif
268 KIO::ConnectionServer mConnectionServer;
269 QList<IdleSlave*> mSlaveList;
270 QTimer mTimer;
271 QTimer mAutoTimer;
272 bool bProcessingQueue;
273 AutoStart mAutoStart;
274 QString mSlaveDebug;
275 QString mSlaveValgrind;
276 QString mSlaveValgrindSkin;
277 bool dontBlockReading;
278 #ifdef Q_WS_X11
279 Display *mCached_dpy;
280 #endif
281 void processRequestReturn(int status, const QByteArray &requestData);
283 protected Q_SLOTS:
284 #ifdef Q_WS_WIN
285 void slotGotOutput();
286 void slotFinished(int exitCode, QProcess::ExitStatus exitStatus);
287 #endif
289 #endif