summaryrefslogtreecommitdiffstats
path: root/kinit/klauncher.h
blob: a9ed80f3be7279e936cf8dcd035b0324f66bf4a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
   This file is part of the KDE libraries
   Copyright (c) 1999 Waldo Bastian <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef _KLAUNCHER_H_
#define _KLAUNCHER_H_

#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <qstring.h>
#include <qvaluelist.h>
#include <qsocketnotifier.h>
#include <qptrlist.h>
#include <qtimer.h>

#include <dcopclient.h>
#include <kio/connection.h>
#include <ksock.h>
#include <kurl.h>
#include <kuniqueapplication.h>

#include <kservice.h>

#include "autostart.h"

class IdleSlave : public QObject
{
   Q_OBJECT
public:
   IdleSlave(KSocket *socket);
   bool match( const QString &protocol, const QString &host, bool connected);
   void connect( const QString &app_socket);
   pid_t pid() const { return mPid;}
   int age(time_t now);
   void reparseConfiguration();
   bool onHold(const KURL &url);
   QString protocol() const   {return mProtocol;}

signals:
   void statusUpdate(IdleSlave *);

protected slots:
   void gotInput();

protected:
   KIO::Connection mConn;
   QString mProtocol;
   QString mHost;
   bool mConnected;
   pid_t mPid;
   time_t mBirthDate;
   bool mOnHold;
   KURL mUrl;
};

class SlaveWaitRequest
{
public:
   pid_t pid;
   DCOPClientTransaction *transaction;
};

class KLaunchRequest
{
public:
   QCString name;
   QValueList<QCString> arg_list;
   QCString dcop_name;
   enum status_t { Init = 0, Launching, Running, Error, Done };
   pid_t pid;
   status_t status;
   DCOPClientTransaction *transaction;
   KService::DCOPServiceType_t dcop_service_type;
   bool autoStart;
   QString errorMsg;
#ifdef Q_WS_X11
   QCString startup_id; // "" is the default, "0" for none
   QCString startup_dpy; // Display to send startup notification to.
#endif
   QValueList<QCString> envs; // env. variables to be app's environment
   QCString cwd;
};

struct serviceResult
{
  int result;        // 0 means success. > 0 means error (-1 means pending)
  QCString dcopName; // Contains DCOP name on success
  QString error;     // Contains error description on failure.
  pid_t pid;
};

class KLauncher : public KApplication, public DCOPObject
{
   Q_OBJECT

public:
   KLauncher(int _kdeinitSocket, bool new_startup);

   ~KLauncher();

   void close();
   static void destruct(int exit_code); // exit!

   // DCOP
   virtual bool process(const QCString &fun, const QByteArray &data,
                QCString &replyType, QByteArray &replyData);
   virtual QCStringList functions();
   virtual QCStringList interfaces();

protected:
   void processDied(pid_t pid, long exitStatus);

   void requestStart(KLaunchRequest *request);
   void requestDone(KLaunchRequest *request);

   void setLaunchEnv(const QCString &name, const QCString &value);
   void exec_blind(const QCString &name, const QValueList<QCString> &arg_list,
       const QValueList<QCString> &envs, const QCString& startup_id = "" );
   bool start_service(KService::Ptr service, const QStringList &urls,
       const QValueList<QCString> &envs, const QCString& startup_id = "",
       bool blind = false, bool autoStart = false );
   bool start_service_by_name(const QString &serviceName, const QStringList &urls,
       const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
   bool start_service_by_desktop_path(const QString &serviceName, const QStringList &urls,
       const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
   bool start_service_by_desktop_name(const QString &serviceName, const QStringList &urls,
       const QValueList<QCString> &envs, const QCString& startup_id, bool blind);
   bool kdeinit_exec(const QString &app, const QStringList &args,
       const QValueList<QCString> &envs, QCString startup_id, bool wait);

   void waitForSlave(pid_t pid);

   void autoStart(int phase);

   void createArgs( KLaunchRequest *request, const KService::Ptr service,
                    const QStringList &url);

   pid_t requestHoldSlave(const KURL &url, const QString &app_socket);
   pid_t requestSlave(const QString &protocol, const QString &host,
                      const QString &app_socket, QString &error);


   void queueRequest(KLaunchRequest *);

   void send_service_startup_info( KLaunchRequest *request, KService::Ptr service, const QCString& startup_id,
       const QValueList<QCString> &envs );
   void cancel_service_startup_info( KLaunchRequest *request, const QCString& startup_id,
       const QValueList<QCString> &envs );

public slots:
   void slotAutoStart();
   void slotDequeue();
   void slotKDEInitData(int);
   void slotAppRegistered(const QCString &appId);
   void slotSlaveStatus(IdleSlave *);
   void acceptSlave( KSocket *);
   void slotSlaveGone();
   void idleTimeout();

protected:
   QPtrList<KLaunchRequest> requestList; // Requests being handled
   QPtrList<KLaunchRequest> requestQueue; // Requests waiting to being handled
   int kdeinitSocket;
   QSocketNotifier *kdeinitNotifier;
   serviceResult DCOPresult;
   KLaunchRequest *lastRequest;
   QPtrList<SlaveWaitRequest> mSlaveWaitRequest;
   QString mPoolSocketName;
   KServerSocket *mPoolSocket;
   QPtrList<IdleSlave> mSlaveList;
   QTimer mTimer;
   QTimer mAutoTimer;
   bool bProcessingQueue;
   AutoStart mAutoStart;
   QCString mSlaveDebug;
   QCString mSlaveValgrind;
   QCString mSlaveValgrindSkin;
   bool dontBlockReading;
   bool newStartup;
#ifdef Q_WS_X11
   Display *mCached_dpy;
#endif
};
#endif