Quark  0.1
ExternalCommandTask Class Reference

An abstract subclass of Task that runs an external command (a subprocess). More...

#include <ExternalCommandTask.h++>

Inheritance diagram for ExternalCommandTask:

Signals

void statusUpdated (const QString &status)
 Emitted whenever updateStatus() is called. More...
 
void finished ()
 Emitted when the task has finished executing. More...
 
void cancelled ()
 Emitted when the task has been cancelled. More...
 

Public Member Functions

virtual ~ExternalCommandTask ()
 Destructor. More...
 
QString executable () const
 Returns the path to the executable that will be run. More...
 
QStringList args () const
 Returns the arguments to the executable. More...
 
int exitCode () const
 Returns the exit code from the subprocess. More...
 
QString toString () const
 Returns a string representation of the task. More...
 
virtual void execute ()
 Specified by Task. More...
 
virtual bool cancel ()
 Specified by Task. More...
 
int id () const
 Returns the unique ID that was assigned to this task. More...
 
bool isRunning () const
 Tests if the task is currently executing. More...
 
bool isCancelling () const
 Tests if the task is currently cancelling. More...
 
bool isCancelled () const
 Tests if the task has been cancelled. More...
 
bool isFailed () const
 Tests if the task has failed. More...
 
bool isBackground () const
 Tests if the task is a background task. More...
 
QString error () const
 Returns the error message reported by this task upon failure, if any. More...
 
void setTimeout (int seconds)
 Sets the task's timeout, in seconds. More...
 
qint64 executionTime () const
 Returns the amount of time the task spent executing, or 0 if the task has not finished executing. More...
 

Static Public Attributes

static const int DEFAULT_TIMEOUT
 The default timeout interval, in seconds. More...
 

Protected Member Functions

 ExternalCommandTask (const QString &executable)
 Constructs a new ExternalCommandTask that will run the given executable. More...
 
void setArgs (QStringList args)
 Sets the command line arguments for the executable. More...
 
void setUnbufferedOutput (bool unbufferedOutput)
 Specifies whether the command's output will be unbuffered. More...
 
virtual void processStandardOutput (QString text)
 Called to process standard output from the process. More...
 
virtual void processStandardError (QString text)
 Called to process standard error from the process. More...
 
virtual void finish ()
 Called when the process has exited and just before the finished() signal is emitted. More...
 
void setCancelled ()
 Marks the task as cancelled. More...
 
void fail (QString error=QString())
 Marks the task as failed, with an optional error message. More...
 
void updateStatus (const QString &text)
 Updates the status of the task. More...
 

Detailed Description

An abstract subclass of Task that runs an external command (a subprocess).

Subclasses must provide a suitable constructor and may optionally override processStandardOutput(), processStandardError(), and finish().

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~ExternalCommandTask()

virtual ~ExternalCommandTask ( )
virtual

Destructor.

◆ ExternalCommandTask()

ExternalCommandTask ( const QString &  executable)
protected

Constructs a new ExternalCommandTask that will run the given executable.

Member Function Documentation

◆ args()

QStringList args ( ) const
inline

Returns the arguments to the executable.

◆ cancel()

virtual bool cancel ( )
virtual

Specified by Task.

Reimplemented from Task.

◆ cancelled

void cancelled ( )
signalinherited

Emitted when the task has been cancelled.

◆ error()

QString error ( ) const
inlineinherited

Returns the error message reported by this task upon failure, if any.

◆ executable()

QString executable ( ) const
inline

Returns the path to the executable that will be run.

◆ execute()

virtual void execute ( )
virtual

Specified by Task.

Implements Task.

◆ executionTime()

qint64 executionTime ( ) const
inherited

Returns the amount of time the task spent executing, or 0 if the task has not finished executing.

◆ exitCode()

int exitCode ( ) const
inline

Returns the exit code from the subprocess.

◆ fail()

void fail ( QString  error = QString())
protectedinherited

Marks the task as failed, with an optional error message.

◆ finish()

virtual void finish ( )
protectedvirtual

Called when the process has exited and just before the finished() signal is emitted.

May be overridden to perform any necessary cleanup tasks. The default implementation is a no-op.

◆ finished

void finished ( )
signalinherited

Emitted when the task has finished executing.

◆ id()

int id ( ) const
inlineinherited

Returns the unique ID that was assigned to this task.

◆ isBackground()

bool isBackground ( ) const
inlineinherited

Tests if the task is a background task.

◆ isCancelled()

bool isCancelled ( ) const
inlineinherited

Tests if the task has been cancelled.

◆ isCancelling()

bool isCancelling ( ) const
inlineinherited

Tests if the task is currently cancelling.

◆ isFailed()

bool isFailed ( ) const
inlineinherited

Tests if the task has failed.

◆ isRunning()

bool isRunning ( ) const
inlineinherited

Tests if the task is currently executing.

◆ processStandardError()

virtual void processStandardError ( QString  text)
protectedvirtual

Called to process standard error from the process.

The default implementation is a no-op.

◆ processStandardOutput()

virtual void processStandardOutput ( QString  text)
protectedvirtual

Called to process standard output from the process.

The default implementation is a no-op.

◆ setArgs()

void setArgs ( QStringList  args)
protected

Sets the command line arguments for the executable.

◆ setCancelled()

void setCancelled ( )
protectedinherited

Marks the task as cancelled.

◆ setTimeout()

void setTimeout ( int  seconds)
inherited

Sets the task's timeout, in seconds.

◆ setUnbufferedOutput()

void setUnbufferedOutput ( bool  unbufferedOutput)
inlineprotected

Specifies whether the command's output will be unbuffered.

If the output is unbuffered, it will be passed to the processStandardOutput() and processStandardError() methods as it arrives; otherwise, it will be buffered internally and passed to these methods when the subprocess has finished executing. By default, output is buffered.

◆ statusUpdated

void statusUpdated ( const QString &  status)
signalinherited

Emitted whenever updateStatus() is called.

◆ toString()

QString toString ( ) const

Returns a string representation of the task.

◆ updateStatus()

void updateStatus ( const QString &  text)
protectedinherited

Updates the status of the task.

See statusUpdated().

Member Data Documentation

◆ DEFAULT_TIMEOUT

const int DEFAULT_TIMEOUT
staticinherited

The default timeout interval, in seconds.


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