PARP Research Group University of Murcia, Spain


QVWorker Class Reference
[Core classes]

Base class for Worker threads. More...

#include <qvcore/qvworker.h>

Inherits QVPropertyContainer.

Inherited by CannyWorker, ComponentTreeWorker, ContourExtractorWorker, ContourPainter, MyWorker, MyWorker, PlayerWorker, PlayerWorker, QVCameraWorker, QVCannyEdgeDetector, QVFilterSelectorWorker< T, C >, QVGraphsWorker, QVHarrisPointDetector, QVHessianPointDetector, QVImageMeans< T, C >, QVImageResizerWorker< T, C >, QVImageRetarderWorker< T, C >, QVIPPAbsDiffWorker< TYPE, C >, QVIPPAddCWorker< TYPE, C >, QVIPPAddRandUniform_DirectWorker< TYPE, C >, QVIPPAddWorker< TYPE, C >, QVIPPCompareCWorker< TYPE, C >, QVIPPComputeThreshold_OtsuWorker< TYPE, C >, QVIPPCopyC3P3Worker< TYPE >, QVIPPCopyP3C3Worker< TYPE >, QVIPPDilate3x3Worker< TYPE, C >, QVIPPErode3x3Worker< TYPE, C >, QVIPPFilterBoxWorker< TYPE, C >, QVIPPFilterGaussWorker< TYPE, C >, QVIPPFilterHipassWorker< TYPE, C >, QVIPPFilterMaxWorker< TYPE, C >, QVIPPFilterMedianWorker< TYPE, C >, QVIPPFilterMinWorker< TYPE, C >, QVMSERDetector, QVPlanarRectifierWorker, QVPointWorker, QVSynchronizer, and QVYUV4MPEG2Recorder.

List of all members.

Public Types

