1 | // This file is part of the PACPUS framework distributed under the
|
---|
2 | // CECILL-C License, Version 1.0.
|
---|
3 | //
|
---|
4 | /// @file
|
---|
5 | /// @author Samuel Gosselin <firstname.surname@utc.fr>
|
---|
6 | /// @date December, 2012
|
---|
7 | /// @version $Id: PeriodicWorker.h 66 2013-01-09 16:54:11Z kurdejma $
|
---|
8 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
9 | /// @brief Periodic worker base class
|
---|
10 | ///
|
---|
11 | /// Detailed description.
|
---|
12 |
|
---|
13 | #ifndef DEF_PACPUS_PERIODIC_WORKER_H
|
---|
14 | #define DEF_PACPUS_PERIODIC_WORKER_H
|
---|
15 |
|
---|
16 | // Includes, pacpus.
|
---|
17 | #include <Pacpus/PacpusTools/AsyncWorkerBase.h>
|
---|
18 |
|
---|
19 | class QTimer;
|
---|
20 |
|
---|
21 | namespace pacpus
|
---|
22 | {
|
---|
23 | /** PeriodicWorker
|
---|
24 | * @brief A simple base class for periodic worker.
|
---|
25 | *
|
---|
26 | * @example
|
---|
27 | * class MyWorker
|
---|
28 | * : public PeriodicWorkder
|
---|
29 | * {
|
---|
30 | * public:
|
---|
31 | * void doWork() { std::cout << "Hey, I'm working!" << std::endl; }
|
---|
32 | * };
|
---|
33 | *
|
---|
34 | * // Do its work every second.
|
---|
35 | * MyWorker worker;
|
---|
36 | * worker.startWork(1000);
|
---|
37 | */
|
---|
38 | class PeriodicWorker
|
---|
39 | : public AsyncWorkerBase
|
---|
40 | {
|
---|
41 | Q_OBJECT
|
---|
42 | public:
|
---|
43 | /// Ctor of PeriodicWorker.
|
---|
44 | PeriodicWorker();
|
---|
45 |
|
---|
46 | /// Dtor of PeriodicWorker.
|
---|
47 | virtual ~PeriodicWorker();
|
---|
48 |
|
---|
49 | /** Start the periodic worker.
|
---|
50 | * @param msec Period in mseconds.
|
---|
51 | */
|
---|
52 | void startWork(int msec);
|
---|
53 |
|
---|
54 | /** Stop the periodic worker, but do not delete it. */
|
---|
55 | void stopWork();
|
---|
56 |
|
---|
57 | public slots:
|
---|
58 | /** Do the work.
|
---|
59 | * This method need to be implemented in the subclasses, it will be called
|
---|
60 | * each time the timer has reached its period.
|
---|
61 | */
|
---|
62 | virtual void doWork() = 0;
|
---|
63 |
|
---|
64 | private:
|
---|
65 | QTimer* mHeartbeat;
|
---|
66 | };
|
---|
67 | }
|
---|
68 |
|
---|
69 | #endif // DEF_PACPUS_PERIODIC_WORKER_H
|
---|