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

Last change on this file since 31 was 31, checked in by sgosseli, 11 years ago

Huge commit: use the new includes style in all the files, add the license header in all the headers, and in some cpp.

File size: 1.5 KB
Line 
1/**
2 *
3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
5 *
6 * See the LICENSE file for more information or a copy at:
7 * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
8 *
9 */
10
11#ifndef DEF_PACPUS_PERIODIC_WORKER_H
12#define DEF_PACPUS_PERIODIC_WORKER_H
13
14// Includes, pacpus.
15#include <PacpusTools/AsyncWorkerBase.h>
16
17class QTimer;
18
19namespace pacpus
20{
21 /** PeriodicWorker
22 * @brief A simple base class for periodic worker.
23 *
24 * @example
25 * class MyWorker
26 * : public PeriodicWorkder
27 * {
28 * public:
29 * void doWork() { std::cout << "Hey, I'm working!" << std::endl; }
30 * };
31 *
32 * // Do its work every second.
33 * MyWorker worker;
34 * worker.startWork(1000);
35 */
36 class PeriodicWorker
37 : public AsyncWorkerBase
38 {
39 Q_OBJECT
40 public:
41 /// Ctor of PeriodicWorker.
42 PeriodicWorker();
43
44 /// Dtor of PeriodicWorker.
45 virtual ~PeriodicWorker();
46
47 /** Start the periodic worker.
48 * @param msec Period in mseconds.
49 */
50 void startWork(int msec);
51
52 /** Stop the periodic worker, but do not delete it. */
53 void stopWork();
54
55 public slots:
56 /** Do the work.
57 * This method need to be implemented in the subclasses, it will be called
58 * each time the timer has reached its period.
59 */
60 virtual void doWork() = 0;
61
62 private:
63 QTimer* mHeartbeat;
64 };
65}
66
67#endif // DEF_PACPUS_PERIODIC_WORKER_H
Note: See TracBrowser for help on using the repository browser.