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