enum  TWorkerStatus {
  Running, RunningOneStep, Paused, Stoped,
  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 stop ()
 Finish worker execution.
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 (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.
 QVWorker (const QVWorker &other)
 Copy Constructor for QVWorker class.
 ~QVWorker ()
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 isStoped () const
 Function that can be used to check stopped 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.
int getIteration () const
 Function to obtain the number of iteration the worker has performed.
bool isStatsEnabled () const
 Function to obtain if the stats are enabled.
QVStat getCpuStat () const
 Gets CpuStat object for the worker.
void setPrintStatsFrequency (int freq)
 Prints CpuStat object for the worker.
void printStats ()
 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.
void workerIterate ()


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

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.
Stoped  Worker is stoped. It won't call function iterate() (but don't block its conected sychronous workers), or finish execution thread, until slots 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.

QVWorker::QVWorker ( const QVWorker other  ) 

Copy Constructor for QVWorker class.

Creates a new worker form a given worker.

Parameters:
other the given worker.

Definition at line 59 of file qvworker.cpp.

QVWorker::~QVWorker (  ) 

Destructor for QVWorker class.

Definition at line 66 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.

Reimplemented in QVYUV4MPEG2Recorder, QVIPPCopyP3C3Worker< TYPE >, QVIPPCopyC3P3Worker< TYPE >, QVIPPDilate3x3Worker< TYPE, C >, QVIPPErode3x3Worker< TYPE, C >, QVIPPComputeThreshold_OtsuWorker< TYPE, C >, QVIPPAddRandUniform_DirectWorker< TYPE, C >, QVIPPFilterBoxWorker< TYPE, C >, QVIPPFilterMedianWorker< TYPE, C >, QVIPPFilterMaxWorker< TYPE, C >, QVIPPFilterMinWorker< TYPE, C >, QVIPPFilterGaussWorker< TYPE, C >, QVIPPFilterHipassWorker< TYPE, C >, QVIPPAddWorker< TYPE, C >, QVIPPAbsDiffWorker< TYPE, C >, QVIPPAddCWorker< TYPE, C >, QVIPPCompareCWorker< TYPE, C >, QVCannyEdgeDetector, QVFilterSelectorWorker< T, C >, QVGraphsWorker, QVHarrisPointDetector, QVHessianPointDetector, QVImageMeans< T, C >, QVImageResizerWorker< T, C >, QVImageRetarderWorker< T, C >, QVMSERDetector, QVPlanarRectifierWorker, QVPointWorker, QVSynchronizer, MyWorker, ContourExtractorWorker, PlayerWorker, MyWorker, ComponentTreeWorker, CannyWorker, ContourPainter, PlayerWorker, QVIPPCopyP3C3Worker< TYPE >, QVIPPCopyC3P3Worker< TYPE >, QVIPPDilate3x3Worker< TYPE, C >, QVIPPErode3x3Worker< TYPE, C >, QVIPPComputeThreshold_OtsuWorker< TYPE, C >, QVIPPAddRandUniform_DirectWorker< TYPE, C >, QVIPPFilterBoxWorker< TYPE, C >, QVIPPFilterBoxWorker< TYPE, C >, QVIPPFilterMedianWorker< TYPE, C >, QVIPPFilterMedianWorker< TYPE, C >, QVIPPFilterMaxWorker< TYPE, C >, QVIPPFilterMaxWorker< TYPE, C >, QVIPPFilterMinWorker< TYPE, C >, QVIPPFilterMinWorker< TYPE, C >, QVIPPFilterGaussWorker< TYPE, C >, QVIPPFilterHipassWorker< TYPE, C >, QVIPPFilterGaussWorker< TYPE, C >, QVIPPFilterHipassWorker< TYPE, C >, QVIPPAddWorker< TYPE, C >, QVIPPAddWorker< TYPE, C >, QVIPPAddCWorker< TYPE, C >, QVIPPAddCWorker< TYPE, C >, QVIPPAbsDiffWorker< TYPE, C >, and QVIPPCompareCWorker< TYPE, C >.

Definition at line 91 of file qvworker.h.

Referenced by workerIterate().

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

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

Definition at line 96 of file qvworker.h.

Referenced by iterate(), and run().

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 109 of file qvworker.h.

Referenced by QVYUV4MPEG2Recorder::QVYUV4MPEG2Recorder().

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 113 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 117 of file qvworker.h.

bool QVWorker::isStoped (  )  const [inline]

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

Returns:
true if worker is stoped.

Definition at line 121 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 125 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 129 of file qvworker.h.

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 138 of file qvworker.h.

Referenced by workerIterate().

bool QVWorker::isStatsEnabled (  )  const [inline]

Function to obtain if the stats are enabled.

Returns:
if the stats are enabled.

Definition at line 142 of file qvworker.h.

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.

If th stats are disabled, return an empty QVStat.

Returns:
constant reference to worker's CpuStat object.

Definition at line 154 of file qvworker.h.

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

Prints CpuStat object for the worker.

Periodically prints performance statistics for the worker. If the stats are disabled, do nothing.

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

Definition at line 166 of file qvworker.h.

void QVWorker::printStats (  )  [inline]

Prints CpuStat object for the worker.

Prints performance statistics for the worker. If the stats are disabled, do nothing.

Definition at line 179 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 203 of file qvworker.h.

Referenced by QVCameraWorker::QVCameraWorker(), and QVYUV4MPEG2Recorder::QVYUV4MPEG2Recorder().

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

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

Definition at line 206 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.

Reimplemented in QVYUV4MPEG2Recorder.

Definition at line 243 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.

If the stats are disabled, do nothing.

These statistics can be plotted through the graphical user interface (see WorkerWidget 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 282 of file qvworker.h.

Referenced by QVPlanarRectifierWorker::iterate(), QVHessianPointDetector::iterate(), QVFilterSelectorWorker< T, C >::iterate(), ContourPainter::iterate(), CannyWorker::iterate(), ComponentTreeWorker::iterate(), ContourExtractorWorker::iterate(), and workerIterate().


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



QVision framework. PARP research group, copyright 2007, 2008.