QVWorker Class Reference
[Core classes]

Base class for Worker threads. More...

#include <qvcore/qvworker.h>

Inherits QVPropertyContainer.

List of all members.

Public Types

enum  TWorkerStatus { Running, RunningOneStep, Paused, Finished }

Public Slots

void pause ()
 Set worker status to Paused.
void unPause ()
 Set worker status to Running.
void step ()
 Set worker status to RunningOneStep.
void finish ()
 Finish worker execution.
virtual void processTrigger (QString name)
 Process trigger activations in the worker.

Signals

void startIteration ()
 Signal emited before each call to iterate() function.
void endIteration ()
 Signal emited after each call to iterate() function.
void endIteration (uint id, int iteration)
 Signal emited after each call to iterate() function.
void statusUpdate (QVWorker::TWorkerStatus)
 Signal emited when worker changes its status.

Public Member Functions

 QVWorker (const QString name=QString())
 Constructor for QVWorker class.
virtual void iterate ()
 Function to be defined in subclasses with processing code.
virtual void worker ()
void setMinimumDelay (int ms)
 Sets a minimum ms delay for each iteration (default is 0).
bool isFinished () const
 Function that can be used to check finish status of worker.
bool isPaused () const
 Function that can be used to check paused status of worker.
bool isRunning () const
 Function that can be used to check running status of worker.
TWorkerStatus getStatus () const
 Function to obtain the status of the worker.
void unlink ()
 Completely unlinks a property holder.
int getIteration () const
 Function to obtain the number of iteration the worker has performed.
QVStat getCpuStat () const
 Gets CpuStat object for the worker.
void printStat (int freq)
 Prints CpuStat object for the worker.
void addTrigger (QString name)
 Adds a trigger to the worker.
const QStringList getTriggerList () const

Protected Member Functions

void run ()
void timeFlag (const QString flag)
 Stablish a performance breakpoint in the execution of the worker.


Detailed Description

Base class for Worker threads.

This class can be used to construct worker threads for the Worker Design Pattern. Worker threads classes should inherit from QVWorker, and implement abstract function iterate, with the body of the function code

For a detailed usage of this class in a QVision application, see section ProgrammingModel.

Definition at line 45 of file qvworker.h.


Member Enumeration Documentation

enum QVWorker::TWorkerStatus

Different states in which a worker object can be.

Enumerator:
Running  Worker is running. iterate() function will be called continuously, until slots pause() or finish() are called.
RunningOneStep  Worker will execute iterate() function once, and then will change to Paused status.
Paused  Worker is paused. It won't call function iterate(), or finish execution thread, until slots unPause() or finish() are called respectively.
Finished  Worker is finished. Execution thread ended.

Definition at line 51 of file qvworker.h.


Constructor & Destructor Documentation

QVWorker::QVWorker ( const QString  name = QString()  ) 

Constructor for QVWorker class.

Inits worker, and set it's status to Running.

Parameters:
name the (optional) name given to the worker.

Definition at line 34 of file qvworker.cpp.


Member Function Documentation

virtual void QVWorker::iterate (  )  [inline, virtual]

Function to be defined in subclasses with processing code.

This function should contain the code to process data, that will be executed continuously until worker is finished.

Definition at line 78 of file qvworker.h.

Referenced by run().

virtual void QVWorker::worker (  )  [inline, virtual]

Deprecated:
Code to process inputs should be defined in function iterate() instead.
See also:
iterate()

Definition at line 83 of file qvworker.h.

Referenced by iterate().

void QVWorker::setMinimumDelay ( int  ms  )  [inline]

Sets a minimum ms delay for each iteration (default is 0).

This function should be called to stablish a minimum delay for each iteration (that is, it should be used to limit the speed at which the worker iterates). Of course, if the real processing iteration time is longer than the delay set with this function, it will not have any visible effect.

Warning: due to underlying operating system time management imprecissions, low values (typically under 40 ms) of this parameter can result in longer delays than expected.

Definition at line 96 of file qvworker.h.

