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
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties | List of all members
Zbl::ZProcess Class Reference

QML/Javascript wrapper for the QProcess class, allows QML programs to spawn and communicate with a background operating system process. More...

#include <ZProcess.h>

Inheritance diagram for Zbl::ZProcess:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZProcess:
Collaboration graph
[legend]

Public Types

enum  ProcessError {
  FailedToStart = QProcess::FailedToStart, Crashed = QProcess::Crashed, Timedout = QProcess::Timedout, ReadError = QProcess::ReadError,
  WriteError = QProcess::WriteError, UnknownError = QProcess::UnknownError
}
 
enum  ProcessState { NotRunning = QProcess::NotRunning, Starting = QProcess::Starting, Running = QProcess::Running }
 
enum  ProcessChannel { StandardOutput = QProcess::StandardOutput, StandardError = QProcess::StandardError }
 
enum  ProcessChannelMode {
  SeparateChannels = QProcess::SeparateChannels, MergedChannels = QProcess::MergedChannels, ForwardedChannels = QProcess::ForwardedChannels, ForwardedOutputChannel = QProcess::ForwardedOutputChannel,
  ForwardedErrorChannel = QProcess::ForwardedErrorChannel
}
 
enum  ExitStatus { NormalExit = QProcess::NormalExit, CrashExit = QProcess::CrashExit }
 

Public Slots

void start (int mode=static_cast< int >(ZioDevice::ReadWrite))
 Starts the process. More...
 
void closeWriteChannel ()
 Schedules the write channel of the process to close once all input data has been read by the process. More...
 
void getQDevice (QIODevice **device)
 Obtains the QIODevice pointer for this object. More...
 

Signals

void tagsChanged ()
 
void started ()
 
void finished (int exitCode, QProcess::ExitStatus exitStatus)
 
void errorOccurred (QProcess::ProcessError error)
 
void stateChanged (QProcess::ProcessState state, QPrivateSignal)
 
void readyReadStandardOutput (QPrivateSignal)
 
void readyReadStandardError (QPrivateSignal)
 

Public Member Functions

 ZProcess (QObject *parent=nullptr)
 
virtual ~ZProcess ()
 
QObject * getJsDevice ()
 
QVariant getTags ()
 
QStringList getArguments ()
 Returns the arguments that will be passed to the process when it starts. More...
 
void setArguments (const QStringList &arguments)
 Sets the arguments that will be passed to the process when it starts. More...
 
QString getProgram () const
 Returns the path to the program the process will be started with. More...
 
void setProgram (const QString &program)
 Sets the path to the program the process will be started with. More...
 
void setProcessChannelMode (int mode)
 Sets the process channel mode that will be used the next time the process starts. More...
 
int getProcessChannelMode () const
 Returns the channel mode of the QProcess standard output and standard error channels. More...
 
void setReadChannel (int channel)
 Determine which read channel is currently active. More...
 
int getReadChannel () const
 Obtain the current read channel. More...
 
qint64 getProcessID () const
 Obtain the process ID. Note that Linux will reuse process IDs. They are ephemeral, not unique. More...
 
int getState () const
 Obtains the current process state. More...
 
int getError () const
 Obtains the current error state. More...
 
int exitCode () const
 Obtains the exit code of the last process that finished. More...
 
int exitStatus () const
 Obtains the exit status of the last process that finished. More...
 
Q_INVOKABLE void envClear ()
 Clears the process execution environment that will be passed to the child process. More...
 
Q_INVOKABLE QStringList envGetList ()
 Obtains the list of process environment variables that will be passed to the child process. More...
 
Q_INVOKABLE void envSetValue (const QString &name, const QString &value)
 Sets an environment variable that will be passed to the child process. More...
 
Q_INVOKABLE QString envGetValue (const QString &name)
 Returns the value of an environment variable that will be passed to the child process. More...
 
Q_INVOKABLE bool envValueExists (const QString &name)
 Determine if an environment variable has been set to be passed to the child process. More...
 
Q_INVOKABLE void closeReadChannel (int channel)
 Closes the specified read channel of the process. More...
 
Q_INVOKABLE QObject * readAllStandardError ()
 Obtains all available data from the process's stderr channel. More...
 
Q_INVOKABLE QObject * readAllStandardOutput ()
 Obtains all available data from the process's stdout channel. More...
 

