![]() |
University of Murcia, Spain ![]() |
QVWorker Class ReferenceBase class for Worker threads.
More...
|
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 (const 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 () |
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.
Different states in which a worker object can be.
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.
QVWorker::QVWorker | ( | const QString | name = QString() |
) |
Constructor for QVWorker class.
Inits worker, and set it's status to Running.
name | the (optional) name given to the worker. |
Definition at line 35 of file qvworker.cpp.
QVWorker::QVWorker | ( | const QVWorker & | other | ) |
Copy Constructor for QVWorker class.
Creates a new worker form a given worker.
other | the given worker. |
Definition at line 66 of file qvworker.cpp.
QVWorker::~QVWorker | ( | ) |
Destructor for QVWorker class.
Definition at line 73 of file qvworker.cpp.
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, QVConvert_uCharsFloatC1Worker, QVConvert_uCharsFloatC3Worker, QVConvert_sFloatuCharC1Worker, QVConvert_sFloatuCharC3Worker, QVAdd_uCharC1Worker, QVAdd_uCharC3Worker, QVAdd_sFloatC1Worker, QVAdd_sFloatC3Worker, QVAddC_uCharC1Worker, QVAddC_sFloatC1Worker, QVMul_uCharC1Worker, QVMul_uCharC3Worker, QVMul_sFloatC3Worker, QVMul_sFloatC1Worker, QVMulC_uCharC1Worker, QVMulC_sFloatC1Worker, QVMulScale_uCharC1Worker, QVMulScale_uCharC3Worker, QVSub_uCharC1Worker, QVSub_uCharC3Worker, QVSub_sFloatC1Worker, QVSub_sFloatC3Worker, QVSubC_uCharC1Worker, QVSubC_sFloatC1Worker, QVDiv_uCharC1Worker, QVDiv_uCharC3Worker, QVDiv_sFloatC3Worker, QVDiv_sFloatC1Worker, QVDivC_uCharC1Worker, QVDivC_sFloatC1Worker, QVAbs_sShortC1Worker, QVAbs_sFloatC1Worker, QVAbsDiff_uCharC1Worker, QVAbsDiff_sFloatC1Worker, QVSqr_sFloatC1Worker, QVLn_sFloatC1Worker, QVLn_sFloatC3Worker, QVAndC_uCharC1Worker, QVNot_uCharC1Worker, QVNot_uCharC3Worker, QVOrC_uCharC1Worker, QVXorC_uCharC1Worker, QVLShiftC_uCharC1Worker, QVRShiftC_uCharC1Worker, QVRGBToGray_uCharC3C1Worker, QVRGBToGray_sFloatC3C1Worker, QVThreshold_uCharC1Worker, QVThreshold_sFloatC1Worker, QVComputeThreshold_Otsu_uCharC1Worker, QVCompare_uCharC1Worker, QVCompare_sFloatC1Worker, QVCompareC_uCharC1Worker, QVCompareC_sFloatC1Worker, QVFilterBox_uCharC1Worker, QVFilterBox_uCharC3Worker, QVFilterBox_sFloatC1Worker, QVFilterMin_uCharC1Worker, QVFilterMin_uCharC3Worker, QVFilterMin_sFloatC1Worker, QVFilterMax_uCharC1Worker, QVFilterMax_uCharC3Worker, QVFilterMax_sFloatC1Worker, QVFilterMedian_uCharC1Worker, QVFilterMedian_uCharC3Worker, QVFilterMedianHoriz_uCharC1Worker, QVFilterSobelHorizMask_sFloatC1Worker, QVFilterSobelVertMask_sFloatC1Worker, QVFilterLaplace_uCharC1Worker, QVFilterLaplace_sFloatC1Worker, QVFilterGauss_uCharC1Worker, QVFilterGauss_sFloatC1Worker, QVFilterGauss_uCharC3Worker, QVFilterGauss_sFloatC3Worker, QVFilterHipass_uCharC1Worker, QVFilterHipass_uCharC3Worker, QVFilterHipass_sFloatC1Worker, QVFilterHipass_sFloatC3Worker, QVFilterLowpass_uCharC1Worker, QVFilterLowpass_sFloatC1Worker, QVSum_uCharC1Worker, QVMean_uCharC1Worker, QVMin_uCharC1Worker, QVMin_sFloatC1Worker, QVMax_uCharC1Worker, QVMax_sFloatC1Worker, ContourExtractorWorker, ComponentTreeWorker, CannyWorker, ContourPainter, and UserInteract.
Definition at line 91 of file qvworker.h.
Referenced by workerIterate().
virtual void QVWorker::worker | ( | ) | [inline, virtual] |
Definition at line 96 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 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.
Definition at line 113 of file qvworker.h.
bool QVWorker::isPaused | ( | ) | const [inline] |
Function that can be used to check paused status of worker.
Definition at line 117 of file qvworker.h.
bool QVWorker::isStoped | ( | ) | const [inline] |
Function that can be used to check stopped status of worker.
Definition at line 121 of file qvworker.h.
bool QVWorker::isRunning | ( | ) | const [inline] |
Function that can be used to check running status of worker.
Definition at line 125 of file qvworker.h.
TWorkerStatus QVWorker::getStatus | ( | ) | const [inline] |
Function to obtain the 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.
Definition at line 138 of file qvworker.h.
Referenced by UserInteract::processTrigger(), and workerIterate().
bool QVWorker::isStatsEnabled | ( | ) | const [inline] |
Function to obtain 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.
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.
freq | The frequency (iterations) whitch prints the stats. |
Definition at line 166 of file qvworker.h.
Referenced by QVWorker().
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 183 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.
Definition at line 207 of file qvworker.h.
Referenced by QVYUV4MPEG2Recorder::QVYUV4MPEG2Recorder(), and UserInteract::UserInteract().
const QStringList QVWorker::getTriggerList | ( | ) | const [inline] |
Returns the list of triggers (as a QStringList) for the worker.
Definition at line 210 of file qvworker.h.
virtual void QVWorker::processTrigger | ( | const 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.
name | the name of the trigger that was activated. |
Reimplemented in QVYUV4MPEG2Recorder, and UserInteract.
Definition at line 247 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 289 of file qvworker.h.
Referenced by ContourPainter::iterate(), CannyWorker::iterate(), ComponentTreeWorker::iterate(), ContourExtractorWorker::iterate(), and workerIterate().