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

Last change on this file since 103 was 103, checked in by DHERBOMEZ Gérald, 11 years ago

Correction of link bugs.
Windows build OK.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
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 103 2013-06-05 15:39:28Z gdherbom $
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
22class QTimer;
23
24namespace pacpus
25{
26 /** PeriodicWorker
27 * @brief A simple base class for periodic worker.
28 *
29 * @example
30 * class MyWorker
31 * : public PeriodicWorkder
32 * {
33 * public:
34 * void doWork() { std::cout << "Hey, I'm working!" << std::endl; }
35 * };
36 *
37 * // Do its work every second.
38 * MyWorker worker;
39 * worker.startWork(1000);
40 */
41 class PACPUSTOOLS_API PeriodicWorker
42 : public AsyncWorkerBase
43 {
44 Q_OBJECT
45 public:
46 /// Ctor of PeriodicWorker.
47 PeriodicWorker();
48
49 /// Dtor of PeriodicWorker.
50 virtual ~PeriodicWorker();
51
52 /** Start the periodic worker.
53 * @param msec Period in mseconds.
54 */
55 void startWork(int msec);
56
57 /** Stop the periodic worker, but do not delete it. */
58 void stopWork();
59
60 public 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 */
65 virtual void doWork() = 0;
66
67 private:
68 QTimer* mHeartbeat;
69 };
70}
71
72#endif // DEF_PACPUS_PERIODIC_WORKER_H
Note: See TracBrowser for help on using the repository browser.