source: pacpusframework/branches/0.2.x/include/Pacpus/PacpusTools/PeriodicWorker.h

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

Update: merged changes from trunk.

  • Property svn:executable set to *
File size: 1.9 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 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#include <Pacpus/PacpusTools/AsyncWorkerBase.h>
18#include <Pacpus/PacpusTools/PacpusToolsConfig.h>
19
20class QTimer;
21
22namespace pacpus
23{
24
25/// @brief A simple base class for periodic worker.
26///
27/// @example
28/// To use the PeriodicWorker, simply inherit from this class when creating your worker.
29/// ~~~
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/// ~~~
41class 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 void startWork(int msec);
55
56 /// Stop the periodic worker, but do not delete it.
57 void stopWork();
58
59 public Q_SLOTS:
60 /// Do the work.
61 /// This method need to be implemented in the subclasses, it will be called
62 /// each time the timer has reached its period.
63 virtual void doWork() = 0;
64
65 private:
66 QTimer* mHeartbeat;
67 };
68
69} // namespace pacpus
70
71#endif // DEF_PACPUS_PERIODIC_WORKER_H
Note: See TracBrowser for help on using the repository browser.