Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
HardwareTransport.h
Go to the documentation of this file.
1
23
25#include <boost/shared_array.hpp>
26#include <boost/asio/windows/stream_handle.hpp>
27
28#pragma once
29
30namespace RobotRaconteur
31{
32class ROBOTRACONTEUR_CORE_API LocalTransportConnection;
33
51class ROBOTRACONTEUR_CORE_API HardwareTransport : public Transport, public RR_ENABLE_SHARED_FROM_THIS<HardwareTransport>
52{
53 friend class HardwareTransportConnection;
54
55 private:
56 bool transportopen;
57
58 public:
59 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<ITransportConnection> > TransportConnections;
60 boost::mutex TransportConnections_lock;
61
75 HardwareTransport(const RR_SHARED_PTR<RobotRaconteurNode>& node = RobotRaconteurNode::sp());
76
77 RR_OVIRTUAL ~HardwareTransport() RR_OVERRIDE;
78
79 RR_OVIRTUAL bool IsServer() const RR_OVERRIDE;
80
81 RR_OVIRTUAL bool IsClient() const RR_OVERRIDE;
82
83 RR_OVIRTUAL std::string GetUrlSchemeString() const RR_OVERRIDE;
84
85 RR_OVIRTUAL std::vector<std::string> GetServerListenUrls() RR_OVERRIDE;
86
87 RR_OVIRTUAL void SendMessage(const RR_INTRUSIVE_PTR<Message>& m) RR_OVERRIDE;
88
89 RR_OVIRTUAL void AsyncSendMessage(
90 const RR_INTRUSIVE_PTR<Message>& m,
91 const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& handler) RR_OVERRIDE;
92
93 RR_OVIRTUAL void AsyncCreateTransportConnection(
94 boost::string_ref url, const RR_SHARED_PTR<Endpoint>& e,
95 boost::function<void(const RR_SHARED_PTR<ITransportConnection>&,
96 const RR_SHARED_PTR<RobotRaconteurException>&)>& callback) RR_OVERRIDE;
97
98 RR_OVIRTUAL RR_SHARED_PTR<ITransportConnection> CreateTransportConnection(
99 boost::string_ref url, const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE;
100
101 RR_OVIRTUAL void CloseTransportConnection(const RR_SHARED_PTR<Endpoint>& e) RR_OVERRIDE;
102
103 protected:
104 virtual void AsyncCreateTransportConnection2(
105 const std::string& noden, const RR_SHARED_PTR<ITransportConnection>& transport,
106 const RR_SHARED_PTR<RobotRaconteurException>& err,
107 boost::function<void(const RR_SHARED_PTR<ITransportConnection>&,
108 const RR_SHARED_PTR<RobotRaconteurException>&)>& callback);
109
110 virtual void CloseTransportConnection_timed(const boost::system::error_code& err, const RR_SHARED_PTR<Endpoint>& e,
111 const RR_SHARED_PTR<void>& timer);
112
113 public:
114 RR_OVIRTUAL bool CanConnectService(boost::string_ref url) RR_OVERRIDE;
115
116 RR_OVIRTUAL void Close() RR_OVERRIDE;
117
118 RR_OVIRTUAL void CheckConnection(uint32_t endpoint) RR_OVERRIDE;
119
120 RR_OVIRTUAL void PeriodicCleanupTask() RR_OVERRIDE;
121
122 RR_OVIRTUAL uint32_t TransportCapability(boost::string_ref name) RR_OVERRIDE;
123
124 RR_OVIRTUAL void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m) RR_OVERRIDE;
125
126 RR_OVIRTUAL void AsyncGetDetectedNodes(
127 const std::vector<std::string>& schemes,
128 const boost::function<void(const RR_SHARED_PTR<std::vector<NodeDiscoveryInfo> >&)>& handler,
129 int32_t timeout = RR_TIMEOUT_INFINITE) RR_OVERRIDE;
130
132 virtual int32_t GetMaxMessageSize();
134 virtual void SetMaxMessageSize(int32_t size);
135
137 virtual bool GetDisableMessage4();
139 virtual void SetDisableMessage4(bool d);
140
142 virtual bool GetDisableStringTable();
144 virtual void SetDisableStringTable(bool d);
145
149 virtual void SetDisableAsyncMessageIO(bool d);
150
158 virtual void AddUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_);
159
167 virtual void RemoveUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_);
168
178 virtual bool IsValidUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_);
179
180 virtual void register_transport(const RR_SHARED_PTR<ITransportConnection>& connection);
181 virtual void erase_transport(const RR_SHARED_PTR<ITransportConnection>& connection);
182
183 template <typename T, typename F>
184 boost::signals2::connection AddCloseListener(const RR_SHARED_PTR<T>& t, const F& f)
185 {
186 boost::mutex::scoped_lock lock(closed_lock);
187 if (closed)
188 {
189 lock.unlock();
190 boost::bind(f, t)();
191 return boost::signals2::connection();
192 }
193
194 return close_signal.connect(boost::signals2::signal<void()>::slot_type(boost::bind(f, t.get())).track(t));
195 }
196
197 protected:
198 boost::mutex parameter_lock;
199 int32_t max_message_size;
200 bool disable_message4;
201 bool disable_string_table;
202 bool disable_async_message_io;
203
204 boost::mutex discovery_lock;
205
206 RR_SHARED_PTR<void> internal1;
207 RR_SHARED_PTR<void> internal2;
208 RR_SHARED_PTR<void> internal3;
209 RR_SHARED_PTR<void> internal4;
210
211 std::list<boost::tuple<uint16_t, uint16_t, uint8_t> > usb_devices;
212
213 bool closed;
214 boost::mutex closed_lock;
215 boost::signals2::signal<void()> close_signal;
216};
217#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
218using HardwareTransportPtr = RR_SHARED_PTR<HardwareTransport>;
219#endif
220} // namespace RobotRaconteur
#define RR_TIMEOUT_INFINITE
Disable timeout for asynchronous operations.
Definition RobotRaconteurConstants.h:566
virtual void RemoveUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_)
Remove a registered USB VID/PID pair.
virtual bool GetDisableAsyncMessageIO()
Get if async message io is disabled.
virtual void AddUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_)
Add a USB VID/PID pair to the search list.
virtual void SetDisableMessage4(bool d)
Set disable Message Format Version 4.
virtual void SetDisableAsyncMessageIO(bool d)
Get if async message io is disabled.
virtual int32_t GetMaxMessageSize()
Get the maximum serialized message size.
virtual void SetDisableStringTable(bool d)
Set disable string table.
virtual bool GetDisableMessage4()
Get disable Message Format Version 4.
virtual void SetMaxMessageSize(int32_t size)
Set the maximum serialized message size.
HardwareTransport(const boost::shared_ptr< RobotRaconteurNode > &node=RobotRaconteurNode::sp())
Construct a new HardwareTransport.
virtual bool GetDisableStringTable()
Get disable string table.
virtual bool IsValidUsbDevice(uint16_t vid, uint16_t pid, uint8_t interface_)
Check if VID/PID pair has been registered.
Raw information used to announce and detect nodes.
Definition Discovery.h:137
Base class for Robot Raconteur exceptions.
Definition Error.h:53
static boost::shared_ptr< RobotRaconteurNode > sp()
Singleton shared_ptr accessor.