Remote Call Framework 3.2
PeriodicTimer.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, 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: 3.2
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/AsioFwd.hpp>
23 #include <RCF/Export.hpp>
24 #include <RCF/ThreadLibrary.hpp>
25 #include <RCF/Timer.hpp>
26 
27 namespace RCF {
28 
29  class AsioTimer;
30  class I_Service;
31  class PeriodicTimer;
32 
33  class TimerControlBlock
34  {
35  public:
36  TimerControlBlock(PeriodicTimer * pPeriodicTimer);
37 
38  Mutex mMutex;
39  PeriodicTimer * mpPeriodicTimer;
40  };
41 
42  typedef std::shared_ptr<TimerControlBlock> TimerControlBlockPtr;
43  typedef std::shared_ptr<AsioTimer> AsioTimerPtr;
44 
45  class RCF_EXPORT PeriodicTimer
46  {
47  public:
48  PeriodicTimer(I_Service & service, std::uint32_t intervalMs);
49  ~PeriodicTimer();
50 
51  void start();
52  void stop();
53 
54  void setIntervalMs(std::uint32_t intervalMs);
55  std::uint32_t getIntervalMs();
56 
57  private:
58 
59  friend class PeriodicTimerSentry;
60 
61  void setTimer();
62  void onTimer();
63 
64  static void sOnTimer(
65  const AsioErrorCode & ec,
66  TimerControlBlockPtr tcbPtr);
67 
68  TimerControlBlockPtr mTcbPtr;
69  I_Service & mService;
70  std::uint32_t mIntervalMs;
71  Timer mLastRunTimer;
72  AsioTimerPtr mAsioTimerPtr;
73  };
74 
75 } // namespace RCF
76 
77 #endif // ! INCLUDE_RCF_PERIODICTIMER_HPP
Definition: AmiIoHandler.hpp:24