summaryrefslogtreecommitdiffstats
path: root/kinit/klauncher.h
blob: e681939e1c47902f6cf575de1fa81f36d31b811e (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 <bastian@kde.org>

   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 <tqstring.h>
#include <tqvaluelist.h>
#include <tqsocketnotifier.h>
#include <tqptrlist.h>
#include <tqtimer.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 TQString &protocol, const TQString &host, bool connected);
   void connect( const TQString &app_socket);
   pid_t pid() const { return mPid;}
   int age(time_t now);
   void reparseConfiguration();
   bool onHold(const KURL &url);
   TQString protocol() const   {return mProtocol;}

signals:
   void statusUpdate(IdleSlave *);

protected slots:
   void gotInput();

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

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

class KLaunchRequest
{
public:
   TQCString name;
   TQValueList<TQCString> arg_list;
   TQCString 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;
   TQString errorMsg;
#ifdef Q_WS_X11
   TQCString startup_id; // "" is the default, "0" for none
   TQCString startup_dpy; // Display to send startup notification to.
#endif
   TQValueList<TQCString> envs; // env. variables to be app's environment
   TQCString cwd;
};

struct serviceResult
{
  int result;        // 0 means success. > 0 means error (-1 means pending)
  TQCString dcopName; // Contains DCOP name on success
  TQString 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 TQCString &fun, const TQByteArray &data,
                TQCString &replyType, TQByteArray &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 TQCString &name, const TQCString &value);
   void exec_blind(const TQCString &name, const TQValueList<TQCString> &arg_list,
       const TQValueList<TQCString> &envs, const TQCString& startup_id = "" );
   bool start_service(KService::Ptr service, const TQStringList &urls,
       const TQValueList<TQCString> &envs, const TQCString& startup_id = "",
       bool blind = false, bool autoStart = false );
   bool start_service_by_name(const TQString &serviceName, const TQStringList &urls,
       const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind);
   bool start_service_by_desktop_path(const TQString &serviceName, const TQStringList &urls,
       const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind);
   bool start_service_by_desktop_name(const TQString &serviceName, const TQStringList &urls,
       const TQValueList<TQCString> &envs, const TQCString& startup_id, bool blind);
   bool kdeinit_exec(const TQString &app, const TQStringList &args,
       const TQValueList<TQCString> &envs, TQCString startup_id, bool wait);

   void waitForSlave(pid_t pid);

   void autoStart(int phase);

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

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


   void queueRequest(KLaunchRequest *);

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

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

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