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