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

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

[doc] Added: Pacpus API reference main page.
Fixed: example sections in doc.

  • Property svn:keywords set to Id
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 115 2013-06-25 09:37:38Z 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// Includes, pacpus.
18#include "Pacpus/kernel/PacpusToolsConfig.h"
19#include <Pacpus/PacpusTools/AsyncWorkerBase.h>
20
21class QTimer;
22
23namespace pacpus
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 /// ~~~
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.