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