Remote Call Framework 3.3
PeriodicTimer.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://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 under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_PERIODICTIMER_HPP
19 #define INCLUDE_RCF_PERIODICTIMER_HPP
20 
21 #include <RCF/AsioFwd.hpp>
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 
37  Mutex mMutex;
38  PeriodicTimer * mpPeriodicTimer;
39  };
40 
41  typedef std::shared_ptr<TimerControlBlock> TimerControlBlockPtr;
42  typedef std::shared_ptr<AsioTimer> AsioTimerPtr;
43 
44  class RCF_EXPORT PeriodicTimer
45  {
46  public:
47  PeriodicTimer(I_Service & service, std::uint32_t intervalMs);
48  ~PeriodicTimer();
49 
50  void start();
51  void stop();
52 
53  void setIntervalMs(std::uint32_t intervalMs);
54  std::uint32_t getIntervalMs();
55 
56  private:
57 
58  friend class PeriodicTimerSentry;
59 
60  void setTimer();
61  void onTimer();
62 
63  static void sOnTimer(
64  const AsioErrorCode & ec,
65  TimerControlBlockPtr tcbPtr);
66 
67  TimerControlBlockPtr mTcbPtr;
68  I_Service & mService;
69  std::uint32_t mIntervalMs;
70  Timer mLastRunTimer;
71  AsioTimerPtr mAsioTimerPtr;
72  };
73 
74 } // namespace RCF
75 
76 #endif // ! INCLUDE_RCF_PERIODICTIMER_HPP
Definition: AmiIoHandler.hpp:23