Static Public Member Functions

static void registerType ()
 Registers ZFile as a QML type. More...
 

Protected Member Functions

ZBL_DECLARE_LOGGED_OBJECT void initZioDevice ()
 Construct and connect a ZioDevice object that presents a Javascript interface to this process's QIODevice object. More...
 
void createTags ()
 Create the m_tag object that presents a Javascript interface for QProcess enumeration values. More...
 

Protected Attributes

QProcess * m_p
 Smart pointer to the embedded QFile object. More...
 
ZioDevicem_zd
 Pointer to QioDevice interface object. More...
 

Static Protected Attributes

static QVariant m_tags
 A QVariantMap used to pass QFile enumeration values to Javascript programs. More...
 

Properties

QObject device
 A ZioDevice object that represents the File's QioDevice interface. More...
 
QVariant tags
 A Javascript object containing QFile enumeration values. More...
 
QStringList arguments
 Set/get the argument list for the process. More...
 
QString program
 Set/get the program for the process. More...
 
int processChannelMode
 Set/get the process channel mode for the process. More...
 
int readChannel
 Set/get the current read channel. More...
 
qint64 processId
 Set/get the operating system process ID for the last process run by this object. More...
 
qint64 state
 Obtain the current process state. More...
 
qint64 error
 Obtain the process's current error state. More...
 

Detailed Description

QML/Javascript wrapper for the QProcess class, allows QML programs to spawn and communicate with a background operating system process.

Child process will inherit the originating process environment unless modified by calling envClear() or envSetValue().

Definition at line 20 of file ZProcess.h.

Member Enumeration Documentation

◆ ExitStatus

Enumerator
NormalExit 
CrashExit 

Definition at line 57 of file ZProcess.h.

◆ ProcessChannel

Enumerator
StandardOutput 
StandardError 

Definition at line 42 of file ZProcess.h.

◆ ProcessChannelMode

Enumerator
SeparateChannels 
MergedChannels 
ForwardedChannels 
ForwardedOutputChannel 
ForwardedErrorChannel 

Definition at line 48 of file ZProcess.h.

◆ ProcessError

Enumerator
FailedToStart 
Crashed 
Timedout 
ReadError 
WriteError 
UnknownError 

Definition at line 25 of file ZProcess.h.

◆ ProcessState

Enumerator
NotRunning 
Starting 
Running 

Definition at line 35 of file ZProcess.h.

Constructor & Destructor Documentation

◆ ZProcess()

Zbl::ZProcess::ZProcess ( QObject *  parent = nullptr)
explicit

Definition at line 13 of file ZProcess.cpp.

◆ ~ZProcess()

Zbl::ZProcess::~ZProcess ( )
virtual

Definition at line 34 of file ZProcess.cpp.

Member Function Documentation

◆ closeReadChannel()

void Zbl::ZProcess::closeReadChannel ( int  channel)

Closes the specified read channel of the process.

Parameters
channelThe read channel to close

Definition at line 154 of file ZProcess.cpp.

◆ closeWriteChannel

void Zbl::ZProcess::closeWriteChannel ( )
slot

Schedules the write channel of the process to close once all input data has been read by the process.

Definition at line 149 of file ZProcess.cpp.

◆ createTags()

void Zbl::ZProcess::createTags ( )
protected

Create the m_tag object that presents a Javascript interface for QProcess enumeration values.

Definition at line 55 of file ZProcess.cpp.

◆ envClear()

void Zbl::ZProcess::envClear ( )

Clears the process execution environment that will be passed to the child process.

Definition at line 218 of file ZProcess.cpp.

◆ envGetList()

QStringList Zbl::ZProcess::envGetList ( )

Obtains the list of process environment variables that will be passed to the child process.

Returns
List of environment value strings

Definition at line 223 of file ZProcess.cpp.

◆ envGetValue()

QString Zbl::ZProcess::envGetValue ( const QString &  name)

Returns the value of an environment variable that will be passed to the child process.

Returns
A string

Definition at line 235 of file ZProcess.cpp.

◆ envSetValue()

void Zbl::ZProcess::envSetValue ( const QString &  name,
const QString &  value 
)

Sets an environment variable that will be passed to the child process.

Definition at line 228 of file ZProcess.cpp.

