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

Last change on this file since 73 was 73, checked in by Marek Kurdej, 11 years ago

Minor: line-endings.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
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 73 2013-01-10 16:56:42Z 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
19class QTimer;
20
21namespace 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
Note: See TracBrowser for help on using the repository browser.