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

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

Added: PacpusException - base class for all exceptions. DbiteExceptions inherits from it.
Added: PacpusLibConfig.h - dllimport/dllexport clauses separated from pacpus.h.
Update: comments.

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