Quark  0.1
Task Class Referenceabstract

An abstract base class for objects that represent tasks to be executed by a TaskProcessor. More...

#include <Task.h++>

Inheritance diagram for Task:

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 ~Task ()
 Destructor. 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

 Task (bool background=false)
 Constructs a new Task of the given type. More...
 
virtual void execute ()=0
 Executes the task. More...
 
virtual bool cancel ()
 Attempts to cancel the task. 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...
 

Friends

class TaskProcessor
 

Detailed Description

An abstract base class for objects that represent tasks to be executed by a TaskProcessor.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~Task()

virtual ~Task ( )
virtual

Destructor.

◆ Task()

Task ( bool  background = false)
protected

Constructs a new Task of the given type.

Parameters
backgroundWhether this is a "background" task that continues executing indefinitely.

Member Function Documentation

◆ cancel()

virtual bool cancel ( )
protectedvirtual

Attempts to cancel the task.

Some tasks may not be cancellable. The default implementation is a no-op that returns false.

Parameters
<b>true</b>if the task was successfully cancelled, false otherwise.

Reimplemented in ExternalCommandTask.

◆ cancelled

void cancelled ( )
signal

Emitted when the task has been cancelled.

◆ error()

QString error ( ) const
inline

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

◆ execute()

virtual void execute ( )
protectedpure virtual

Executes the task.

The actual work of the task must be implemented in this method.

Implemented in ExternalCommandTask.

◆ executionTime()

qint64 executionTime ( ) const

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

◆ fail()

void fail ( QString  error = QString())
protected

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

◆ finished

void finished ( )
signal

Emitted when the task has finished executing.

◆ id()

int id ( ) const
inline

Returns the unique ID that was assigned to this task.

◆ isBackground()

bool isBackground ( ) const
inline

Tests if the task is a background task.

◆ isCancelled()

bool isCancelled ( ) const
inline

Tests if the task has been cancelled.

◆ isCancelling()

bool isCancelling ( ) const
inline

Tests if the task is currently cancelling.

◆ isFailed()

bool isFailed ( ) const
inline

Tests if the task has failed.

◆ isRunning()

bool isRunning ( ) const
inline

Tests if the task is currently executing.

◆ setCancelled()

void setCancelled ( )
protected

Marks the task as cancelled.

◆ setTimeout()

void setTimeout ( int  seconds)

Sets the task's timeout, in seconds.

◆ statusUpdated

void statusUpdated ( const QString &  status)
signal

Emitted whenever updateStatus() is called.

◆ updateStatus()

void updateStatus ( const QString &  text)
protected

Updates the status of the task.

See statusUpdated().

Friends And Related Function Documentation

◆ TaskProcessor

friend class TaskProcessor
friend

Member Data Documentation

◆ DEFAULT_TIMEOUT

const int DEFAULT_TIMEOUT
static

The default timeout interval, in seconds.


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