1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef Q3PROCESS_H
|
---|
43 | #define Q3PROCESS_H
|
---|
44 |
|
---|
45 | #include <QtCore/qobject.h>
|
---|
46 | #include <QtCore/qstringlist.h>
|
---|
47 | #include <QtCore/qdir.h>
|
---|
48 |
|
---|
49 | QT_BEGIN_HEADER
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | QT_MODULE(Qt3SupportLight)
|
---|
54 |
|
---|
55 | #ifndef QT_NO_PROCESS
|
---|
56 |
|
---|
57 | class Q3ProcessPrivate;
|
---|
58 | class Q3Membuf;
|
---|
59 |
|
---|
60 | class Q_COMPAT_EXPORT Q3Process : public QObject
|
---|
61 | {
|
---|
62 | Q_OBJECT
|
---|
63 | public:
|
---|
64 | Q3Process( QObject *parent=0, const char *name=0 );
|
---|
65 | Q3Process( const QString& arg0, QObject *parent=0, const char *name=0 );
|
---|
66 | Q3Process( const QStringList& args, QObject *parent=0, const char *name=0 );
|
---|
67 | ~Q3Process();
|
---|
68 |
|
---|
69 | // set and get the arguments and working directory
|
---|
70 | QStringList arguments() const;
|
---|
71 | void clearArguments();
|
---|
72 | virtual void setArguments( const QStringList& args );
|
---|
73 | virtual void addArgument( const QString& arg );
|
---|
74 | #ifndef QT_NO_DIR
|
---|
75 | QDir workingDirectory() const;
|
---|
76 | virtual void setWorkingDirectory( const QDir& dir );
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | // set and get the comms wanted
|
---|
80 | enum Communication { Stdin=0x01, Stdout=0x02, Stderr=0x04, DupStderr=0x08 };
|
---|
81 | void setCommunication( int c );
|
---|
82 | int communication() const;
|
---|
83 |
|
---|
84 | // start the execution
|
---|
85 | virtual bool start( QStringList *env=0 );
|
---|
86 | virtual bool launch( const QString& buf, QStringList *env=0 );
|
---|
87 | virtual bool launch( const QByteArray& buf, QStringList *env=0 );
|
---|
88 |
|
---|
89 | // inquire the status
|
---|
90 | bool isRunning() const;
|
---|
91 | bool normalExit() const;
|
---|
92 | int exitStatus() const;
|
---|
93 |
|
---|
94 | // reading
|
---|
95 | virtual QByteArray readStdout();
|
---|
96 | virtual QByteArray readStderr();
|
---|
97 | bool canReadLineStdout() const;
|
---|
98 | bool canReadLineStderr() const;
|
---|
99 | virtual QString readLineStdout();
|
---|
100 | virtual QString readLineStderr();
|
---|
101 |
|
---|
102 | // get platform dependent process information
|
---|
103 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
|
---|
104 | typedef void* PID;
|
---|
105 | #else
|
---|
106 | typedef Q_LONG PID;
|
---|
107 | #endif
|
---|
108 | PID processIdentifier();
|
---|
109 |
|
---|
110 | void flushStdin();
|
---|
111 |
|
---|
112 | Q_SIGNALS:
|
---|
113 | void readyReadStdout();
|
---|
114 | void readyReadStderr();
|
---|
115 | void processExited();
|
---|
116 | void wroteToStdin();
|
---|
117 | void launchFinished();
|
---|
118 |
|
---|
119 | public Q_SLOTS:
|
---|
120 | // end the execution
|
---|
121 | void tryTerminate() const;
|
---|
122 | void kill() const;
|
---|
123 |
|
---|
124 | // input
|
---|
125 | virtual void writeToStdin( const QByteArray& buf );
|
---|
126 | virtual void writeToStdin( const QString& buf );
|
---|
127 | virtual void closeStdin();
|
---|
128 |
|
---|
129 | protected: // ### or private?
|
---|
130 | void connectNotify( const char * signal );
|
---|
131 | void disconnectNotify( const char * signal );
|
---|
132 | private:
|
---|
133 | void setIoRedirection( bool value );
|
---|
134 | void setNotifyOnExit( bool value );
|
---|
135 | void setWroteStdinConnected( bool value );
|
---|
136 |
|
---|
137 | void init();
|
---|
138 | void reset();
|
---|
139 | #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
|
---|
140 | uint readStddev( Qt::HANDLE dev, char *buf, uint bytes );
|
---|
141 | #endif
|
---|
142 | Q3Membuf* membufStdout();
|
---|
143 | Q3Membuf* membufStderr();
|
---|
144 |
|
---|
145 | private Q_SLOTS:
|
---|
146 | void socketRead( int fd );
|
---|
147 | void socketWrite( int fd );
|
---|
148 | void timeout();
|
---|
149 | void closeStdinLaunch();
|
---|
150 |
|
---|
151 | private:
|
---|
152 | Q3ProcessPrivate *d;
|
---|
153 | #ifndef QT_NO_DIR
|
---|
154 | QDir workingDir;
|
---|
155 | #endif
|
---|
156 | QStringList _arguments;
|
---|
157 |
|
---|
158 | int exitStat; // exit status
|
---|
159 | bool exitNormal; // normal exit?
|
---|
160 | bool ioRedirection; // automatically set be (dis)connectNotify
|
---|
161 | bool notifyOnExit; // automatically set be (dis)connectNotify
|
---|
162 | bool wroteToStdinConnected; // automatically set be (dis)connectNotify
|
---|
163 |
|
---|
164 | bool readStdoutCalled;
|
---|
165 | bool readStderrCalled;
|
---|
166 | int comms;
|
---|
167 |
|
---|
168 | friend class Q3ProcessPrivate;
|
---|
169 | #if defined(Q_OS_UNIX)
|
---|
170 | friend class Q3ProcessManager;
|
---|
171 | friend class QProc;
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
|
---|
175 | Q3Process( const Q3Process & );
|
---|
176 | Q3Process &operator=( const Q3Process & );
|
---|
177 | #endif
|
---|
178 | };
|
---|
179 |
|
---|
180 | #endif // QT_NO_PROCESS
|
---|
181 |
|
---|
182 | QT_END_NAMESPACE
|
---|
183 |
|
---|
184 | QT_END_HEADER
|
---|
185 |
|
---|
186 | #endif // Q3PROCESS_H
|
---|