◆ envValueExists()

bool Zbl::ZProcess::envValueExists ( const QString &  name)

Determine if an environment variable has been set to be passed to the child process.

Returns
true if a variable of the specified name exists, false otherwise

Definition at line 240 of file ZProcess.cpp.

◆ errorOccurred

void Zbl::ZProcess::errorOccurred ( QProcess::ProcessError  error)
signal

◆ exitCode()

int Zbl::ZProcess::exitCode ( ) const

Obtains the exit code of the last process that finished.

Not valid unless exitStatus() returns ExitNormal.

Returns
exit code of the last process that finished

Definition at line 208 of file ZProcess.cpp.

◆ exitStatus()

int Zbl::ZProcess::exitStatus ( ) const

Obtains the exit status of the last process that finished.

Returns
A ZProcess:ExitStatus value

Definition at line 213 of file ZProcess.cpp.

◆ finished

void Zbl::ZProcess::finished ( int  exitCode,
QProcess::ExitStatus  exitStatus 
)
signal

◆ getArguments()

QStringList Zbl::ZProcess::getArguments ( )

Returns the arguments that will be passed to the process when it starts.

Returns
A list of program arguments
See also
ZProcess::setArgumets

Definition at line 129 of file ZProcess.cpp.

◆ getError()

int Zbl::ZProcess::getError ( ) const

Obtains the current error state.

Returns
A QProcess::ProcessError value indicates the current error state of the process

Definition at line 193 of file ZProcess.cpp.

◆ getJsDevice()

QObject * Zbl::ZProcess::getJsDevice ( )

Definition at line 89 of file ZProcess.cpp.

◆ getProcessChannelMode()

int Zbl::ZProcess::getProcessChannelMode ( ) const

Returns the channel mode of the QProcess standard output and standard error channels.

Returns
A QProcess::ProcessChannelMode value

Definition at line 203 of file ZProcess.cpp.

◆ getProcessID()

qint64 Zbl::ZProcess::getProcessID ( ) const

Obtain the process ID. Note that Linux will reuse process IDs. They are ephemeral, not unique.

Returns
ID of the last process that run under this ZProcess instance.

Definition at line 159 of file ZProcess.cpp.

◆ getProgram()

QString Zbl::ZProcess::getProgram ( ) const

Returns the path to the program the process will be started with.

Returns
Path to the program to run.

Definition at line 139 of file ZProcess.cpp.

◆ getQDevice

void Zbl::ZProcess::getQDevice ( QIODevice **  device)
slot

Obtains the QIODevice pointer for this object.

Connect this slot to ZioDevice::getCurrentDevice signal with a direct connection. This mechanism allows multiple Zuble QML types to share the QIODevice API definition.

// TBD: should we have used multiple inheritance instead?

Parameters
devicePointer to a pointer to a QIODevice that should receive the pointer to QProcess object cast to QIODevice pointer;

Definition at line 96 of file ZProcess.cpp.

Referenced by initZioDevice().

◆ getReadChannel()

int Zbl::ZProcess::getReadChannel ( ) const

Obtain the current read channel.

Returns
A QProcess::ProcessChannel value

Definition at line 164 of file ZProcess.cpp.

◆ getState()

int Zbl::ZProcess::getState ( ) const

Obtains the current process state.

Returns
A QProcess::ProcessState value indicates the current process state of the process

Definition at line 188 of file ZProcess.cpp.

◆ getTags()

QVariant Zbl::ZProcess::getTags ( )

Definition at line 84 of file ZProcess.cpp.

◆ initZioDevice()

void Zbl::ZProcess::initZioDevice ( )
protected

Construct and connect a ZioDevice object that presents a Javascript interface to this process's QIODevice object.

Definition at line 47 of file ZProcess.cpp.

◆ readAllStandardError()

QObject * Zbl::ZProcess::readAllStandardError ( )

Obtains all available data from the process's stderr channel.

Returns
A ZByteArray containing data that was read from the process.

Definition at line 174 of file ZProcess.cpp.

◆ readAllStandardOutput()

QObject * Zbl::ZProcess::readAllStandardOutput ( )

Obtains all available data from the process's stdout channel.

Returns
A ZByteArray containing data that was read from the process.

Definition at line 181 of file ZProcess.cpp.

◆ readyReadStandardError

