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