source: pacpusframework/trunk/include/Pacpus/PacpusTools/PeriodicWorker.h@ 18

Last change on this file since 18 was 10, checked in by sgosseli, 12 years ago

Add PeriodWorker and provide an example in the documentation.

File size: 1.2 KB
Line 
1#ifndef DEF_PERIODIC_WORKER_H
2#define DEF_PERIODIC_WORKER_H
3
4// Includes, pacpus.
5#include <PacpusTools/AsyncWorkerBase.h>
6
7class QTimer;
8
9namespace pacpus
10{
11 /** PeriodicWorker
12 * @brief A simple base class for periodic worker.
13 *
14 * @example
15 * class MyWorker
16 * : public PeriodicWorkder
17 * {
18 * public:
19 * void doWork() { std::cout << "Hey, I'm working!" << std::endl; }
20 * };
21 *
22 * // Do its work every second.
23 * MyWorker worker;
24 * worker.startWork(1000);
25 */
26 class PeriodicWorker
27 : public AsyncWorkerBase
28 {
29 Q_OBJECT
30 public:
31 /// Ctor of PeriodicWorker.
32 PeriodicWorker();
33
34 /// Dtor of PeriodicWorker.
35 virtual ~PeriodicWorker();
36
37 /** Start the periodic worker.
38 * @param msec Period in mseconds.
39 */
40 void startWork(int msec);
41
42 /** Stop the periodic worker, but do not delete it. */
43 void stopWork();
44
45 public slots:
46 /** Do the work.
47 * This method need to be implemented in the subclasses, it will be called
48 * each time the timer has reached its period.
49 */
50 virtual void doWork() = 0;
51
52 private:
53 QTimer* mHeartbeat;
54 };
55}
56
57#endif
Note: See TracBrowser for help on using the repository browser.