RCFProto

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
PeriodicTimer.hpp
1
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18
19 #ifndef INCLUDE_RCF_PERIODICTIMER_HPP
20 #define INCLUDE_RCF_PERIODICTIMER_HPP
21
22 #include <RCF/Export.hpp>
23 #include <RCF/ThreadLibrary.hpp>
24 #include <RCF/Timer.hpp>
25
26 namespace RCF {
27
28 class AsioTimer;
29 class I_Service;
30 class PeriodicTimer;
31
32 class TimerControlBlock
33 {
34 public:
35 TimerControlBlock(PeriodicTimer * pPeriodicTimer) :
36 mpPeriodicTimer(pPeriodicTimer)
37 {
38 }
39
40 Mutex mMutex;
41 PeriodicTimer * mpPeriodicTimer;
42 };
43
44 typedef boost::shared_ptr<TimerControlBlock> TimerControlBlockPtr;
45
46 class RCF_EXPORT PeriodicTimer
47 {
48 public:
49 PeriodicTimer(I_Service & service, boost::uint32_t intervalMs);
50 ~PeriodicTimer();
51
52 void start();
53 void stop();
54
55 void setIntervalMs(boost::uint32_t intervalMs);
56 boost::uint32_t getIntervalMs();
57
58 private:
59
60 friend class PeriodicTimerSentry;
61
62 void setTimer();
63 void onTimer();
64
65 static void sOnTimer(
66 const AsioErrorCode & ec,
67 TimerControlBlockPtr tcbPtr);
68
69 TimerControlBlockPtr mTcbPtr;
70 I_Service & mService;
71 boost::uint32_t mIntervalMs;
72 Timer mLastRunTimer;
73 //AsioDeadlineTimer mAsioTimer;
74 AsioTimerPtr mAsioTimerPtr;
75 };
76
77 } // namespace RCF
78
79 #endif // ! INCLUDE_RCF_PERIODICTIMER_HPP
80
81