Robot Raconteur Core C++ Library
Endpoint.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include "RobotRaconteur/NodeID.h"
27 
28 #include "RobotRaconteur/Error.h"
30 #include "RobotRaconteur/Message.h"
31 #include <boost/date_time.hpp>
32 #include <boost/atomic.hpp>
33 
34 // Workaround for Windows headers
35 #ifdef SendMessage
36 #undef SendMessage
37 #endif
38 
39 namespace RobotRaconteur
40 {
41 
42 class ROBOTRACONTEUR_CORE_API RobotRaconteurNode;
43 class ROBOTRACONTEUR_CORE_API ITransportConnection;
44 
45 class ROBOTRACONTEUR_CORE_API Endpoint : private boost::noncopyable
46 {
47  private:
48  boost::atomic<uint32_t> m_LocalEndpoint;
49  boost::atomic<uint32_t> m_RemoteEndpoint;
50  boost::shared_mutex m_RemoteNodeName_lock;
51  std::string m_RemoteNodeName;
52  boost::shared_mutex m_RemoteNodeID_lock;
53  NodeID m_RemoteNodeID;
54  boost::atomic<uint32_t> m_transport;
55 
56  boost::mutex m_TransportConnection_lock;
57  RR_WEAK_PTR<ITransportConnection> m_TransportConnection;
58 
59  boost::atomic<boost::posix_time::ptime> m_LastMessageReceivedTime;
60  boost::atomic<boost::posix_time::ptime> m_LastMessageSentTime;
61 
62  boost::atomic<uint16_t> MessageNumber;
63 
64  public:
65  uint32_t GetLocalEndpoint();
66  void SetLocalEndpoint(uint32_t endpoint);
67 
68  uint32_t GetRemoteEndpoint();
69  void SetRemoteEndpoint(uint32_t endpoint);
70 
71  std::string GetRemoteNodeName();
72  void SetRemoteNodeName(boost::string_ref name);
73 
74  NodeID GetRemoteNodeID();
75  void SetRemoteNodeID(const NodeID& id);
76 
77  uint32_t GetTransport();
78  void SetTransport(uint32_t transport);
79 
80  virtual RR_SHARED_PTR<ITransportConnection> GetTransportConnection();
81  virtual void SetTransportConnection(const RR_SHARED_PTR<ITransportConnection>& c);
82 
83  boost::posix_time::ptime GetLastMessageReceivedTime();
84  void SetLastMessageReceivedTime(boost::posix_time::ptime time);
85 
86  boost::posix_time::ptime GetLastMessageSentTime();
87  void SetLastMessageSentTime(boost::posix_time::ptime time);
88 
89  virtual void SendMessage(const RR_INTRUSIVE_PTR<Message>& m);
90 
91  virtual void AsyncSendMessage(const RR_INTRUSIVE_PTR<Message>& m,
92  const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& callback);
93 
94  virtual void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m) = 0;
95 
96  virtual void PeriodicCleanupTask();
97 
98  virtual void TransportConnectionClosed(uint32_t endpoint);
99 
100  protected:
101  virtual void CheckEndpointCapabilityMessage(const RR_INTRUSIVE_PTR<Message>& m);
102 
103  public:
104  virtual uint32_t EndpointCapability(boost::string_ref name);
105 
106  Endpoint(const RR_SHARED_PTR<RobotRaconteurNode>& node);
107 
108  virtual ~Endpoint() {}
109 
110  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
111 
112  protected:
113  RR_WEAK_PTR<RobotRaconteurNode> node;
114 };
115 
116 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
117 using EndpointPtr = RR_SHARED_PTR<Endpoint>;
118 using EndpointConstPtr = RR_SHARED_PTR<const Endpoint>;
119 #endif
120 
121 } // namespace RobotRaconteur