author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
//#define QPROCESS_DEBUG |
|
43 |
||
44 |
#ifdef QPROCESS_DEBUG |
|
45 |
#include "qdebug.h" |
|
46 |
#define QPROCESS_DEBUG_PRINT(args...) qDebug(args); |
|
47 |
#else |
|
48 |
#define QPROCESS_DEBUG_PRINT(args...) |
|
49 |
#endif |
|
50 |
||
51 |
#ifndef QT_NO_PROCESS |
|
52 |
||
53 |
#define QPROCESS_ASSERT(check, panicReason, args...) \ |
|
54 |
if (!(check)) { \ |
|
55 |
qWarning(args); \ |
|
56 |
User::Panic(KQProcessPanic, panicReason); \ |
|
57 |
} |
|
58 |
||
59 |
#include <exception> |
|
60 |
#include <e32base.h> |
|
61 |
#include <e32std.h> |
|
62 |
#include <stdio.h> |
|
63 |
#include "qplatformdefs.h" |
|
64 |
||
65 |
#include "qdir.h" |
|
66 |
#include "qstring.h" |
|
67 |
#include "qprocess.h" |
|
68 |
#include "qprocess_p.h" |
|
69 |
#include "qeventdispatcher_symbian_p.h" |
|
70 |
||
71 |
#include <private/qthread_p.h> |
|
72 |
#include <qmutex.h> |
|
73 |
#include <qmap.h> |
|
74 |
#include <qsocketnotifier.h> |
|
75 |
||
76 |
#include <errno.h> |
|
77 |
||
78 |
||
79 |
QT_BEGIN_NAMESPACE |
|
80 |
||
81 |
_LIT(KQProcessManagerThreadName, "QProcManThread"); |
|
82 |
_LIT(KQProcessPanic, "QPROCESS"); |
|
83 |
enum TQProcessPanic { |
|
84 |
EProcessManagerMediatorRunError = 1, |
|
85 |
EProcessManagerMediatorInactive = 2, |
|
86 |
EProcessManagerMediatorNotPending = 3, |
|
87 |
EProcessManagerMediatorInvalidCmd = 4, |
|
88 |
EProcessManagerMediatorCreationFailed = 5, |
|
89 |
EProcessManagerMediatorThreadOpenFailed = 6, |
|
90 |
EProcessManagerMediatorNullObserver = 7, |
|
91 |
EProcessActiveRunError = 10, |
|
92 |
EProcessActiveNullParameter = 11, |
|
93 |
EProcessManagerMutexCreationFail = 20, |
|
94 |
EProcessManagerThreadCreationFail = 21, |
|
95 |
EProcessManagerSchedulerCreationFail = 22, |
|
96 |
EProcessManagerNullParam = 23 |
|
97 |
}; |
|
98 |
||
99 |
// Forward declarations |
|
100 |
class QProcessManager; |
|
101 |
||
102 |
||
103 |
// Active object to listen for child process death |
|
104 |
class QProcessActive : public CActive |
|
105 |
{ |
|
106 |
public: |
|
107 |
static QProcessActive *construct(QProcess *process, |
|
108 |
RProcess **proc, |
|
109 |
int serial, |
|
110 |
int deathPipe); |
|
111 |
||
112 |
virtual ~QProcessActive(); |
|
113 |
||
114 |
void start(); |
|
115 |
void stop(); |
|
116 |
||
117 |
bool error(); |
|
118 |
||
119 |
protected: |
|
120 |
||
121 |
// Inherited from CActive |
|
122 |
void RunL(); |
|
123 |
TInt RunError(TInt aError); |
|
124 |
void DoCancel(); |
|
125 |
||
126 |
QProcessActive(); |
|
127 |
||
128 |
private: |
|
129 |
||
130 |
QProcess *process; |
|
131 |
RProcess **pproc; |
|
132 |
int serial; |
|
133 |
int deathPipe; |
|
134 |
bool errorValue; |
|
135 |
}; |
|
136 |
||
137 |
// Active object to communicate synchronously with process manager thread |
|
138 |
class QProcessManagerMediator : public CActive |
|
139 |
{ |
|
140 |
public: |
|
141 |
static QProcessManagerMediator *construct(); |
|
142 |
||
143 |
virtual ~QProcessManagerMediator(); |
|
144 |
||
145 |
bool add(QProcessActive *processObserver); |
|
146 |
void remove(QProcessActive *processObserver); |
|
147 |
void terminate(); |
|
148 |
||
149 |
protected: |
|
150 |
||
151 |
enum Commands { |
|
152 |
ENoCommand, |
|
153 |
EAdd, |
|
154 |
ERemove, |
|
155 |
ETerminate |
|
156 |
}; |
|
157 |
||
158 |
// Inherited from CActive |
|
159 |
void RunL(); |
|
160 |
TInt RunError(TInt aError); |
|
161 |
void DoCancel(); |
|
162 |
||
163 |
QProcessManagerMediator(); |
|
164 |
||
165 |
bool notify(QProcessActive *processObserver, Commands command); |
|
166 |
||
167 |
private: |
|
168 |
QProcessActive *currentObserver; |
|
169 |
Commands currentCommand; |
|
170 |
||
171 |
RThread processManagerThread; |
|
172 |
}; |
|
173 |
||
174 |
// Process manager manages child process death listeners. |
|
175 |
// |
|
176 |
// Note: Because QProcess can be used outside event loop, we cannot be guaranteed |
|
177 |
// an active scheduler exists for us to add our process death listener objects. |
|
178 |
// We can't just install active scheduler on the calling thread, as that would block it |
|
179 |
// if we want to actually use it, so a separate manager thread is required. |
|
180 |
class QProcessManager |
|
181 |
{ |
|
182 |
public: |
|
183 |
QProcessManager(); |
|
184 |
~QProcessManager(); |
|
185 |
||
186 |
void startThread(); |
|
187 |
||
188 |
TInt run(void *param); |
|
189 |
bool add(QProcess *process); |
|
190 |
void remove(QProcess *process); |
|
191 |
||
192 |
inline void setMediator(QProcessManagerMediator *newMediator) { |
|
193 |
mediator = newMediator; |
|
194 |
}; |
|
195 |
||
196 |
private: |
|
197 |
inline void lock() { |
|
198 |
managerMutex.Wait(); |
|
199 |
}; |
|
200 |
inline void unlock() { |
|
201 |
managerMutex.Signal(); |
|
202 |
}; |
|
203 |
||
204 |
QMap<int, QProcessActive *> children; |
|
205 |
QProcessManagerMediator *mediator; |
|
206 |
RMutex managerMutex; |
|
207 |
bool threadStarted; |
|
208 |
RThread managerThread; |
|
209 |
}; |
|
210 |
||
211 |
static bool qt_rprocess_running(RProcess *proc) |
|
212 |
{ |
|
213 |
if (proc && proc->Handle()) { |
|
214 |
TExitType et = proc->ExitType(); |
|
215 |
if (et == EExitPending) |
|
216 |
return true; |
|
217 |
} |
|
218 |
||
219 |
return false; |
|
220 |
} |
|
221 |
||
222 |
static void qt_create_symbian_commandline(const QStringList &arguments, QString &commandLine) |
|
223 |
{ |
|
224 |
for (int i = 0; i < arguments.size(); ++i) { |
|
225 |
QString tmp = arguments.at(i); |
|
226 |
// in the case of \" already being in the string the \ must also be escaped |
|
227 |
tmp.replace(QLatin1String("\\\""), QLatin1String("\\\\\"")); |
|
228 |
// escape a single " because the arguments will be parsed |
|
229 |
tmp.replace(QLatin1String("\""), QLatin1String("\\\"")); |
|
230 |
if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) { |
|
231 |
// The argument must not end with a \ since this would be interpreted |
|
232 |
// as escaping the quote -- rather put the \ behind the quote: e.g. |
|
233 |
// rather use "foo"\ than "foo\" |
|
234 |
QString endQuote(QLatin1String("\"")); |
|
235 |
int i = tmp.length(); |
|
236 |
while (i > 0 && tmp.at(i - 1) == QLatin1Char('\\')) { |
|
237 |
--i; |
|
238 |
endQuote += QLatin1String("\\"); |
|
239 |
} |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
240 |
commandLine += QLatin1String("\"") + tmp.left(i) + endQuote + QLatin1Char(' '); |
0 | 241 |
} else { |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
242 |
commandLine += tmp + QLatin1Char(' '); |
0 | 243 |
} |
244 |
} |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
245 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
246 |
// Chop the extra trailing space if any arguments were appended |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
247 |
if (arguments.size()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
248 |
commandLine.chop(1); |
0 | 249 |
} |
250 |
||
251 |
static TInt qt_create_symbian_process(RProcess **proc, const QString &programName, const QStringList &arguments) |
|
252 |
{ |
|
253 |
RProcess *newProc = NULL; |
|
254 |
newProc = new RProcess(); |
|
255 |
||
256 |
if (!newProc) |
|
257 |
return KErrNoMemory; |
|
258 |
||
259 |
QString commandLine; |
|
260 |
qt_create_symbian_commandline(arguments, commandLine); |
|
261 |
||
262 |
TPtrC program_ptr(reinterpret_cast<const TText*>(programName.constData())); |
|
263 |
TPtrC cmdline_ptr(reinterpret_cast<const TText*>(commandLine.constData())); |
|
264 |
||
265 |
TInt err = newProc->Create(program_ptr, cmdline_ptr); |
|
266 |
||
267 |
if (err == KErrNotFound) { |
|
268 |
// Strip path from program name and try again (i.e. try from default location "\sys\bin") |
|
269 |
int index = programName.lastIndexOf(QDir::separator()); |
|
270 |
int index2 = programName.lastIndexOf(QChar(QLatin1Char('/'))); |
|
271 |
index = qMax(index, index2); |
|
272 |
||
273 |
if (index != -1 && programName.length() >= index) { |
|
274 |
QString strippedName; |
|
275 |
strippedName = programName.mid(index + 1); |
|
276 |
QPROCESS_DEBUG_PRINT("qt_create_symbian_process() Executable '%s' not found, trying stripped version '%s'", |
|
277 |
qPrintable(programName), qPrintable(strippedName)); |
|
278 |
||
279 |
TPtrC stripped_ptr(reinterpret_cast<const TText*>(strippedName.constData())); |
|
280 |
err = newProc->Create(stripped_ptr, cmdline_ptr); |
|
281 |
||
282 |
if (err != KErrNone) { |
|
283 |
QPROCESS_DEBUG_PRINT("qt_create_symbian_process() Unable to create process '%s': %d", |
|
284 |
qPrintable(strippedName), err); |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
if (err == KErrNone) |
|
290 |
*proc = newProc; |
|
291 |
else |
|
292 |
delete newProc; |
|
293 |
||
294 |
return err; |
|
295 |
} |
|
296 |
||
297 |
static qint64 qt_native_read(int fd, char *data, qint64 maxlen) |
|
298 |
{ |
|
299 |
qint64 ret = 0; |
|
300 |
do { |
|
301 |
ret = ::read(fd, data, maxlen); |
|
302 |
} while (ret == -1 && errno == EINTR); |
|
303 |
||
304 |
QPROCESS_DEBUG_PRINT("qt_native_read(): fd: %d, result: %d, errno = %d", fd, (int)ret, errno); |
|
305 |
||
306 |
return ret; |
|
307 |
} |
|
308 |
||
309 |
static qint64 qt_native_write(int fd, const char *data, qint64 len) |
|
310 |
{ |
|
311 |
qint64 ret = 0; |
|
312 |
do { |
|
313 |
ret = ::write(fd, data, len); |
|
314 |
} while (ret == -1 && errno == EINTR); |
|
315 |
||
316 |
QPROCESS_DEBUG_PRINT("qt_native_write(): fd: %d, result: %d, errno = %d", fd, (int)ret, errno); |
|
317 |
||
318 |
return ret; |
|
319 |
} |
|
320 |
||
321 |
static void qt_native_close(int fd) |
|
322 |
{ |
|
323 |
int ret; |
|
324 |
do { |
|
325 |
ret = ::close(fd); |
|
326 |
} while (ret == -1 && errno == EINTR); |
|
327 |
} |
|
328 |
||
329 |
static void qt_create_pipe(int *pipe) |
|
330 |
{ |
|
331 |
if (pipe[0] != -1) |
|
332 |
qt_native_close(pipe[0]); |
|
333 |
if (pipe[1] != -1) |
|
334 |
qt_native_close(pipe[1]); |
|
335 |
if (::pipe(pipe) != 0) { |
|
336 |
qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s", |
|
337 |
pipe, qPrintable(qt_error_string(errno))); |
|
338 |
} else { |
|
339 |
QPROCESS_DEBUG_PRINT("qt_create_pipe(): Created pipe %d - %d", pipe[0], pipe[1]); |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
// Called from ProcessManagerThread |
|
344 |
QProcessActive *QProcessActive::construct(QProcess *process, |
|
345 |
RProcess **proc, |
|
346 |
int serial, |
|
347 |
int deathPipe) |
|
348 |
{ |
|
349 |
QPROCESS_ASSERT((process || proc || *proc), |
|
350 |
EProcessActiveNullParameter, |
|
351 |
"QProcessActive::construct(): process (0x%x), proc (0x%x) or *proc == NULL, not creating an instance", process, proc) |
|
352 |
||
353 |
QProcessActive *newInstance = new QProcessActive(); |
|
354 |
||
355 |
if (!newInstance) { |
|
356 |
QPROCESS_DEBUG_PRINT("QProcessActive::construct(): Failed to create new instance"); |
|
357 |
} else { |
|
358 |
newInstance->process = process; |
|
359 |
newInstance->pproc = proc; |
|
360 |
newInstance->serial = serial; |
|
361 |
newInstance->deathPipe = deathPipe; |
|
362 |
newInstance->errorValue = false; |
|
363 |
} |
|
364 |
||
365 |
return newInstance; |
|
366 |
} |
|
367 |
||
368 |
// Called from ProcessManagerThread |
|
369 |
QProcessActive::QProcessActive() |
|
370 |
: CActive(CActive::EPriorityStandard) |
|
371 |
{ |
|
372 |
// Nothing to do |
|
373 |
} |
|
374 |
||
375 |
// Called from ProcessManagerThread |
|
376 |
QProcessActive::~QProcessActive() |
|
377 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
378 |
Cancel(); |
0 | 379 |
process = NULL; |
380 |
pproc = NULL; |
|
381 |
} |
|
382 |
||
383 |
// Called from ProcessManagerThread |
|
384 |
void QProcessActive::start() |
|
385 |
{ |
|
386 |
if (qt_rprocess_running(*pproc)) { |
|
387 |
CActiveScheduler::Add(this); |
|
388 |
(*pproc)->Logon(iStatus); |
|
389 |
SetActive(); |
|
390 |
QPROCESS_DEBUG_PRINT("QProcessActive::start(): Started monitoring for process exit."); |
|
391 |
} else { |
|
392 |
QPROCESS_DEBUG_PRINT("QProcessActive::start(): Process doesn't exist or is already dead"); |
|
393 |
// Assume process has already died |
|
394 |
qt_native_write(deathPipe, "", 1); |
|
395 |
errorValue = true; |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
// Called from ProcessManagerThread |
|
400 |
void QProcessActive::stop() |
|
401 |
{ |
|
402 |
QPROCESS_DEBUG_PRINT("QProcessActive::stop()"); |
|
403 |
||
404 |
// Remove this from scheduler (also cancels the request) |
|
405 |
Deque(); |
|
406 |
} |
|
407 |
||
408 |
bool QProcessActive::error() |
|
409 |
{ |
|
410 |
return errorValue; |
|
411 |
} |
|
412 |
||
413 |
// Called from ProcessManagerThread |
|
414 |
void QProcessActive::RunL() |
|
415 |
{ |
|
416 |
// If this method gets executed, the monitored process has died |
|
417 |
||
418 |
// Notify main thread |
|
419 |
qt_native_write(deathPipe, "", 1); |
|
420 |
QPROCESS_DEBUG_PRINT("QProcessActive::RunL() sending death notice to %d", deathPipe); |
|
421 |
} |
|
422 |
||
423 |
// Called from ProcessManagerThread |
|
424 |
TInt QProcessActive::RunError(TInt aError) |
|
425 |
{ |
|
426 |
Q_UNUSED(aError); |
|
427 |
// Handle RunL leave (should never happen) |
|
428 |
QPROCESS_ASSERT(0, EProcessActiveRunError, "QProcessActive::RunError(): Should never get here!") |
|
429 |
return 0; |
|
430 |
} |
|
431 |
||
432 |
// Called from ProcessManagerThread |
|
433 |
void QProcessActive::DoCancel() |
|
434 |
{ |
|
435 |
QPROCESS_DEBUG_PRINT("QProcessActive::DoCancel()"); |
|
436 |
||
437 |
if (qt_rprocess_running(*pproc)) { |
|
438 |
(*pproc)->LogonCancel(iStatus); |
|
439 |
QPROCESS_DEBUG_PRINT("QProcessActive::DoCancel(): Stopped monitoring for process exit."); |
|
440 |
} else { |
|
441 |
QPROCESS_DEBUG_PRINT("QProcessActive::DoCancel(): Process doesn't exist"); |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
||
446 |
// Called from ProcessManagerThread |
|
447 |
QProcessManagerMediator *QProcessManagerMediator::construct() |
|
448 |
{ |
|
449 |
QProcessManagerMediator *newInstance = new QProcessManagerMediator; |
|
450 |
TInt err(KErrNone); |
|
451 |
||
452 |
newInstance->currentCommand = ENoCommand; |
|
453 |
newInstance->currentObserver = NULL; |
|
454 |
||
455 |
if (newInstance) { |
|
456 |
err = newInstance->processManagerThread.Open(newInstance->processManagerThread.Id()); |
|
457 |
QPROCESS_ASSERT((err == KErrNone), |
|
458 |
EProcessManagerMediatorThreadOpenFailed, |
|
459 |
"QProcessManagerMediator::construct(): Failed to open processManagerThread (err:%d)", err) |
|
460 |
} else { |
|
461 |
QPROCESS_ASSERT(0, |
|
462 |
EProcessManagerMediatorCreationFailed, |
|
463 |
"QProcessManagerMediator::construct(): Failed to open construct mediator") |
|
464 |
} |
|
465 |
||
466 |
// Activate mediator |
|
467 |
CActiveScheduler::Add(newInstance); |
|
468 |
newInstance->iStatus = KRequestPending; |
|
469 |
newInstance->SetActive(); |
|
470 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::construct(): new instance successfully created and activated"); |
|
471 |
||
472 |
return newInstance; |
|
473 |
} |
|
474 |
||
475 |
// Called from ProcessManagerThread |
|
476 |
QProcessManagerMediator::QProcessManagerMediator() |
|
477 |
: CActive(CActive::EPriorityStandard) |
|
478 |
{ |
|
479 |
// Nothing to do |
|
480 |
} |
|
481 |
||
482 |
// Called from ProcessManagerThread |
|
483 |
QProcessManagerMediator::~QProcessManagerMediator() |
|
484 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
485 |
Cancel(); |
0 | 486 |
processManagerThread.Close(); |
487 |
currentCommand = ENoCommand; |
|
488 |
currentObserver = NULL; |
|
489 |
} |
|
490 |
||
491 |
// Called from main thread |
|
492 |
bool QProcessManagerMediator::add(QProcessActive *processObserver) |
|
493 |
{ |
|
494 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::add()"); |
|
495 |
return notify(processObserver, EAdd); |
|
496 |
} |
|
497 |
||
498 |
// Called from main thread |
|
499 |
void QProcessManagerMediator::remove(QProcessActive *processObserver) |
|
500 |
{ |
|
501 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::remove()"); |
|
502 |
notify(processObserver, ERemove); |
|
503 |
} |
|
504 |
||
505 |
// Called from main thread |
|
506 |
void QProcessManagerMediator::terminate() |
|
507 |
{ |
|
508 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::terminate()"); |
|
509 |
notify(NULL, ETerminate); |
|
510 |
} |
|
511 |
||
512 |
// Called from main thread |
|
513 |
bool QProcessManagerMediator::notify(QProcessActive *processObserver, Commands command) |
|
514 |
{ |
|
515 |
bool success(true); |
|
516 |
||
517 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::Notify(): Command: %d, processObserver: 0x%x", command, processObserver); |
|
518 |
||
519 |
QPROCESS_ASSERT((command == ETerminate || processObserver), |
|
520 |
EProcessManagerMediatorNullObserver, |
|
521 |
"QProcessManagerMediator::Notify(): NULL processObserver not allowed for command: %d", command) |
|
522 |
||
523 |
QPROCESS_ASSERT(IsActive(), |
|
524 |
EProcessManagerMediatorInactive, |
|
525 |
"QProcessManagerMediator::Notify(): Mediator is not active!") |
|
526 |
||
527 |
QPROCESS_ASSERT(iStatus == KRequestPending, |
|
528 |
EProcessManagerMediatorNotPending, |
|
529 |
"QProcessManagerMediator::Notify(): Mediator request not pending!") |
|
530 |
||
531 |
currentObserver = processObserver; |
|
532 |
currentCommand = command; |
|
533 |
||
534 |
// Sync with process manager thread |
|
535 |
TRequestStatus pmStatus; |
|
536 |
processManagerThread.Rendezvous(pmStatus); |
|
537 |
||
538 |
// Complete request -> RunL will run in the process manager thread |
|
539 |
TRequestStatus *status = &iStatus; |
|
540 |
processManagerThread.RequestComplete(status, command); |
|
541 |
||
542 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::Notify(): Waiting process manager to complete..."); |
|
543 |
User::WaitForRequest(pmStatus); |
|
544 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::Notify(): Wait over"); |
|
545 |
||
546 |
if (currentObserver) { |
|
547 |
success = !(currentObserver->error()); |
|
548 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::Notify(): success = %d", success); |
|
549 |
} |
|
550 |
||
551 |
currentObserver = NULL; |
|
552 |
currentCommand = ENoCommand; |
|
553 |
||
554 |
return success; |
|
555 |
} |
|
556 |
||
557 |
// Called from ProcessManagerThread |
|
558 |
void QProcessManagerMediator::RunL() |
|
559 |
{ |
|
560 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::RunL(): currentCommand: %d, iStatus: %d", currentCommand, iStatus.Int()); |
|
561 |
switch (currentCommand) { |
|
562 |
case EAdd: |
|
563 |
currentObserver->start(); |
|
564 |
break; |
|
565 |
case ERemove: |
|
566 |
currentObserver->stop(); |
|
567 |
break; |
|
568 |
case ETerminate: |
|
569 |
Deque(); |
|
570 |
CActiveScheduler::Stop(); |
|
571 |
return; |
|
572 |
default: |
|
573 |
QPROCESS_ASSERT(0, |
|
574 |
EProcessManagerMediatorInvalidCmd, |
|
575 |
"QProcessManagerMediator::RunL(): Invalid command!") |
|
576 |
break; |
|
577 |
} |
|
578 |
||
579 |
iStatus = KRequestPending; |
|
580 |
SetActive(); |
|
581 |
||
582 |
// Notify main thread that we are done |
|
583 |
RThread::Rendezvous(KErrNone); |
|
584 |
} |
|
585 |
||
586 |
// Called from ProcessManagerThread |
|
587 |
TInt QProcessManagerMediator::RunError(TInt aError) |
|
588 |
{ |
|
589 |
Q_UNUSED(aError); |
|
590 |
// Handle RunL leave (should never happen) |
|
591 |
QPROCESS_ASSERT(0, |
|
592 |
EProcessManagerMediatorRunError, |
|
593 |
"QProcessManagerMediator::RunError(): Should never get here!") |
|
594 |
return 0; |
|
595 |
} |
|
596 |
||
597 |
// Called from ProcessManagerThread |
|
598 |
void QProcessManagerMediator::DoCancel() |
|
599 |
{ |
|
600 |
QPROCESS_DEBUG_PRINT("QProcessManagerMediator::DoCancel()"); |
|
601 |
TRequestStatus *status = &iStatus; |
|
602 |
processManagerThread.RequestComplete(status, KErrCancel); |
|
603 |
} |
|
604 |
||
605 |
Q_GLOBAL_STATIC(QProcessManager, processManager) |
|
606 |
||
607 |
TInt processManagerThreadFunction(TAny *param) |
|
608 |
{ |
|
609 |
QPROCESS_ASSERT(param, |
|
610 |
EProcessManagerNullParam, |
|
611 |
"processManagerThreadFunction(): NULL param") |
|
612 |
||
613 |
QProcessManager *manager = reinterpret_cast<QProcessManager*>(param); |
|
614 |
||
615 |
CActiveScheduler *scheduler = new CQtActiveScheduler(); |
|
616 |
||
617 |
QPROCESS_ASSERT(scheduler, |
|
618 |
EProcessManagerSchedulerCreationFail, |
|
619 |
"processManagerThreadFunction(): Scheduler creation failed") |
|
620 |
||
621 |
CActiveScheduler::Install(scheduler); |
|
622 |
||
623 |
//Creating mediator also adds it to scheduler and activates it. Failure will panic. |
|
624 |
manager->setMediator(QProcessManagerMediator::construct()); |
|
625 |
RThread::Rendezvous(KErrNone); |
|
626 |
||
627 |
CActiveScheduler::Start(); |
|
628 |
||
629 |
CActiveScheduler::Install(NULL); |
|
630 |
delete scheduler; |
|
631 |
||
632 |
return KErrNone; |
|
633 |
} |
|
634 |
||
635 |
QProcessManager::QProcessManager() |
|
636 |
: mediator(NULL), threadStarted(false) |
|
637 |
{ |
|
638 |
TInt err = managerMutex.CreateLocal(); |
|
639 |
||
640 |
QPROCESS_ASSERT(err == KErrNone, |
|
641 |
EProcessManagerMutexCreationFail, |
|
642 |
"QProcessManager::QProcessManager(): Failed to create new managerMutex (err: %d)", err) |
|
643 |
} |
|
644 |
||
645 |
QProcessManager::~QProcessManager() |
|
646 |
{ |
|
647 |
QPROCESS_DEBUG_PRINT("QProcessManager::~QProcessManager()"); |
|
648 |
// Cancel death listening for all child processes |
|
649 |
if (mediator) { |
|
650 |
QMap<int, QProcessActive *>::Iterator it = children.begin(); |
|
651 |
while (it != children.end()) { |
|
652 |
// Remove all monitors |
|
653 |
QProcessActive *active = it.value(); |
|
654 |
mediator->remove(active); |
|
655 |
||
656 |
QPROCESS_DEBUG_PRINT("QProcessManager::~QProcessManager() removed listening for a process"); |
|
657 |
++it; |
|
658 |
} |
|
659 |
||
660 |
// Terminate process manager thread. |
|
661 |
mediator->terminate(); |
|
662 |
delete mediator; |
|
663 |
} |
|
664 |
||
665 |
qDeleteAll(children.values()); |
|
666 |
children.clear(); |
|
667 |
managerThread.Close(); |
|
668 |
managerMutex.Close(); |
|
669 |
} |
|
670 |
||
671 |
void QProcessManager::startThread() |
|
672 |
{ |
|
673 |
lock(); |
|
674 |
||
675 |
if (!threadStarted) { |
|
676 |
TInt err = managerThread.Create(KQProcessManagerThreadName, |
|
677 |
processManagerThreadFunction, |
|
678 |
0x5000, |
|
679 |
(RAllocator*)NULL, |
|
680 |
(TAny*)this, |
|
681 |
EOwnerProcess); |
|
682 |
||
683 |
QPROCESS_ASSERT(err == KErrNone, |
|
684 |
EProcessManagerThreadCreationFail, |
|
685 |
"QProcessManager::startThread(): Failed to create new managerThread (err:%d)", err) |
|
686 |
||
687 |
threadStarted = true; |
|
688 |
||
689 |
// Manager thread must start running before we continue, so sync with rendezvous |
|
690 |
TRequestStatus status; |
|
691 |
managerThread.Rendezvous(status); |
|
692 |
managerThread.Resume(); |
|
693 |
User::WaitForRequest(status); |
|
694 |
} |
|
695 |
||
696 |
unlock(); |
|
697 |
} |
|
698 |
||
699 |
static QBasicAtomicInt idCounter = Q_BASIC_ATOMIC_INITIALIZER(1); |
|
700 |
||
701 |
bool QProcessManager::add(QProcess *process) |
|
702 |
{ |
|
703 |
QPROCESS_ASSERT(process, |
|
704 |
EProcessManagerNullParam, |
|
705 |
"QProcessManager::add(): Failed to add QProcessActive to ProcessManager - NULL process") |
|
706 |
||
707 |
lock(); |
|
708 |
||
709 |
int serial = idCounter.fetchAndAddRelaxed(1); |
|
710 |
process->d_func()->serial = serial; |
|
711 |
||
712 |
QPROCESS_DEBUG_PRINT("QProcessManager::add(): serial: %d, deathPipe: %d - %d, symbianProcess: 0x%x", serial, process->d_func()->deathPipe[0], process->d_func()->deathPipe[1], process->d_func()->symbianProcess); |
|
713 |
||
714 |
QProcessActive *newActive = |
|
715 |
QProcessActive::construct(process, |
|
716 |
&(process->d_func()->symbianProcess), |
|
717 |
serial, |
|
718 |
process->d_func()->deathPipe[1]); |
|
719 |
||
720 |
if (newActive) { |
|
721 |
if (mediator->add(newActive)) { |
|
722 |
children.insert(serial, newActive); |
|
723 |
unlock(); |
|
724 |
return true; |
|
725 |
} else { |
|
726 |
QPROCESS_DEBUG_PRINT("QProcessManager::add(): Failed to add QProcessActive to ProcessManager"); |
|
727 |
delete newActive; |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
unlock(); |
|
732 |
||
733 |
return false; |
|
734 |
} |
|
735 |
||
736 |
void QProcessManager::remove(QProcess *process) |
|
737 |
{ |
|
738 |
QPROCESS_ASSERT(process, |
|
739 |
EProcessManagerNullParam, |
|
740 |
"QProcessManager::remove(): Failed to remove QProcessActive from ProcessManager - NULL process") |
|
741 |
||
742 |
lock(); |
|
743 |
||
744 |
int serial = process->d_func()->serial; |
|
745 |
QProcessActive *active = children.value(serial); |
|
746 |
if (!active) { |
|
747 |
unlock(); |
|
748 |
return; |
|
749 |
} |
|
750 |
||
751 |
mediator->remove(active); |
|
752 |
||
753 |
children.remove(serial); |
|
754 |
delete active; |
|
755 |
||
756 |
unlock(); |
|
757 |
} |
|
758 |
||
759 |
void QProcessPrivate::destroyPipe(int *pipe) |
|
760 |
{ |
|
761 |
if (pipe[1] != -1) { |
|
762 |
qt_native_close(pipe[1]); |
|
763 |
pipe[1] = -1; |
|
764 |
} |
|
765 |
if (pipe[0] != -1) { |
|
766 |
qt_native_close(pipe[0]); |
|
767 |
pipe[0] = -1; |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
bool QProcessPrivate::createChannel(Channel &channel) |
|
772 |
{ |
|
773 |
Q_UNUSED(channel); |
|
774 |
// No channels used |
|
775 |
return false; |
|
776 |
} |
|
777 |
||
778 |
void QProcessPrivate::startProcess() |
|
779 |
{ |
|
780 |
Q_Q(QProcess); |
|
781 |
||
782 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::startProcess()"); |
|
783 |
||
784 |
// Start the process (platform dependent) |
|
785 |
q->setProcessState(QProcess::Starting); |
|
786 |
||
787 |
processManager()->startThread(); |
|
788 |
||
789 |
qt_create_pipe(deathPipe); |
|
790 |
if (threadData->eventDispatcher) { |
|
791 |
deathNotifier = new QSocketNotifier(deathPipe[0], |
|
792 |
QSocketNotifier::Read, q); |
|
793 |
QObject::connect(deathNotifier, SIGNAL(activated(int)), |
|
794 |
q, SLOT(_q_processDied())); |
|
795 |
} |
|
796 |
||
797 |
TInt err = qt_create_symbian_process(&symbianProcess, program, arguments); |
|
798 |
||
799 |
if (err == KErrNone) { |
|
800 |
pid = symbianProcess->Id().Id(); |
|
801 |
||
802 |
::fcntl(deathPipe[0], F_SETFL, ::fcntl(deathPipe[0], F_GETFL) | O_NONBLOCK); |
|
803 |
||
804 |
if (!processManager()->add(q)) { |
|
805 |
qWarning("QProcessPrivate::startProcess(): Failed to start monitoring for process death."); |
|
806 |
err = KErrNoMemory; |
|
807 |
} |
|
808 |
} |
|
809 |
||
810 |
if (err != KErrNone) { |
|
811 |
// Cleanup, report error and return |
|
812 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::startProcess() Process open failed, err: %d, '%s'", err, qPrintable(program)); |
|
813 |
q->setProcessState(QProcess::NotRunning); |
|
814 |
processError = QProcess::FailedToStart; |
|
815 |
q->setErrorString(QLatin1String(QT_TRANSLATE_NOOP(QProcess, "Resource error (qt_create_symbian_process failure)"))); |
|
816 |
emit q->error(processError); |
|
817 |
cleanup(); |
|
818 |
return; |
|
819 |
} |
|
820 |
||
821 |
processLaunched = true; |
|
822 |
||
823 |
symbianProcess->Resume(); |
|
824 |
||
825 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::startProcess(): this: 0x%x, pid: %ld", this, pid); |
|
826 |
||
827 |
// Notify child start |
|
828 |
_q_startupNotification(); |
|
829 |
||
830 |
} |
|
831 |
||
832 |
bool QProcessPrivate::processStarted() |
|
833 |
{ |
|
834 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::processStarted() == %s", processLaunched ? "true" : "false"); |
|
835 |
||
836 |
// Since we cannot get information whether process has actually been launched |
|
837 |
// or not in Symbian, we need to fake it. Assume process is started if launch was |
|
838 |
// successful. |
|
839 |
||
840 |
return processLaunched; |
|
841 |
} |
|
842 |
||
843 |
qint64 QProcessPrivate::bytesAvailableFromStdout() const |
|
844 |
{ |
|
845 |
// In Symbian, stdout is not supported |
|
846 |
return 0; |
|
847 |
} |
|
848 |
||
849 |
qint64 QProcessPrivate::bytesAvailableFromStderr() const |
|
850 |
{ |
|
851 |
// In Symbian, stderr is not supported |
|
852 |
return 0; |
|
853 |
} |
|
854 |
||
855 |
qint64 QProcessPrivate::readFromStdout(char *data, qint64 maxlen) |
|
856 |
{ |
|
857 |
Q_UNUSED(data); |
|
858 |
Q_UNUSED(maxlen); |
|
859 |
// In Symbian, stdout is not supported |
|
860 |
return 0; |
|
861 |
} |
|
862 |
||
863 |
qint64 QProcessPrivate::readFromStderr(char *data, qint64 maxlen) |
|
864 |
{ |
|
865 |
Q_UNUSED(data); |
|
866 |
Q_UNUSED(maxlen); |
|
867 |
// In Symbian, stderr is not supported |
|
868 |
return 0; |
|
869 |
} |
|
870 |
||
871 |
qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) |
|
872 |
{ |
|
873 |
Q_UNUSED(data); |
|
874 |
Q_UNUSED(maxlen); |
|
875 |
// In Symbian, stdin is not supported |
|
876 |
return 0; |
|
877 |
} |
|
878 |
||
879 |
void QProcessPrivate::terminateProcess() |
|
880 |
{ |
|
881 |
// Needs PowerMgmt capability if process has been started; will panic kern-exec 46 otherwise. |
|
882 |
// Always works if process is not yet started. |
|
883 |
if (qt_rprocess_running(symbianProcess)) { |
|
884 |
symbianProcess->Terminate(0); |
|
885 |
} else { |
|
886 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::terminateProcess(), Process not running"); |
|
887 |
} |
|
888 |
} |
|
889 |
||
890 |
void QProcessPrivate::killProcess() |
|
891 |
{ |
|
892 |
// Needs PowerMgmt capability if process has been started; will panic kern-exec 46 otherwise. |
|
893 |
// Always works if process is not yet started. |
|
894 |
if (qt_rprocess_running(symbianProcess)) { |
|
895 |
symbianProcess->Kill(0); |
|
896 |
} else { |
|
897 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::killProcess(), Process not running"); |
|
898 |
} |
|
899 |
} |
|
900 |
||
901 |
bool QProcessPrivate::waitForStarted(int msecs) |
|
902 |
{ |
|
903 |
Q_UNUSED(msecs); |
|
904 |
// Since we can get no actual feedback from process beyond its death, |
|
905 |
// assume that started has already been emitted if process has been launched |
|
906 |
return processLaunched; |
|
907 |
} |
|
908 |
||
909 |
bool QProcessPrivate::waitForReadyRead(int msecs) |
|
910 |
{ |
|
911 |
// Functionality not supported in Symbian |
|
912 |
Q_UNUSED(msecs); |
|
913 |
return false; |
|
914 |
} |
|
915 |
||
916 |
bool QProcessPrivate::waitForBytesWritten(int msecs) |
|
917 |
{ |
|
918 |
// Functionality not supported in Symbian |
|
919 |
Q_UNUSED(msecs); |
|
920 |
return false; |
|
921 |
} |
|
922 |
||
923 |
bool QProcessPrivate::waitForFinished(int msecs) |
|
924 |
{ |
|
925 |
Q_Q(QProcess); |
|
926 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished(%d)", msecs); |
|
927 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
928 |
TRequestStatus timerStatus = KErrNone; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
929 |
TRequestStatus logonStatus = KErrNone; |
0 | 930 |
bool timeoutOccurred = false; |
931 |
||
932 |
// Logon to process to observe its death |
|
933 |
if (qt_rprocess_running(symbianProcess)) { |
|
934 |
symbianProcess->Logon(logonStatus); |
|
935 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
936 |
if (msecs < 0) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
// If timeout is negative, there is no timeout |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished() - Waiting (just logon)..."); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
939 |
User::WaitForRequest(logonStatus); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
940 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished() - Wait completed"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
941 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
942 |
// Create timer |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
943 |
RTimer timer; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
944 |
timer.CreateLocal(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
945 |
TTimeIntervalMicroSeconds32 interval(msecs*1000); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
timer.After(timerStatus, interval); |
0 | 947 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished() - Waiting (logon + timer)..."); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
949 |
User::WaitForRequest(logonStatus, timerStatus); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished() - Wait completed"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
951 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
952 |
if (timerStatus == KErrNone) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
timeoutOccurred = true; |
0 | 954 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
955 |
timer.Cancel(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
956 |
timer.Close(); |
0 | 957 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
958 |
symbianProcess->LogonCancel(logonStatus); |
0 | 959 |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
960 |
// Eat cancel request completion so that it won't mess up main thread scheduling later |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
961 |
User::WaitForRequest(logonStatus, timerStatus); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
962 |
} |
0 | 963 |
} else { |
964 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForFinished(), qt_rprocess_running returned false"); |
|
965 |
} |
|
966 |
||
967 |
if (timeoutOccurred) { |
|
968 |
processError = QProcess::Timedout; |
|
969 |
q->setErrorString(QLatin1String(QT_TRANSLATE_NOOP(QProcess, "Process operation timed out"))); |
|
970 |
return false; |
|
971 |
} |
|
972 |
||
973 |
_q_processDied(); |
|
974 |
||
975 |
return true; |
|
976 |
} |
|
977 |
||
978 |
bool QProcessPrivate::waitForWrite(int msecs) |
|
979 |
{ |
|
980 |
// Functionality not supported in Symbian |
|
981 |
Q_UNUSED(msecs); |
|
982 |
return false; |
|
983 |
} |
|
984 |
||
985 |
// Deceptively named function. Exit code is actually got in waitForDeadChild(). |
|
986 |
void QProcessPrivate::findExitCode() |
|
987 |
{ |
|
988 |
Q_Q(QProcess); |
|
989 |
processManager()->remove(q); |
|
990 |
} |
|
991 |
||
992 |
bool QProcessPrivate::waitForDeadChild() |
|
993 |
{ |
|
994 |
Q_Q(QProcess); |
|
995 |
||
996 |
// read a byte from the death pipe |
|
997 |
char c; |
|
998 |
qt_native_read(deathPipe[0], &c, 1); |
|
999 |
||
1000 |
if (symbianProcess && symbianProcess->Handle()) { |
|
1001 |
TExitType et = symbianProcess->ExitType(); |
|
1002 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForDeadChild() symbianProcess->ExitType: %d", et); |
|
1003 |
if (et != EExitPending) { |
|
1004 |
processManager()->remove(q); |
|
1005 |
exitCode = symbianProcess->ExitReason(); |
|
1006 |
crashed = (et == EExitPanic); |
|
1007 |
#if defined QPROCESS_DEBUG |
|
1008 |
TExitCategoryName catName = symbianProcess->ExitCategory(); |
|
1009 |
qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode" |
|
1010 |
<< exitCode << ", crashed:" << crashed |
|
1011 |
<< ", category:" << QString::fromUtf16(catName.Ptr()); |
|
1012 |
#endif |
|
1013 |
} else { |
|
1014 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForDeadChild() not dead!"); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
return true; |
|
1019 |
} |
|
1020 |
||
1021 |
void QProcessPrivate::_q_notified() |
|
1022 |
{ |
|
1023 |
// Nothing to do in Symbian |
|
1024 |
} |
|
1025 |
||
1026 |
bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) |
|
1027 |
{ |
|
1028 |
QPROCESS_DEBUG_PRINT("QProcessPrivate::startDetached()"); |
|
1029 |
Q_UNUSED(workingDirectory); |
|
1030 |
||
1031 |
RProcess *newProc = NULL; |
|
1032 |
||
1033 |
TInt err = qt_create_symbian_process(&newProc, program, arguments); |
|
1034 |
||
1035 |
if (err == KErrNone) { |
|
1036 |
if (pid) |
|
1037 |
*pid = newProc->Id().Id(); |
|
1038 |
||
1039 |
newProc->Resume(); |
|
1040 |
newProc->Close(); |
|
1041 |
return true; |
|
1042 |
} |
|
1043 |
||
1044 |
return false; |
|
1045 |
} |
|
1046 |
||
1047 |
||
1048 |
void QProcessPrivate::initializeProcessManager() |
|
1049 |
{ |
|
1050 |
(void) processManager(); |
|
1051 |
} |
|
1052 |
||
1053 |
QT_END_NAMESPACE |
|
1054 |
||
1055 |
#endif // QT_NO_PROCESS |