-rw-r--r-- | core/launcher/qprocess.h | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/core/launcher/qprocess.h b/core/launcher/qprocess.h new file mode 100644 index 0000000..0162234 --- a/dev/null +++ b/core/launcher/qprocess.h | |||
@@ -0,0 +1,163 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef QPROCESS_H | ||
22 | #define QPROCESS_H | ||
23 | |||
24 | #include <qtopia/global.h> | ||
25 | |||
26 | #ifndef QT_H | ||
27 | #include "qobject.h" | ||
28 | #include "qstringlist.h" | ||
29 | #include "qdir.h" | ||
30 | #endif // QT_H | ||
31 | |||
32 | #ifndef QT_NO_PROCESS | ||
33 | |||
34 | class QProcessPrivate; | ||
35 | |||
36 | |||
37 | class Q_EXPORT QProcess : public QObject | ||
38 | { | ||
39 | Q_OBJECT | ||
40 | public: | ||
41 | QProcess( QObject *parent=0, const char *name=0 ); | ||
42 | QProcess( const QString& arg0, QObject *parent=0, const char *name=0 ); | ||
43 | QProcess( const QStringList& args, QObject *parent=0, const char *name=0 ); | ||
44 | ~QProcess(); | ||
45 | |||
46 | // set and get the arguments and working directory | ||
47 | QStringList arguments() const; | ||
48 | void clearArguments(); | ||
49 | virtual void setArguments( const QStringList& args ); | ||
50 | virtual void addArgument( const QString& arg ); | ||
51 | #ifndef QT_NO_DIR | ||
52 | QDir workingDirectory() const; | ||
53 | virtual void setWorkingDirectory( const QDir& dir ); | ||
54 | #endif | ||
55 | |||
56 | // priority | ||
57 | int priority() const; | ||
58 | void setPriority(int); | ||
59 | |||
60 | // set and get the comms wanted | ||
61 | enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 }; | ||
62 | void setCommunication( int c ); | ||
63 | int communication() const; | ||
64 | |||
65 | // start the execution | ||
66 | virtual bool start( QStringList *env=0 ); | ||
67 | virtual bool launch( const QString& buf, QStringList *env=0 ); | ||
68 | virtual bool launch( const QByteArray& buf, QStringList *env=0 ); | ||
69 | |||
70 | // inquire the status | ||
71 | bool isRunning() const; | ||
72 | bool normalExit() const; | ||
73 | int exitStatus() const; | ||
74 | |||
75 | // reading | ||
76 | virtual QByteArray readStdout(); | ||
77 | virtual QByteArray readStderr(); | ||
78 | bool canReadLineStdout() const; | ||
79 | bool canReadLineStderr() const; | ||
80 | virtual QString readLineStdout(); | ||
81 | virtual QString readLineStderr(); | ||
82 | |||
83 | // get platform dependent process information | ||
84 | #if defined(Q_OS_WIN32) | ||
85 | typedef void* PID; | ||
86 | #else | ||
87 | typedef long Q_LONG; | ||
88 | typedef Q_LONG PID; | ||
89 | #endif | ||
90 | PID processIdentifier(); | ||
91 | |||
92 | void flushStdin(); | ||
93 | |||
94 | signals: | ||
95 | void readyReadStdout(); | ||
96 | void readyReadStderr(); | ||
97 | void processExited(); | ||
98 | void wroteToStdin(); | ||
99 | void launchFinished(); | ||
100 | |||
101 | public slots: | ||
102 | // end the execution | ||
103 | void tryTerminate() const; | ||
104 | void kill() const; | ||
105 | |||
106 | // input | ||
107 | virtual void writeToStdin( const QByteArray& buf ); | ||
108 | virtual void writeToStdin( const QString& buf ); | ||
109 | virtual void closeStdin(); | ||
110 | |||
111 | protected: // ### or private? | ||
112 | void connectNotify( const char * signal ); | ||
113 | void disconnectNotify( const char * signal ); | ||
114 | private: | ||
115 | void setIoRedirection( bool value ); | ||
116 | void setNotifyOnExit( bool value ); | ||
117 | void setWroteStdinConnected( bool value ); | ||
118 | |||
119 | void init(); | ||
120 | void reset(); | ||
121 | #if defined(Q_OS_WIN32) | ||
122 | uint readStddev( HANDLE dev, char *buf, uint bytes ); | ||
123 | #endif | ||
124 | bool scanNewline( bool stdOut, QByteArray *store ); | ||
125 | |||
126 | QByteArray* bufStdout(); | ||
127 | QByteArray* bufStderr(); | ||
128 | void consumeBufStdout( int consume ); | ||
129 | void consumeBufStderr( int consume ); | ||
130 | |||
131 | private slots: | ||
132 | void socketRead( int fd ); | ||
133 | void socketWrite( int fd ); | ||
134 | void timeout(); | ||
135 | void closeStdinLaunch(); | ||
136 | |||
137 | private: | ||
138 | QProcessPrivate *d; | ||
139 | #ifndef QT_NO_DIR | ||
140 | QDir workingDir; | ||
141 | #endif | ||
142 | QStringList _arguments; | ||
143 | |||
144 | int exitStat; // exit status | ||
145 | bool exitNormal; // normal exit? | ||
146 | bool ioRedirection; // automatically set be (dis)connectNotify | ||
147 | bool notifyOnExit; // automatically set be (dis)connectNotify | ||
148 | bool wroteToStdinConnected; // automatically set be (dis)connectNotify | ||
149 | |||
150 | bool readStdoutCalled; | ||
151 | bool readStderrCalled; | ||
152 | int comms; | ||
153 | |||
154 | friend class QProcessPrivate; | ||
155 | #if defined(Q_OS_UNIX) || defined(_OS_UNIX) || defined(UNIX) | ||
156 | friend class QProcessManager; | ||
157 | friend class QProc; | ||
158 | #endif | ||
159 | }; | ||
160 | |||
161 | #endif // QT_NO_PROCESS | ||
162 | |||
163 | #endif // QPROCESS_H | ||