30 #include <boost/date_time.hpp>
35 #pragma warning(disable : 4996)
36 #include <boost/signals2.hpp>
38 #ifdef ROBOTRACONTEUR_WINDOWS
42 namespace RobotRaconteur
45 enum TransportListenerEventType
47 TransportListenerEventType_TransportClosed = 1,
48 TransportListenerEventType_TransportConnectionClosed
51 class ROBOTRACONTEUR_CORE_API RobotRaconteurNode;
52 class ROBOTRACONTEUR_CORE_API Timer;
53 struct ROBOTRACONTEUR_CORE_API TimerEvent;
54 class ROBOTRACONTEUR_CORE_API AutoResetEvent;
55 class ROBOTRACONTEUR_CORE_API Transport;
57 class ROBOTRACONTEUR_CORE_API ITransportTimeProvider
60 virtual boost::posix_time::ptime NowUTC() = 0;
62 virtual TimeSpec NowTimeSpec() = 0;
64 virtual boost::posix_time::ptime NowNodeTime() = 0;
66 virtual boost::posix_time::ptime NodeSyncTimeUTC() = 0;
68 virtual TimeSpec NodeSyncTimeSpec() = 0;
70 virtual RR_SHARED_PTR<Timer> CreateTimer(
const boost::posix_time::time_duration& duration,
71 const boost::function<
void(
const TimerEvent&)>& handler,
72 bool oneshot =
false) = 0;
74 virtual RR_SHARED_PTR<Rate> CreateRate(
double frequency) = 0;
76 virtual void Sleep(
const boost::posix_time::time_duration& duration) = 0;
78 virtual RR_SHARED_PTR<AutoResetEvent> CreateAutoResetEvent() = 0;
80 virtual ~ITransportTimeProvider() {}
83 class ROBOTRACONTEUR_CORE_API ITransportConnection : boost::noncopyable
86 virtual ~ITransportConnection() {}
88 virtual void SendMessage(
const RR_INTRUSIVE_PTR<Message>& m) = 0;
90 virtual void AsyncSendMessage(
91 const RR_INTRUSIVE_PTR<Message>& m,
92 const boost::function<
void(
const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
94 virtual void Close() = 0;
96 virtual void CheckConnection(uint32_t endpoint) = 0;
98 virtual uint32_t GetLocalEndpoint() = 0;
100 virtual uint32_t GetRemoteEndpoint() = 0;
102 virtual NodeID GetRemoteNodeID() = 0;
104 virtual RR_SHARED_PTR<RobotRaconteurNode> GetNode() = 0;
106 virtual bool CheckCapabilityActive(uint32_t flag) = 0;
108 virtual RR_SHARED_PTR<Transport> GetTransport() = 0;
111 class ROBOTRACONTEUR_CORE_API NodeDiscoveryInfo;
119 class ROBOTRACONTEUR_CORE_API
Transport :
public IPeriodicCleanupTask, boost::noncopyable
123 friend class ITransport;
127 RR_WEAK_PTR<RobotRaconteurNode> node;
130 Transport(
const RR_SHARED_PTR<RobotRaconteurNode>& node);
132 static boost::thread_specific_ptr<std::string> m_CurrentThreadTransportConnectionURL;
134 static std::string GetCurrentTransportConnectionURL();
136 static boost::thread_specific_ptr<RR_SHARED_PTR<ITransportConnection> > m_CurrentThreadTransport;
138 static RR_SHARED_PTR<ITransportConnection> GetCurrentThreadTransport();
142 uint32_t TransportID;
144 virtual void CheckConnection(uint32_t endpoint) = 0;
146 virtual bool IsClient()
const = 0;
148 virtual bool IsServer()
const = 0;
150 virtual std::string GetUrlSchemeString()
const = 0;
152 virtual std::vector<std::string> GetServerListenUrls() = 0;
156 virtual bool CanConnectService(boost::string_ref url) = 0;
158 virtual RR_SHARED_PTR<ITransportConnection> CreateTransportConnection(boost::string_ref url,
159 const RR_SHARED_PTR<Endpoint>& e) = 0;
161 virtual void AsyncCreateTransportConnection(
162 boost::string_ref url,
const RR_SHARED_PTR<Endpoint>& e,
163 boost::function<
void(
const RR_SHARED_PTR<ITransportConnection>&,
164 const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
166 virtual void CloseTransportConnection(
const RR_SHARED_PTR<Endpoint>& e) = 0;
168 virtual void SendMessage(
const RR_INTRUSIVE_PTR<Message>& m) = 0;
170 virtual void AsyncSendMessage(
171 const RR_INTRUSIVE_PTR<Message>& m,
172 const boost::function<
void(
const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
174 virtual void MessageReceived(
const RR_INTRUSIVE_PTR<Message>& m) = 0;
176 virtual RR_INTRUSIVE_PTR<Message> SpecialRequest(
const RR_INTRUSIVE_PTR<Message>& m,
177 const RR_SHARED_PTR<ITransportConnection>& tc);
179 virtual void Close();
181 RR_OVIRTUAL
void PeriodicCleanupTask() RR_OVERRIDE;
183 virtual uint32_t TransportCapability(boost::string_ref name);
188 boost::signals2::signal<void(
const RR_SHARED_PTR<Transport>& transport, TransportListenerEventType ev,
189 const RR_SHARED_PTR<void>& parameter)>
192 virtual RR_SHARED_PTR<RobotRaconteurNode> GetNode()
const;
194 virtual std::vector<NodeDiscoveryInfo> GetDetectedNodes(
const std::vector<std::string>& schemes);
196 virtual void AsyncGetDetectedNodes(
197 const std::vector<std::string>& schemes,
198 const boost::function<
void(
const RR_SHARED_PTR<std::vector<NodeDiscoveryInfo> >&)>& handler,
202 virtual void LocalNodeServicesChanged();
204 void FireTransportEventListener(
const RR_SHARED_PTR<Transport>& shared_this, TransportListenerEventType ev,
205 const RR_SHARED_PTR<void>& parameter);
207 void TransportConnectionClosed(uint32_t endpoint);
210 struct ROBOTRACONTEUR_CORE_API ParseConnectionURLResult
212 ParseConnectionURLResult() : port(0) {}
219 std::string nodename;
223 ROBOTRACONTEUR_CORE_API ParseConnectionURLResult ParseConnectionURL(boost::string_ref url);
225 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
228 using ITransportConnectionPtr = RR_SHARED_PTR<ITransportConnection>;
#define RR_TIMEOUT_INFINITE
Disable timeout for asynchronous operations.
Definition: RobotRaconteurConstants.h:566
boost::shared_ptr< Transport > TransportPtr
Convenience alias for Transport shared_ptr.
Definition: Transport.h:227
The central node implementation.
Definition: RobotRaconteurNode.h:132
Base class for transports.
Definition: Transport.h:120