#include <qvcore/qvworker.h>
Inherits QVPropertyContainer.
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 | 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. | |
int | getIteration () const |
Function to obtain the number of iteration the worker has performed. | |
CpuStat & | getCpuStat () |
Gets CpuStat object for the worker. | |
void | addTrigger (QString name) |
Adds a trigger to the worker. | |
const QStringList | getTriggerList () |
Protected Member Functions | |
void | run () |
void | timeFlag (const QString flag) |
Stablish a performance breakpoint in the execution of the worker. |
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 QVision's basic programming model..
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. |
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 32 of file qvworker.cpp.
References QVPropertyContainer::inputFlag, and qvApp.
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.
References worker().
Referenced by run().
virtual void QVWorker::worker | ( | ) | [inline, virtual] |
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.
Definition at line 100 of file qvworker.h.
References Finished.
bool QVWorker::isPaused | ( | ) | const [inline] |
Function that can be used to check paused status of worker.
Definition at line 104 of file qvworker.h.
References Paused.
bool QVWorker::isRunning | ( | ) | const [inline] |
Function that can be used to check running status of worker.
Definition at line 108 of file qvworker.h.
References Running.
TWorkerStatus QVWorker::getStatus | ( | ) | const [inline] |
Function to obtain the status of the worker.
Definition at line 112 of file qvworker.h.
int QVWorker::getIteration | ( | ) | const [inline] |
Function to obtain the number of iteration the worker has performed.
Definition at line 116 of file qvworker.h.
CpuStat& QVWorker::getCpuStat | ( | ) | [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.
Definition at line 126 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 146 of file qvworker.h.
const QStringList QVWorker::getTriggerList | ( | ) | [inline] |
Returns the list of triggers (as a QStringList) for the worker.
Definition at line 149 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.
name | the name of the trigger that was activated. |
Definition at line 182 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 performance breakpoints, in which execution time will be statistically measured.
These statistics are the ones used in the user interface CPU plot graphic, amongst others, in the QVision.
Definition at line 217 of file qvworker.h.
Referenced by run().