WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZProcess.h
Go to the documentation of this file.
1 #ifndef ZPROCESS_H
2 #define ZPROCESS_H
3 
4 #include <QObject>
5 #include "zglobal.h"
6 #include "ZioDevice.h"
7 #include <QProcess>
8 
9 namespace Zbl
10 {
11 
20 class ZProcess : public QObject
21 {
22  Q_OBJECT
23 public:
24 
25  enum ProcessError {
26  FailedToStart = QProcess::FailedToStart,
27  Crashed = QProcess::Crashed,
28  Timedout = QProcess::Timedout,
29  ReadError = QProcess::ReadError,
30  WriteError = QProcess::WriteError,
31  UnknownError = QProcess::UnknownError
32  };
33  Q_ENUM(ProcessError)
34 
35  enum ProcessState {
36  NotRunning = QProcess::NotRunning,
37  Starting = QProcess::Starting,
38  Running = QProcess::Running
39  };
40  Q_ENUM(ProcessState)
41 
43  StandardOutput = QProcess::StandardOutput,
44  StandardError = QProcess::StandardError
45  };
46  Q_ENUM(ProcessChannel)
47 
49  SeparateChannels = QProcess::SeparateChannels,
50  MergedChannels = QProcess::MergedChannels,
51  ForwardedChannels = QProcess::ForwardedChannels,
52  ForwardedOutputChannel = QProcess::ForwardedOutputChannel,
53  ForwardedErrorChannel = QProcess::ForwardedErrorChannel
54  };
55  Q_ENUM(ProcessChannelMode)
56 
57  enum ExitStatus {
58  NormalExit = QProcess::NormalExit,
59  CrashExit = QProcess::CrashExit
60  };
61  Q_ENUM(ExitStatus)
62 
63 
64  explicit ZProcess(QObject *parent = nullptr);
65  virtual ~ZProcess();
66 
67  QObject* getJsDevice();
68  QVariant getTags();
69 
73  static void registerType();
74 
75 
81  Q_PROPERTY(QObject* device READ getJsDevice CONSTANT)
82 
83 
87  Q_PROPERTY(QVariant tags READ getTags NOTIFY tagsChanged)
88 
93  Q_PROPERTY(QStringList arguments READ getArguments WRITE setArguments)
94 
99  Q_PROPERTY(QString program READ getProgram WRITE setProgram)
100 
106 
111  Q_PROPERTY(int readChannel READ getReadChannel WRITE setReadChannel)
112 
120  Q_PROPERTY(qint64 processId READ getProcessID)
121 
126  Q_PROPERTY(qint64 state READ getState)
127 
132  Q_PROPERTY(qint64 error READ getError)
133 
134 
135 #if 0
136 
146  Q_INVOKABLE void release();
147 #endif
148 
149 
159  QStringList getArguments();
160 
170  void setArguments(const QStringList &arguments);
171 
178  QString getProgram() const;
179 
187  void setProgram(const QString &program);
188 
189 
197  void setProcessChannelMode(int mode);
198 
205  int getProcessChannelMode() const;
206 
207 
216  void setReadChannel(int channel);
217 
224  int getReadChannel() const;
225 
226 
234  qint64 getProcessID() const;
235 
243  int getState() const;
244 
252  int getError() const;
253 
262  int exitCode() const;
263 
270  int exitStatus() const;
271 
272 
273  // working directory set/get?
274 
280  Q_INVOKABLE void envClear();
281 
290  Q_INVOKABLE QStringList envGetList();
291 
297  Q_INVOKABLE void envSetValue(const QString& name, const QString& value);
298 
306  Q_INVOKABLE QString envGetValue(const QString& name);
307 
315  Q_INVOKABLE bool envValueExists(const QString& name);
316 
323  Q_INVOKABLE void closeReadChannel(int channel);
324 
331  Q_INVOKABLE QObject* readAllStandardError();
332 
339  Q_INVOKABLE QObject* readAllStandardOutput();
340 
341 
342 public slots:
343 
354  void start(int mode = static_cast<int>(ZioDevice::ReadWrite));
355 
361  void closeWriteChannel();
362 
377  void getQDevice(QIODevice** device); // for ZioDevice::getCurrentDevice
378 
379 signals:
380 
381  void tagsChanged();
382 
383  void started();
384  void finished(int exitCode, QProcess::ExitStatus exitStatus);
385  void errorOccurred(QProcess::ProcessError error);
386  void stateChanged(QProcess::ProcessState state, QPrivateSignal);
387  void readyReadStandardOutput(QPrivateSignal);
388  void readyReadStandardError(QPrivateSignal);
389 
390 
391 protected:
392 
394 
399  void initZioDevice();
400 
405  void createTags();
406 
407 
411  QProcess* m_p;
412 
417 
423  static QVariant m_tags;
424 };
425 
426 } // Zbl
427 
428 #endif // ZPROCESS_H
virtual ~ZProcess()
Definition: ZProcess.cpp:34
void getQDevice(QIODevice **device)
Obtains the QIODevice pointer for this object.
Definition: ZProcess.cpp:96
Q_INVOKABLE void envClear()
Clears the process execution environment that will be passed to the child process.
Definition: ZProcess.cpp:218
int exitCode() const
Obtains the exit code of the last process that finished.
Definition: ZProcess.cpp:208
void readyReadStandardError(QPrivateSignal)
QVariant getTags()
Definition: ZProcess.cpp:84
void errorOccurred(QProcess::ProcessError error)
QML/Javascript wrapper for the QProcess class, allows QML programs to spawn and communicate with a ba...
Definition: ZProcess.h:20
void stateChanged(QProcess::ProcessState state, QPrivateSignal)
int readChannel
Set/get the current read channel.
Definition: ZProcess.h:111
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
void start(int mode=static_cast< int >(ZioDevice::ReadWrite))
Starts the process.
Definition: ZProcess.cpp:124
void tagsChanged()
ZBL_DECLARE_LOGGED_OBJECT void initZioDevice()
Construct and connect a ZioDevice object that presents a Javascript interface to this process&#39;s QIODe...
Definition: ZProcess.cpp:47
QObject * getJsDevice()
Definition: ZProcess.cpp:89
Q_INVOKABLE void envSetValue(const QString &name, const QString &value)
Sets an environment variable that will be passed to the child process.
Definition: ZProcess.cpp:228
void finished(int exitCode, QProcess::ExitStatus exitStatus)
Q_INVOKABLE void closeReadChannel(int channel)
Closes the specified read channel of the process.
Definition: ZProcess.cpp:154
int getReadChannel() const
Obtain the current read channel.
Definition: ZProcess.cpp:164
ZioDevice * m_zd
Pointer to QioDevice interface object.
Definition: ZProcess.h:416
void readyReadStandardOutput(QPrivateSignal)
void closeWriteChannel()
Schedules the write channel of the process to close once all input data has been read by the process...
Definition: ZProcess.cpp:149
QVariant tags
A Javascript object containing QFile enumeration values.
Definition: ZProcess.h:87
Q_INVOKABLE QString envGetValue(const QString &name)
Returns the value of an environment variable that will be passed to the child process.
Definition: ZProcess.cpp:235
void setArguments(const QStringList &arguments)
Sets the arguments that will be passed to the process when it starts.
Definition: ZProcess.cpp:134
void createTags()
Create the m_tag object that presents a Javascript interface for QProcess enumeration values...
Definition: ZProcess.cpp:55
Q_INVOKABLE QStringList envGetList()
Obtains the list of process environment variables that will be passed to the child process...
Definition: ZProcess.cpp:223
QString program
Set/get the program for the process.
Definition: ZProcess.h:99
qint64 getProcessID() const
Obtain the process ID. Note that Linux will reuse process IDs. They are ephemeral, not unique.
Definition: ZProcess.cpp:159
Q_INVOKABLE bool envValueExists(const QString &name)
Determine if an environment variable has been set to be passed to the child process.
Definition: ZProcess.cpp:240
void setReadChannel(int channel)
Determine which read channel is currently active.
Definition: ZProcess.cpp:169
static void registerType()
Registers ZFile as a QML type.
Definition: ZProcess.cpp:40
int exitStatus() const
Obtains the exit status of the last process that finished.
Definition: ZProcess.cpp:213
qint64 state
Obtain the current process state.
Definition: ZProcess.h:126
A javascript wrapper for QIODevice.
Definition: ZioDevice.h:40
ZProcess(QObject *parent=nullptr)
Definition: ZProcess.cpp:13
Definition: ZAndGate.cpp:6
void setProcessChannelMode(int mode)
Sets the process channel mode that will be used the next time the process starts. ...
Definition: ZProcess.cpp:198
int getError() const
Obtains the current error state.
Definition: ZProcess.cpp:193
qint64 error
Obtain the process&#39;s current error state.
Definition: ZProcess.h:132
static QVariant m_tags
A QVariantMap used to pass QFile enumeration values to Javascript programs.
Definition: ZProcess.h:423
void setProgram(const QString &program)
Sets the path to the program the process will be started with.
Definition: ZProcess.cpp:144
Q_INVOKABLE QObject * readAllStandardOutput()
Obtains all available data from the process&#39;s stdout channel.
Definition: ZProcess.cpp:181
QStringList arguments
Set/get the argument list for the process.
Definition: ZProcess.h:93
int getProcessChannelMode() const
Returns the channel mode of the QProcess standard output and standard error channels.
Definition: ZProcess.cpp:203
Q_INVOKABLE QObject * readAllStandardError()
Obtains all available data from the process&#39;s stderr channel.
Definition: ZProcess.cpp:174
qint64 processId
Set/get the operating system process ID for the last process run by this object.
Definition: ZProcess.h:120
QStringList getArguments()
Returns the arguments that will be passed to the process when it starts.
Definition: ZProcess.cpp:129
QObject device
A ZioDevice object that represents the File&#39;s QioDevice interface.
Definition: ZProcess.h:81
int processChannelMode
Set/get the process channel mode for the process.
Definition: ZProcess.h:105
int getState() const
Obtains the current process state.
Definition: ZProcess.cpp:188
QProcess * m_p
Smart pointer to the embedded QFile object.
Definition: ZProcess.h:411
QString getProgram() const
Returns the path to the program the process will be started with.
Definition: ZProcess.cpp:139