void Zbl::ZProcess::readyReadStandardError ( QPrivateSignal  )
signal

◆ readyReadStandardOutput

void Zbl::ZProcess::readyReadStandardOutput ( QPrivateSignal  )
signal

◆ registerType()

void Zbl::ZProcess::registerType ( )
static

Registers ZFile as a QML type.

Definition at line 40 of file ZProcess.cpp.

Referenced by Zbl::Zblcore::registerTypes().

◆ setArguments()

void Zbl::ZProcess::setArguments ( const QStringList &  arguments)

Sets the arguments that will be passed to the process when it starts.

Parameters
Alist of program arguments
See also
ZProcess::setArgumets

Definition at line 134 of file ZProcess.cpp.

◆ setProcessChannelMode()

void Zbl::ZProcess::setProcessChannelMode ( int  mode)

Sets the process channel mode that will be used the next time the process starts.

Parameters
modeThe input channel mode to use

Definition at line 198 of file ZProcess.cpp.

◆ setProgram()

void Zbl::ZProcess::setProgram ( const QString &  program)

Sets the path to the program the process will be started with.

This method must be called before calling start.

Parameters
programPath to the program to run.

Definition at line 144 of file ZProcess.cpp.

◆ setReadChannel()

void Zbl::ZProcess::setReadChannel ( int  channel)

Determine which read channel is currently active.

Use this method to switch between reading stderr and stdout channels.

Parameters
AQProcess::ProcessChannel value to set the current read channel.

Definition at line 169 of file ZProcess.cpp.

◆ start

void Zbl::ZProcess::start ( int  mode = static_cast<int>(ZioDevice::ReadWrite))
slot

Starts the process.

Parameters
modeOpen mode of the process. ZioDevice::ReadWrite is default.

Script threads use ZProcess.device.tags.ReadWrite etc...

See also
ZioDevice::OpenMode

Definition at line 124 of file ZProcess.cpp.

◆ started

void Zbl::ZProcess::started ( )
signal

Referenced by ZProcess().

◆ stateChanged

void Zbl::ZProcess::stateChanged ( QProcess::ProcessState  state,
QPrivateSignal   
)
signal

◆ tagsChanged

void Zbl::ZProcess::tagsChanged ( )
signal

Member Data Documentation

◆ m_p

QProcess* Zbl::ZProcess::m_p
protected

◆ m_tags

QVariant Zbl::ZProcess::m_tags
staticprotected

A QVariantMap used to pass QFile enumeration values to Javascript programs.

Definition at line 423 of file ZProcess.h.

Referenced by createTags(), and getTags().

◆ m_zd

ZioDevice* Zbl::ZProcess::m_zd
protected

Pointer to QioDevice interface object.

Definition at line 416 of file ZProcess.h.

Referenced by getJsDevice(), and initZioDevice().

Property Documentation

◆ arguments

QStringList Zbl::ZProcess::arguments
readwrite

Set/get the argument list for the process.

Definition at line 93 of file ZProcess.h.

◆ device

QObject Zbl::ZProcess::device
read

A ZioDevice object that represents the File's QioDevice interface.

Definition at line 81 of file ZProcess.h.

◆ error

qint64 Zbl::ZProcess::error
read

Obtain the process's current error state.

Definition at line 132 of file ZProcess.h.

◆ processChannelMode

int Zbl::ZProcess::processChannelMode
readwrite

Set/get the process channel mode for the process.

Definition at line 105 of file ZProcess.h.

◆ processId

qint64 Zbl::ZProcess::processId
read

Set/get the operating system process ID for the last process run by this object.

Note that process IDs are reused by Linux.

Definition at line 120 of file ZProcess.h.

◆ program

QString Zbl::ZProcess::program
readwrite

Set/get the program for the process.

Definition at line 99 of file ZProcess.h.

◆ readChannel

int Zbl::ZProcess::readChannel
readwrite

Set/get the current read channel.

Definition at line 111 of file ZProcess.h.

◆ state

qint64 Zbl::ZProcess::state
read

Obtain the current process state.

Definition at line 126 of file ZProcess.h.

◆ tags

QVariant Zbl::ZProcess::tags
read

A Javascript object containing QFile enumeration values.

Definition at line 87 of file ZProcess.h.


The documentation for this class was generated from the following files: