Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
Transport.h
Go to the documentation of this file.
1
23
24#pragma once
25
30#include <boost/date_time.hpp>
31
33
34#ifdef _MSVC_VER
35#pragma warning(push)
36#pragma warning(disable : 4996)
37#endif
38#include <boost/signals2.hpp>
39
40#ifdef ROBOTRACONTEUR_WINDOWS
41#undef SendMessage
42#endif
43
44namespace RobotRaconteur
45{
46
47enum TransportListenerEventType
48{
49 TransportListenerEventType_TransportClosed = 1,
50 TransportListenerEventType_TransportConnectionClosed
51};
52
53class ROBOTRACONTEUR_CORE_API RobotRaconteurNode;
54class ROBOTRACONTEUR_CORE_API Timer;
55struct ROBOTRACONTEUR_CORE_API TimerEvent;
56class ROBOTRACONTEUR_CORE_API AutoResetEvent;
57class ROBOTRACONTEUR_CORE_API Transport;
58
59class ROBOTRACONTEUR_CORE_API ITransportTimeProvider
60{
61 public:
62 virtual boost::posix_time::ptime NowUTC() = 0;
63
64 virtual TimeSpec NowTimeSpec() = 0;
65
66 virtual boost::posix_time::ptime NowNodeTime() = 0;
67
68 virtual boost::posix_time::ptime NodeSyncTimeUTC() = 0;
69
70 virtual TimeSpec NodeSyncTimeSpec() = 0;
71
72 virtual RR_SHARED_PTR<Timer> CreateTimer(const boost::posix_time::time_duration& duration,
73 const boost::function<void(const TimerEvent&)>& handler,
74 bool oneshot = false) = 0;
75
76 virtual RR_SHARED_PTR<Rate> CreateRate(double frequency) = 0;
77
78 virtual void Sleep(const boost::posix_time::time_duration& duration) = 0;
79
80 virtual RR_SHARED_PTR<AutoResetEvent> CreateAutoResetEvent() = 0;
81
82 virtual ~ITransportTimeProvider() {}
83};
84
85class ROBOTRACONTEUR_CORE_API ITransportConnection : boost::noncopyable
86{
87 public:
88 virtual ~ITransportConnection() {}
89
90 virtual void SendMessage(const RR_INTRUSIVE_PTR<Message>& m) = 0;
91
92 virtual void AsyncSendMessage(
93 const RR_INTRUSIVE_PTR<Message>& m,
94 const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
95
96 virtual void Close() = 0;
97
98 virtual void CheckConnection(uint32_t endpoint) = 0;
99
100 virtual uint32_t GetLocalEndpoint() = 0;
101
102 virtual uint32_t GetRemoteEndpoint() = 0;
103
104 virtual NodeID GetRemoteNodeID() = 0;
105
106 virtual RR_SHARED_PTR<RobotRaconteurNode> GetNode() = 0;
107
108 virtual bool CheckCapabilityActive(uint32_t flag) = 0;
109
110 virtual RR_SHARED_PTR<Transport> GetTransport() = 0;
111};
112
113class ROBOTRACONTEUR_CORE_API NodeDiscoveryInfo;
114
121class ROBOTRACONTEUR_CORE_API Transport : public IPeriodicCleanupTask, boost::noncopyable
122{
123 public:
124 friend class RobotRaconteurNode;
125 friend class ITransport;
126 RR_OVIRTUAL ~Transport() RR_OVERRIDE {}
127
128 protected:
129 RR_WEAK_PTR<RobotRaconteurNode> node;
130
131 public:
132 Transport(const RR_SHARED_PTR<RobotRaconteurNode>& node);
133
134 static boost::thread_specific_ptr<std::string> m_CurrentThreadTransportConnectionURL;
135
136 static std::string GetCurrentTransportConnectionURL();
137
138 static boost::thread_specific_ptr<RR_SHARED_PTR<ITransportConnection> > m_CurrentThreadTransport;
139
140 static RR_SHARED_PTR<ITransportConnection> GetCurrentThreadTransport();
141
142 uint32_t TransportID;
143
144 virtual void CheckConnection(uint32_t endpoint) = 0;
145
146 virtual bool IsClient() const = 0;
147
148 virtual bool IsServer() const = 0;
149
150 virtual std::string GetUrlSchemeString() const = 0;
151
152 virtual std::vector<std::string> GetServerListenUrls() = 0;
153
154 virtual bool CanConnectService(boost::string_ref url) = 0;
155
156 virtual RR_SHARED_PTR<ITransportConnection> CreateTransportConnection(boost::string_ref url,
157 const RR_SHARED_PTR<Endpoint>& e) = 0;
158
159 virtual void AsyncCreateTransportConnection(
160 boost::string_ref url, const RR_SHARED_PTR<Endpoint>& e,
161 boost::function<void(const RR_SHARED_PTR<ITransportConnection>&,
162 const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
163
164 virtual void CloseTransportConnection(const RR_SHARED_PTR<Endpoint>& e) = 0;
165
166 virtual void SendMessage(const RR_INTRUSIVE_PTR<Message>& m) = 0;
167
168 virtual void AsyncSendMessage(
169 const RR_INTRUSIVE_PTR<Message>& m,
170 const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) = 0;
171
172 virtual void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m) = 0;
173
174 virtual RR_INTRUSIVE_PTR<Message> SpecialRequest(const RR_INTRUSIVE_PTR<Message>& m,
175 const RR_SHARED_PTR<ITransportConnection>& tc);
176
177 virtual void Close();
178
179 RR_OVIRTUAL void PeriodicCleanupTask() RR_OVERRIDE;
180
181 virtual uint32_t TransportCapability(boost::string_ref name);
182
183 boost::signals2::signal<void(const RR_SHARED_PTR<Transport>& transport, TransportListenerEventType ev,
184 const RR_SHARED_PTR<void>& parameter)>
185 TransportListeners;
186
187 virtual RR_SHARED_PTR<RobotRaconteurNode> GetNode() const;
188
189 virtual std::vector<NodeDiscoveryInfo> GetDetectedNodes(const std::vector<std::string>& schemes);
190
191 virtual void AsyncGetDetectedNodes(
192 const std::vector<std::string>& schemes,
193 const boost::function<void(const RR_SHARED_PTR<std::vector<NodeDiscoveryInfo> >&)>& handler,
194 int32_t timeout = RR_TIMEOUT_INFINITE);
195
196 protected:
197 virtual void LocalNodeServicesChanged();
198
199 void FireTransportEventListener(const RR_SHARED_PTR<Transport>& shared_this, TransportListenerEventType ev,
200 const RR_SHARED_PTR<void>& parameter);
201
202 void TransportConnectionClosed(uint32_t endpoint);
203};
204
205struct ROBOTRACONTEUR_CORE_API ParseConnectionURLResult
206{
207 ParseConnectionURLResult() : port(0) {}
208
209 std::string scheme;
210 std::string host;
211 int32_t port;
212 std::string path;
213 NodeID nodeid;
214 std::string nodename;
215 std::string service;
216};
217
218ROBOTRACONTEUR_CORE_API ParseConnectionURLResult ParseConnectionURL(boost::string_ref url);
219
220#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
222using TransportPtr = RR_SHARED_PTR<Transport>;
223using ITransportConnectionPtr = RR_SHARED_PTR<ITransportConnection>;
224#endif
225
226} // namespace RobotRaconteur
227
228#ifdef _MSVC_VER
229#pragma warning(pop)
230#endif
#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:222
Synchronization event for thread synchronization. Resets automatically after being triggered.
Definition AutoResetEvent.h:36
Raw information used to announce and detect nodes.
Definition Discovery.h:137
The central node implementation.
Definition RobotRaconteurNode.h:132
A timer to invoke a callback.
Definition Timer.h:80
Base class for transports.
Definition Transport.h:122
Timer event structure.
Definition Timer.h:55