bool QVWorker::isFinished (  )  const [inline]

Function that can be used to check finish status of worker.

Returns:
true if worker is finished.

Definition at line 100 of file qvworker.h.

bool QVWorker::isPaused (  )  const [inline]

Function that can be used to check paused status of worker.

Returns:
true if worker is paused.

Definition at line 104 of file qvworker.h.

bool QVWorker::isRunning (  )  const [inline]

Function that can be used to check running status of worker.

Returns:
true if worker is running.

Definition at line 108 of file qvworker.h.

TWorkerStatus QVWorker::getStatus (  )  const [inline]

Function to obtain the status of the worker.

Returns:
status of the worker.

Definition at line 112 of file qvworker.h.

void QVWorker::unlink (  ) 

Completely unlinks a property holder.

A worker only can be unlinked if the worker's status is Finished.

Reimplemented from QVPropertyContainer.

Definition at line 52 of file qvworker.cpp.

Referenced by run().

int QVWorker::getIteration (  )  const [inline]

Function to obtain the number of iteration the worker has performed.

Returns:
number of times that the iterate() function has been called.

Definition at line 121 of file qvworker.h.

Referenced by run().

QVStat QVWorker::getCpuStat (  )  const [inline]

Gets CpuStat object for the worker.

Every worker has a CpuStat type object that mantains cpu time performance for different parts (code fragments) of function iterate(). This object is updated in method timeFlag(), when stablishing a performance breakpoint in the execution of the worker.

Returns:
constant reference to worker's CpuStat object.

Definition at line 131 of file qvworker.h.

void QVWorker::printStat ( int  freq  )  [inline]

Prints CpuStat object for the worker.

Prints CpuStat means for the worker.

Parameters:
freq The frequency (iterations) whitch prints the stats.

Definition at line 138 of file qvworker.h.

void QVWorker::addTrigger ( QString  name  )  [inline]

Adds a trigger to the worker.

Triggers are just named actions that can be called upon a QVWorker to change it's state, initialize itself, or whatever action the programmer considers convenient, in a completely asynchronous manner. When added to a worker, they will depict a button in the corresponding property widget in the interface, that will do a call to processTrigger() function when pressed.

This method is provided just for convenience. The same effect could be achieved just by adding a new slot when subclassing QVWorker, and connecting it to a button clicked signal. But using this generic function avoids the programmer to have to declare the new worker class as a Q_OBJECT, if he just needs the trigger functionality, and does not want to declare any other signals or slots in his new worker class.

See also:
processTrigger()

Definition at line 158 of file qvworker.h.

const QStringList QVWorker::getTriggerList (  )  const [inline]

Returns the list of triggers (as a QStringList) for the worker.

Definition at line 161 of file qvworker.h.

virtual void QVWorker::processTrigger ( QString  name  )  [inline, virtual, slot]

Process trigger activations in the worker.

Triggers are just named actions that can be called upon a QVWorker to change it's state, initialize itself, or whatever action the programmer considers convenient, in a completely asynchronous manner.

When added to a worker, they will depict a button in the corresponding property widget in the interface, that will do a call to processTrigger() function when pressed. Use addTrigger to add triggers to a worker, and redefine this function to capture their activations.

See also:
addTrigger()
Parameters:
name the name of the trigger that was activated.

Definition at line 194 of file qvworker.h.

void QVWorker::timeFlag ( const QString  flag  )  [inline, protected]

Stablish a performance breakpoint in the execution of the worker.

This function should be used in the body of iterate() function, to stablish a performance breakpoint, at which the execution time will be statistically measured.

These statistics can be plotted through the graphical user interface (see Worker widgets. section at the QVGUI documentation), creating a QVCpuPlot object, or to the user console if the parameter --"print stats"=true was used in the application command line.

Definition at line 234 of file qvworker.h.

Referenced by run().


The documentation for this class was generated from the following files:
Generated on Thu Jul 17 17:23:30 2008 for QVision by  doxygen 1.5.3