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

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

Modified property: added svn:keywords=Id.

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