Remote Call Framework 3.3
PingBackService.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_PINGBACKSERVICE_HPP
19 #define INCLUDE_RCF_PINGBACKSERVICE_HPP
20 
21 #include <memory>
22 
23 #include <RCF/Export.hpp>
24 #include <RCF/Heap.hpp>
25 #include <RCF/Service.hpp>
26 
27 namespace RCF {
28 
29  class RcfSession;
30  typedef std::shared_ptr<RcfSession> RcfSessionPtr;
31  typedef std::weak_ptr<RcfSession> RcfSessionWeakPtr;
32 
33  typedef std::pair<std::uint32_t, RcfSessionWeakPtr> PingBackTimerEntry;
34 
35  class RCF_EXPORT PingBackService : public I_Service
36  {
37  public:
38 
39  typedef std::weak_ptr<RcfSession> RcfSessionWeakPtr;
40 
41  PingBackService();
42 
43  PingBackTimerEntry registerSession(RcfSessionPtr rcfSessionPtr);
44  void unregisterSession(const PingBackTimerEntry & entry);
45 
46  private:
47 
48  typedef PingBackTimerEntry Entry;
49 
50  void onServiceAdded(RcfServer &server);
51  void onServiceRemoved(RcfServer &server);
52  void stop();
53  void cycle(int timeoutMs);
54 
55  bool mEnabled;
56  bool mLazyStarted;
57 
58  // Internally synchronized.
59  TimerHeap<RcfSessionWeakPtr> mTimerHeap;
60 
61  Mutex mMutex;
62  Condition mCondition;
63  };
64 
65  typedef std::shared_ptr<PingBackService> PingBackServicePtr;
66 
67 } // namespace RCF
68 
69 #endif // ! INCLUDE_RCF_PINGBACKSERVICE_HPP
Definition: AmiIoHandler.hpp:23