1// qprocess.sip generated by MetaSIP
2//
3// This file is part of the QtCore Python extension module.
4//
5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
6//
7// This file is part of PyQt5.
8//
9// This file may be used under the terms of the GNU General Public License
10// version 3.0 as published by the Free Software Foundation and appearing in
11// the file LICENSE included in the packaging of this file.  Please review the
12// following information to ensure the GNU General Public License version 3.0
13// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
14//
15// If you do not wish to use this file under the terms of the GPL version 3.0
16// then you may purchase a commercial license.  For more information contact
17// info@riverbankcomputing.com.
18//
19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
22
23%If (WS_WIN)
24%If (PyQt_Process)
25typedef void *Q_PID;
26%End
27%End
28%If (WS_X11 || WS_MACX)
29%If (PyQt_Process)
30typedef qint64 Q_PID;
31%End
32%End
33%If (PyQt_Process)
34
35class QProcess : QIODevice
36{
37%TypeHeaderCode
38#include <qprocess.h>
39%End
40
41public:
42    enum ExitStatus
43    {
44        NormalExit,
45        CrashExit,
46    };
47
48    enum ProcessError
49    {
50        FailedToStart,
51        Crashed,
52        Timedout,
53        ReadError,
54        WriteError,
55        UnknownError,
56    };
57
58    enum ProcessState
59    {
60        NotRunning,
61        Starting,
62        Running,
63    };
64
65    enum ProcessChannel
66    {
67        StandardOutput,
68        StandardError,
69    };
70
71    enum ProcessChannelMode
72    {
73        SeparateChannels,
74        MergedChannels,
75        ForwardedChannels,
76%If (Qt_5_2_0 -)
77        ForwardedOutputChannel,
78%End
79%If (Qt_5_2_0 -)
80        ForwardedErrorChannel,
81%End
82    };
83
84    explicit QProcess(QObject *parent /TransferThis/ = 0);
85    virtual ~QProcess();
86    void start(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode = QIODevice::ReadWrite) /HoldGIL/;
87    void start(const QString &command, QIODevice::OpenMode mode = QIODevice::ReadWrite) /HoldGIL/;
88%If (Qt_5_1_0 -)
89    void start(QIODevice::OpenMode mode = QIODevice::ReadWrite) /HoldGIL/;
90%End
91    QProcess::ProcessChannel readChannel() const;
92    void setReadChannel(QProcess::ProcessChannel channel);
93    void closeReadChannel(QProcess::ProcessChannel channel);
94    void closeWriteChannel();
95    QString workingDirectory() const;
96    void setWorkingDirectory(const QString &dir);
97    QProcess::ProcessError error() const;
98    QProcess::ProcessState state() const;
99    Q_PID pid() const;
100    bool waitForStarted(int msecs = 30000) /ReleaseGIL/;
101    virtual bool waitForReadyRead(int msecs = 30000) /ReleaseGIL/;
102    virtual bool waitForBytesWritten(int msecs = 30000) /ReleaseGIL/;
103    bool waitForFinished(int msecs = 30000) /ReleaseGIL/;
104    QByteArray readAllStandardOutput() /ReleaseGIL/;
105    QByteArray readAllStandardError() /ReleaseGIL/;
106    int exitCode() const;
107    QProcess::ExitStatus exitStatus() const;
108    virtual qint64 bytesAvailable() const;
109    virtual qint64 bytesToWrite() const;
110    virtual bool isSequential() const;
111    virtual bool canReadLine() const;
112    virtual void close();
113    virtual bool atEnd() const;
114    static int execute(const QString &program, const QStringList &arguments) /ReleaseGIL/;
115    static int execute(const QString &program) /ReleaseGIL/;
116    static bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid = 0);
117    static bool startDetached(const QString &program, const QStringList &arguments);
118    static bool startDetached(const QString &program);
119%If (Qt_5_10_0 -)
120    bool startDetached(qint64 *pid = 0);
121%End
122    static QStringList systemEnvironment();
123    QProcess::ProcessChannelMode processChannelMode() const;
124    void setProcessChannelMode(QProcess::ProcessChannelMode mode);
125    void setStandardInputFile(const QString &fileName);
126    void setStandardOutputFile(const QString &fileName, QIODevice::OpenMode mode = QIODevice::Truncate);
127    void setStandardErrorFile(const QString &fileName, QIODevice::OpenMode mode = QIODevice::Truncate);
128    void setStandardOutputProcess(QProcess *destination);
129
130public slots:
131    void terminate();
132    void kill();
133
134signals:
135    void started();
136    void finished(int exitCode, QProcess::ExitStatus exitStatus);
137    void error(QProcess::ProcessError error);
138    void stateChanged(QProcess::ProcessState state);
139    void readyReadStandardOutput();
140    void readyReadStandardError();
141%If (Qt_5_6_0 -)
142    void errorOccurred(QProcess::ProcessError error);
143%End
144
145protected:
146    void setProcessState(QProcess::ProcessState state);
147    virtual void setupChildProcess();
148    virtual SIP_PYOBJECT readData(qint64 maxlen) /TypeHint="Py_v3:bytes;str",ReleaseGIL/ [qint64 (char *data, qint64 maxlen)];
149%MethodCode
150        // Return the data read or None if there was an error.
151        if (a0 < 0)
152        {
153            PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
154            sipIsErr = 1;
155        }
156        else
157        {
158            char *s = new char[a0];
159            qint64 len;
160
161            Py_BEGIN_ALLOW_THREADS
162        #if defined(SIP_PROTECTED_IS_PUBLIC)
163            len = sipSelfWasArg ? sipCpp->QProcess::readData(s, a0) : sipCpp->readData(s, a0);
164        #else
165            len = sipCpp->sipProtectVirt_readData(sipSelfWasArg, s, a0);
166        #endif
167            Py_END_ALLOW_THREADS
168
169            if (len < 0)
170            {
171                Py_INCREF(Py_None);
172                sipRes = Py_None;
173            }
174            else
175            {
176                sipRes = SIPBytes_FromStringAndSize(s, len);
177
178                if (!sipRes)
179                    sipIsErr = 1;
180            }
181
182            delete[] s;
183        }
184%End
185
186    virtual qint64 writeData(const char *data /Array/, qint64 len /ArraySize/) /ReleaseGIL/;
187
188public:
189    void setProcessEnvironment(const QProcessEnvironment &environment);
190    QProcessEnvironment processEnvironment() const;
191    QString program() const;
192%If (Qt_5_1_0 -)
193    void setProgram(const QString &program);
194%End
195    QStringList arguments() const;
196%If (Qt_5_1_0 -)
197    void setArguments(const QStringList &arguments);
198%End
199%If (Qt_5_1_0 -)
200    virtual bool open(QIODevice::OpenMode mode = QIODevice::ReadWrite) /ReleaseGIL/;
201%End
202%If (Qt_5_2_0 -)
203
204    enum InputChannelMode
205    {
206        ManagedInputChannel,
207        ForwardedInputChannel,
208    };
209
210%End
211%If (Qt_5_2_0 -)
212    QProcess::InputChannelMode inputChannelMode() const;
213%End
214%If (Qt_5_2_0 -)
215    void setInputChannelMode(QProcess::InputChannelMode mode);
216%End
217%If (Qt_5_2_0 -)
218    static QString nullDevice();
219%End
220%If (Qt_5_3_0 -)
221    qint64 processId() const;
222%End
223};
224
225%End
226%If (PyQt_Process)
227
228class QProcessEnvironment
229{
230%TypeHeaderCode
231#include <qprocess.h>
232%End
233
234public:
235    QProcessEnvironment();
236    QProcessEnvironment(const QProcessEnvironment &other);
237    ~QProcessEnvironment();
238    bool operator==(const QProcessEnvironment &other) const;
239    bool operator!=(const QProcessEnvironment &other) const;
240    bool isEmpty() const;
241    void clear();
242    bool contains(const QString &name) const;
243    void insert(const QString &name, const QString &value);
244    void insert(const QProcessEnvironment &e);
245    void remove(const QString &name);
246    QString value(const QString &name, const QString &defaultValue = QString()) const;
247    QStringList toStringList() const;
248    static QProcessEnvironment systemEnvironment();
249    QStringList keys() const;
250    void swap(QProcessEnvironment &other /Constrained/);
251};
252
253%End
254