Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
RobotRaconteurNode.h
Go to the documentation of this file.
1
23
24#pragma once
25
39#include "RobotRaconteur/Tap.h"
41
42#include <queue>
43#include <boost/bind/placeholders.hpp>
44#include <boost/unordered_map.hpp>
45#include <boost/function.hpp>
46#include <boost/bind/protect.hpp>
47#include <boost/random.hpp>
48#include <boost/random/random_device.hpp>
49#include <boost/chrono.hpp>
50
51#ifndef ROBOTRACONTEUR_EMSCRIPTEN
52#include <boost/asio.hpp>
53#endif
54#include <boost/asio/error.hpp>
55#include <boost/asio/placeholders.hpp>
56
57#ifdef ROBOTRACONTEUR_WINDOWS
58
59#undef SendMessage
60
61#endif
62
63namespace boost
64{
65namespace random
66{
67class random_device;
68}
69} // namespace boost
70
71namespace RobotRaconteur
72{
73
94
95class ROBOTRACONTEUR_CORE_API ServiceSecurityPolicy;
96class ROBOTRACONTEUR_CORE_API ServiceInfo2Subscription;
97class ROBOTRACONTEUR_CORE_API ServiceSubscription;
98class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilter;
99class ROBOTRACONTEUR_CORE_API ServiceSubscriptionManager;
100
101namespace detail
102{
103class Discovery;
104}
105
130class ROBOTRACONTEUR_CORE_API RobotRaconteurNode : boost::noncopyable,
131 public RR_ENABLE_SHARED_FROM_THIS<RobotRaconteurNode>
132{
133 private:
134 bool is_shutdown;
135 boost::mutex shutdown_lock;
136 boost::signals2::signal<void()> shutdown_listeners;
137
138 static bool is_init;
139
140 bool instance_is_init;
141 static boost::mutex init_lock;
142
143 public:
144 friend class detail::Discovery;
145 friend class Transport;
146 friend class ServerContext;
147 friend class ServiceSubscriptionManager;
148
159 void Init();
160
168
169 virtual ~RobotRaconteurNode();
170
184
193 static RR_SHARED_PTR<RobotRaconteurNode> sp();
194
203 static RR_WEAK_PTR<RobotRaconteurNode> weak_sp();
204
214
223 std::string NodeName();
224
237
251 void SetNodeName(boost::string_ref name);
252
264
275 bool TryGetNodeName(std::string& node_name);
276
283 RR_SHARED_PTR<ServiceFactory> GetServiceType(boost::string_ref type);
284
292 bool IsServiceTypeRegistered(boost::string_ref servicetype);
293
299 void RegisterServiceType(const RR_SHARED_PTR<ServiceFactory>& factory);
300
309 void UnregisterServiceType(boost::string_ref type);
310
316 std::vector<std::string> GetRegisteredServiceTypes();
317
333 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackStructure(const RR_INTRUSIVE_PTR<RRStructure>& structure);
334
350 RR_INTRUSIVE_PTR<RRStructure> UnpackStructure(const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& structure);
351
369 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackPodArray(const RR_INTRUSIVE_PTR<RRPodBaseArray>& pod_array);
370
386 RR_INTRUSIVE_PTR<RRPodBaseArray> UnpackPodArray(const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& pod_array);
387
403 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackPodMultiDimArray(
404 const RR_INTRUSIVE_PTR<RRPodBaseMultiDimArray>& pod_multiarray);
405
421 RR_INTRUSIVE_PTR<RRPodBaseMultiDimArray> UnpackPodMultiDimArray(
422 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& pod_multiarray);
423
441 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackNamedArray(
442 const RR_INTRUSIVE_PTR<RRNamedBaseArray>& namedarray);
443
459 RR_INTRUSIVE_PTR<RRNamedBaseArray> UnpackNamedArray(
460 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& namedarray);
461
477 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackNamedMultiDimArray(
478 const RR_INTRUSIVE_PTR<RRNamedBaseMultiDimArray>& named_multiarray);
479
495 RR_INTRUSIVE_PTR<RRNamedBaseMultiDimArray> UnpackNamedMultiDimArray(
496 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& named_multiarray);
497
507 template <typename T>
508 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackMultiDimArray(
509 const RR_INTRUSIVE_PTR<RRMultiDimArray<T> >& arr)
510 {
511 return detail::packing::PackMultiDimArray<T>(arr);
512 }
513
526 template <typename T>
527 RR_INTRUSIVE_PTR<RRMultiDimArray<T> > UnpackMultiDimArray(
528 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& ar)
529 {
530 return detail::packing::UnpackMultiDimArray<T>(ar);
531 }
532
544 RR_INTRUSIVE_PTR<MessageElementData> PackVarType(const RR_INTRUSIVE_PTR<RRValue>& vardata);
545
559 RR_INTRUSIVE_PTR<RRValue> UnpackVarType(const RR_INTRUSIVE_PTR<MessageElement>& mvardata);
560
574 template <typename K, typename T, typename U>
575 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackMapType(const U& map)
576 {
577 return detail::packing::PackMapType<K, T, U>(map, this);
578 }
579
592 template <typename K, typename T>
593 RR_INTRUSIVE_PTR<RRMap<K, T> > UnpackMapType(const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& map)
594 {
595 return detail::packing::UnpackMapType<K, T>(map, this);
596 }
597
610 template <typename T, typename U>
611 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackListType(U& list)
612 {
613 return detail::packing::PackListType<T, U>(list, this);
614 }
615
627 template <typename T>
628 RR_INTRUSIVE_PTR<RRList<T> > UnpackListType(const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& list)
629 {
630 return detail::packing::UnpackListType<T>(list, this);
631 }
632
647 template <typename T, typename U>
648 RR_INTRUSIVE_PTR<MessageElementData> PackAnyType(const RR_INTRUSIVE_PTR<U>& data)
649 {
650 return detail::packing::PackAnyType<T, U>(data, this);
651 }
652
667 template <typename T>
668 T UnpackAnyType(const RR_INTRUSIVE_PTR<MessageElement>& mdata)
669 {
670 return detail::packing::UnpackAnyType<T>(mdata, this);
671 }
672
690 virtual void Shutdown();
691
696 typedef boost::signals2::connection shutdown_listener_connection;
697
710 template <typename Handler>
711 shutdown_listener_connection AddShutdownListener(BOOST_ASIO_MOVE_ARG(Handler) h)
712 {
713 // Hold the lock across the connect: Shutdown sets is_shutdown under it before calling the listeners
714 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
715 if (is_shutdown)
716 throw InvalidOperationException("Node has been shut down");
717 return shutdown_listeners.connect(h);
718 }
719
726 uint32_t RegisterTransport(const RR_SHARED_PTR<Transport>& transport);
727
742 void AsyncSendMessage(const RR_INTRUSIVE_PTR<Message>& m,
743 const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& handler);
744
760 void SendMessage(const RR_INTRUSIVE_PTR<Message>& m);
761
773 void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m);
774
775 protected:
784 void TransportConnectionClosed(uint32_t endpoint);
785
786 private:
787 uint32_t RequestTimeout;
788 boost::mutex RequestTimeout_lock;
789
790 uint32_t TransportInactivityTimeout;
791 boost::mutex TransportInactivityTimeout_lock;
792
793 uint32_t EndpointInactivityTimeout;
794 boost::mutex EndpointInactivityTimeout_lock;
795
796 uint32_t MemoryMaxTransferSize;
797 boost::mutex MemoryMaxTransferSize_lock;
798
799 public:
811
820 void SetRequestTimeout(uint32_t timeout);
821
833
842 void SetTransportInactivityTimeout(uint32_t timeout);
843
855
864 void SetEndpointInactivityTimeout(uint32_t timeout);
865
877
887 void SetMemoryMaxTransferSize(uint32_t size);
888
889 protected:
891 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Endpoint> > endpoints;
893 std::map<uint32_t, boost::posix_time::ptime> recent_endpoints;
894
896 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Transport> > transports;
898 boost::shared_mutex transports_lock;
899
901 RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> dynamic_factory;
903 boost::mutex dynamic_factory_lock;
904
905 public:
913 const RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> GetDynamicServiceFactory();
914
924 void SetDynamicServiceFactory(const RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory>& f);
925
941 RR_INTRUSIVE_PTR<Message> GenerateErrorReturnMessage(const RR_INTRUSIVE_PTR<Message>& m, MessageErrorType err,
942 boost::string_ref errname, boost::string_ref errdesc);
943
964 RR_SHARED_PTR<ServerContext> RegisterService(
965 boost::string_ref name, boost::string_ref servicetype, const RR_SHARED_PTR<RRObject>& obj,
966 const RR_SHARED_PTR<ServiceSecurityPolicy>& securitypolicy = RR_SHARED_PTR<ServiceSecurityPolicy>());
967
977 RR_SHARED_PTR<ServerContext> RegisterService(const RR_SHARED_PTR<ServerContext>& c);
978
987 void CloseService(boost::string_ref sname);
988
994 std::vector<std::string> GetRegisteredServiceNames();
995
1003 RR_SHARED_PTR<ServerContext> GetService(boost::string_ref name);
1004
1018 RR_INTRUSIVE_PTR<Message> SpecialRequest(const RR_INTRUSIVE_PTR<Message>& m, uint32_t transportid,
1019 const RR_SHARED_PTR<ITransportConnection>& tc);
1020
1048 RR_SHARED_PTR<RRObject> ConnectService(
1049 boost::string_ref url, boost::string_ref username = "",
1050 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1051 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1052 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1053 const RR_SHARED_PTR<void>&)>
1054 listener = 0,
1055 boost::string_ref objecttype = "");
1056
1076 boost::string_ref url, boost::string_ref username,
1077 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials,
1078 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1079 const RR_SHARED_PTR<void>&)>
1080 listener,
1081 boost::string_ref objecttype,
1082 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1083 int32_t timeout = RR_TIMEOUT_INFINITE);
1084
1101 RR_SHARED_PTR<RRObject> ConnectService(
1102 const std::vector<std::string>& urls, boost::string_ref username = "",
1103 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1104 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1105 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1106 const RR_SHARED_PTR<void>&)>
1107 listener = 0,
1108 boost::string_ref objecttype = "");
1109
1126 const std::vector<std::string>& url, boost::string_ref username,
1127 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials,
1128 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1129 const RR_SHARED_PTR<void>&)>
1130 listener,
1131 boost::string_ref objecttype,
1132 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1133 int32_t timeout = RR_TIMEOUT_INFINITE);
1134
1146 void DisconnectService(const RR_SHARED_PTR<RRObject>& obj);
1147
1156 void AsyncDisconnectService(const RR_SHARED_PTR<RRObject>& obj, boost::function<void()> handler);
1157
1167 std::map<std::string, RR_INTRUSIVE_PTR<RRValue> > GetServiceAttributes(const RR_SHARED_PTR<RRObject>& obj);
1168
1177 RobotRaconteur::NodeID GetServiceNodeID(const RR_SHARED_PTR<RRObject>& obj);
1178
1187 std::string GetServiceNodeName(const RR_SHARED_PTR<RRObject>& obj);
1188
1197 std::string GetServiceName(const RR_SHARED_PTR<RRObject>& obj);
1198
1205 std::string GetObjectServicePath(const RR_SHARED_PTR<RRObject>& obj);
1206
1214 virtual std::string GetObjectType(const RR_SHARED_PTR<RRObject>& obj);
1215
1226 uint32_t RegisterEndpoint(const RR_SHARED_PTR<Endpoint>& e);
1227
1237 void DeleteEndpoint(const RR_SHARED_PTR<Endpoint>& e);
1238
1246 void CheckConnection(uint32_t endpoint);
1247
1248 private:
1249 uint32_t transport_count;
1250
1251 boost::mutex endpoint_lock;
1252
1253 static RobotRaconteurNode m_s;
1254 static RR_SHARED_PTR<RobotRaconteurNode> m_sp;
1255 static RR_WEAK_PTR<RobotRaconteurNode> m_weak_sp;
1256
1257 RobotRaconteur::NodeID m_NodeID;
1258 std::string m_NodeName;
1259
1260 bool NodeID_set;
1261 bool NodeName_set;
1262
1263 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServiceFactory> > service_factories;
1264 boost::shared_mutex service_factories_lock;
1265 boost::mutex id_lock;
1266
1267 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServerContext> > services;
1268 boost::shared_mutex services_lock;
1269
1270 RR_SHARED_PTR<detail::Discovery> m_Discovery;
1271 boost::signals2::signal<void(const NodeDiscoveryInfo&, const std::vector<ServiceInfo2>&)>
1272 discovery_updated_listeners;
1273
1274 boost::signals2::signal<void(const NodeDiscoveryInfo&)> discovery_lost_listeners;
1275
1276 RR_WEAK_PTR<RobotRaconteurNode> weak_this;
1277
1278 public:
1292 std::vector<NodeDiscoveryInfo> GetDetectedNodes();
1293
1305
1317
1322 typedef boost::signals2::connection node_updated_listener_connection;
1323
1338 template <typename Handler>
1340 {
1341 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1342 if (is_shutdown)
1343 {
1344 throw InvalidOperationException("Node has been shut down");
1345 }
1346
1347 return discovery_updated_listeners.connect(h);
1348 }
1349
1354 typedef boost::signals2::connection node_lost_listener_connection;
1355
1368 template <typename Handler>
1370 {
1371 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1372 if (is_shutdown)
1373 {
1374 throw InvalidOperationException("Node has been shut down");
1375 }
1376 return discovery_lost_listeners.connect(h);
1377 }
1378
1390 void NodeAnnouncePacketReceived(boost::string_ref packet);
1391
1402 void NodeDetected(const NodeDiscoveryInfo& info);
1403
1415 void UpdateDetectedNodes(const std::vector<std::string>& schemes);
1416
1427 void AsyncUpdateDetectedNodes(const std::vector<std::string>& schemes, boost::function<void()> handler,
1428 int32_t timeout = 5000);
1429
1439
1447 void SetNodeDiscoveryMaxCacheCount(uint32_t count);
1448
1460 RR_SHARED_PTR<ServiceInfo2Subscription> SubscribeServiceInfo2(
1461 const std::vector<std::string>& service_types,
1462 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1463
1474 RR_SHARED_PTR<ServiceSubscription> SubscribeServiceByType(
1475 const std::vector<std::string>& service_types,
1476 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1477
1490 RR_SHARED_PTR<ServiceSubscription> SubscribeService(
1491 const std::vector<std::string>& url, boost::string_ref username = "",
1492 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1493 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1494 boost::string_ref objecttype = "");
1495
1508 RR_SHARED_PTR<ServiceSubscription> SubscribeService(
1509 const std::string& url, boost::string_ref username = "",
1510 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1511 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1512 boost::string_ref objecttype = "");
1513
1514 protected:
1522 void CleanDiscoveredNodes();
1523
1532 void FireNodeDetected(const RR_SHARED_PTR<NodeDiscoveryInfo>& node,
1533 const RR_SHARED_PTR<std::vector<ServiceInfo2> >& services);
1534
1542 void FireNodeLost(const RR_SHARED_PTR<NodeDiscoveryInfo>& node);
1543
1544 public:
1572 static std::string SelectRemoteNodeURL(const std::vector<std::string>& urls);
1573
1588 std::vector<ServiceInfo2> FindServiceByType(boost::string_ref servicetype,
1589 const std::vector<std::string>& transportschemes);
1590
1601 void AsyncFindServiceByType(boost::string_ref servicetype, const std::vector<std::string>& transportschemes,
1602 boost::function<void(const RR_SHARED_PTR<std::vector<ServiceInfo2> >&)> handler,
1603 int32_t timeout = 5000);
1604
1617 std::vector<NodeInfo2> FindNodeByID(const RobotRaconteur::NodeID& id,
1618 const std::vector<std::string>& transportschemes);
1619
1630 void AsyncFindNodeByID(const RobotRaconteur::NodeID& id, const std::vector<std::string>& transportschemes,
1631 boost::function<void(const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1632 int32_t timeout = 5000);
1633
1646 std::vector<NodeInfo2> FindNodeByName(boost::string_ref name, const std::vector<std::string>& transportschemes);
1647
1658 void AsyncFindNodeByName(boost::string_ref name, const std::vector<std::string>& transportschemes,
1659 boost::function<void(const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1660 int32_t timeout = 5000);
1661
1676 std::string RequestObjectLock(const RR_SHARED_PTR<RRObject>& obj, RobotRaconteurObjectLockFlags flags);
1677
1689 const RR_SHARED_PTR<RRObject>& obj, RobotRaconteurObjectLockFlags flags,
1690 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1691 int32_t timeout = RR_TIMEOUT_INFINITE);
1692
1705 std::string ReleaseObjectLock(const RR_SHARED_PTR<RRObject>& obj);
1706
1718 const RR_SHARED_PTR<RRObject>& obj,
1719 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1720 int32_t timeout = RR_TIMEOUT_INFINITE);
1721
1740 void MonitorEnter(const RR_SHARED_PTR<RRObject>& obj, int32_t timeout = RR_TIMEOUT_INFINITE);
1741
1752 void MonitorExit(const RR_SHARED_PTR<RRObject>& obj);
1753
1759 class ROBOTRACONTEUR_CORE_API ScopedMonitorLock
1760 {
1761 bool locked;
1762 RR_SHARED_PTR<RRObject> obj;
1763 RR_WEAK_PTR<RobotRaconteurNode> node;
1764
1765 public:
1771 RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1772
1783 ScopedMonitorLock(const RR_SHARED_PTR<RRObject>& obj, int32_t timeout = -1);
1784
1791 void lock(int32_t timeout = -1);
1792
1800 void unlock();
1801
1809 void release();
1810
1812 };
1813
1814 private:
1815 RR_SHARED_PTR<Timer> PeriodicCleanupTask_timer;
1816 boost::shared_mutex PeriodicCleanupTask_timer_lock;
1817
1818 static void StartPeriodicCleanupTask(const RR_SHARED_PTR<RobotRaconteurNode>& node);
1819
1820 void PeriodicCleanupTask(const TimerEvent& err);
1821 bool PeriodicCleanupTask_timerstarted;
1822
1823 std::list<RR_SHARED_PTR<IPeriodicCleanupTask> > cleanupobjs;
1824
1825 boost::mutex cleanupobjs_lock;
1826
1827 boost::mutex cleanup_thread_lock;
1828
1829 public:
1838 void AddPeriodicCleanupTask(const RR_SHARED_PTR<IPeriodicCleanupTask>& task);
1839
1845 void RemovePeriodicCleanupTask(const RR_SHARED_PTR<IPeriodicCleanupTask>& task);
1846
1865
1866 RR_SHARED_PTR<RRObject> FindObjRefTyped(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1867 boost::string_ref objecttype);
1868
1882 RR_SHARED_PTR<RRObject> FindObjRefTyped(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1883 boost::string_ref index, boost::string_ref objecttype);
1884
1897 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref objecttype,
1898 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1899 int32_t timeout = RR_TIMEOUT_INFINITE);
1900
1914 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1915 boost::string_ref objecttype,
1916 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1917 int32_t timeout = RR_TIMEOUT_INFINITE);
1918
1930 std::string FindObjectType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref);
1931
1944 std::string FindObjectType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index);
1945
1957 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1958 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1959 int32_t timeout = RR_TIMEOUT_INFINITE);
1960
1973 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1974 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1975 int32_t timeout = RR_TIMEOUT_INFINITE);
1976
1977 private:
1978 RR_SHARED_PTR<ThreadPool> thread_pool;
1979 boost::shared_mutex thread_pool_lock;
1980 RR_SHARED_PTR<ThreadPoolFactory> thread_pool_factory;
1981 boost::mutex thread_pool_factory_lock;
1982
1983 public:
1993 RR_SHARED_PTR<ThreadPool> GetThreadPool();
1994
2007 bool TryGetThreadPool(RR_SHARED_PTR<ThreadPool>& pool);
2008
2018 void SetThreadPool(const RR_SHARED_PTR<ThreadPool>& pool);
2019
2030 RR_SHARED_PTR<ThreadPoolFactory> GetThreadPoolFactory();
2031
2040 void SetThreadPoolFactory(const RR_SHARED_PTR<ThreadPoolFactory>& factory);
2041
2048
2059 void SetThreadPoolCount(int32_t count);
2060
2077 template <typename HandlerType>
2078 static bool TryPostToThreadPool(RR_WEAK_PTR<RobotRaconteurNode> node, BOOST_ASIO_MOVE_ARG(HandlerType) h,
2079 bool shutdown_op = false)
2080 {
2081 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2082 if (!node1)
2083 return false;
2084 {
2085 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2086 if (!shutdown_op && node1->is_shutdown)
2087 return false;
2088 }
2089 RR_SHARED_PTR<ThreadPool> t;
2090 if (!node1->TryGetThreadPool(t))
2091 return false;
2092 return t->TryPost(RR_FORWARD(HandlerType, h));
2093 }
2094
2101
2102 protected:
2114 bool InitThreadPool(int32_t thread_count);
2115
2116 public:
2130 std::vector<std::string> GetPulledServiceTypes(const RR_SHARED_PTR<RRObject>& obj);
2131
2146 RR_SHARED_PTR<ServiceFactory> GetPulledServiceType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref type);
2147
2159 void SetExceptionHandler(boost::function<void(const std::exception*)> handler);
2160
2169 boost::function<void(const std::exception*)> GetExceptionHandler();
2170
2177 void HandleException(const std::exception* exp);
2178
2191 static bool TryHandleException(RR_WEAK_PTR<RobotRaconteurNode> node, const std::exception* exp);
2192
2193 protected:
2195 boost::function<void(const std::exception*)> exception_handler;
2197 boost::mutex exception_handler_lock;
2198
2200 boost::mutex random_generator_lock;
2202 RR_SHARED_PTR<boost::random::random_device> random_generator;
2203
2204 public:
2214 virtual boost::posix_time::ptime NowUTC();
2215
2224
2237 virtual boost::posix_time::ptime NowNodeTime();
2238
2253 virtual boost::posix_time::ptime NodeSyncTimeUTC();
2254
2263
2264 protected:
2266 RR_WEAK_PTR<ITransportTimeProvider> time_provider;
2268 boost::shared_mutex time_provider_lock;
2269
2271 boost::posix_time::ptime node_sync_time;
2272 TimeSpec node_sync_timespec;
2273 boost::chrono::steady_clock::time_point node_internal_start_time;
2274
2275 public:
2294 virtual RR_SHARED_PTR<Timer> CreateTimer(const boost::posix_time::time_duration& period,
2295 boost::function<void(const TimerEvent&)> handler, bool oneshot = false);
2296
2307 virtual RR_SHARED_PTR<Rate> CreateRate(double frequency);
2308
2319 virtual void Sleep(const boost::posix_time::time_duration& duration);
2320
2329 virtual RR_SHARED_PTR<AutoResetEvent> CreateAutoResetEvent();
2330
2341
2351 RR_SHARED_PTR<RobotRaconteurException> DownCastException(const RR_SHARED_PTR<RobotRaconteurException>& exp);
2352
2364 bool IsEndpointLargeTransferAuthorized(uint32_t endpoint);
2365
2374
2384 template <typename T>
2385 T GetRandomInt(T min, T max)
2386 {
2387 boost::mutex::scoped_lock lock(random_generator_lock);
2388 boost::random::uniform_int_distribution<T> d(min, max);
2389 return d(*random_generator);
2390 }
2391
2402 template <typename T>
2403 std::vector<T> GetRandomInts(size_t count, T min, T max)
2404 {
2405 std::vector<T> o;
2406 o.resize(count);
2407 boost::mutex::scoped_lock lock(random_generator_lock);
2408 for (size_t i = 0; i < count; i++)
2409 {
2410 boost::random::uniform_int_distribution<T> d(min, max);
2411 o[i] = d(*random_generator);
2412 }
2413 return o;
2414 }
2415
2425 std::string GetRandomString(size_t count);
2426
2427 protected:
2429 std::string service_state_nonce;
2431 boost::mutex service_state_nonce_lock;
2432
2433 public:
2448 std::string GetServiceStateNonce();
2449
2457 void UpdateServiceStateNonce();
2458
2459 protected:
2460 RR_SHARED_PTR<LogRecordHandler> log_handler;
2461 boost::shared_mutex log_handler_mutex;
2462 RobotRaconteur_LogLevel log_level;
2463 boost::shared_mutex log_level_mutex;
2464
2465 public:
2474
2487 void LogMessage(RobotRaconteur_LogLevel level, const std::string& message);
2488
2501 void LogRecord(const RRLogRecord& record);
2502
2511
2520
2534
2548 const std::string& env_variable_name = "ROBOTRACONTEUR_LOG_LEVEL");
2549
2557 RR_SHARED_PTR<LogRecordHandler> GetLogRecordHandler();
2558
2566 void SetLogRecordHandler(const RR_SHARED_PTR<LogRecordHandler>& handler);
2567
2568 protected:
2569 boost::shared_mutex tap_lock;
2570 RR_SHARED_PTR<MessageTap> tap;
2571
2572 public:
2578 RR_SHARED_PTR<MessageTap> GetMessageTap();
2579
2585 void SetMessageTap(const RR_SHARED_PTR<MessageTap>& message_tap);
2586
2587 protected:
2588 boost::shared_mutex node_directories_lock;
2589 RR_SHARED_PTR<NodeDirectories> node_directories;
2590
2591 public:
2600
2609
2610 protected:
2614 template <typename F>
2615 class asio_async_wait1
2616 {
2617 public:
2618 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2619
2620 void do_complete(const boost::system::error_code& err) { f_(err); }
2621
2622 protected:
2623 F f_;
2624 };
2625
2626 public:
2643 template <typename T, typename F>
2644 static bool asio_async_wait(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2645 BOOST_ASIO_MOVE_ARG(F) f)
2646 {
2647 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2648 if (!node1)
2649 return false;
2650 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2651 if (node1->is_shutdown)
2652 {
2653 l.unlock();
2654 RR_SHARED_PTR<ThreadPool> t;
2655 if (!node1->TryGetThreadPool(t))
2656 return false;
2657 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2658 }
2659
2660 RR_SHARED_PTR<asio_async_wait1<F> > f1(new asio_async_wait1<F>(RR_FORWARD(F, f)));
2661 t->async_wait(boost::bind(&asio_async_wait1<F>::do_complete, f1, boost::asio::placeholders::error));
2662
2663 node1->shutdown_listeners.connect(
2664 boost::signals2::signal<void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
2665 return true;
2666 }
2667
2685 template <typename T, typename B, typename F>
2686 static bool asio_async_read_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2687 BOOST_ASIO_MOVE_ARG(F) f)
2688 {
2689 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2690 if (!node1)
2691 return false;
2692 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2693 if (node1->is_shutdown)
2694 {
2695 l.unlock();
2696 RR_SHARED_PTR<ThreadPool> t;
2697 if (!node1->TryGetThreadPool(t))
2698 return false;
2699 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2700 }
2701
2702 t->async_read_some(b, f);
2703 return true;
2704 }
2705
2724 template <typename T, typename B, typename F>
2725 static bool asio_async_write_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2726 BOOST_ASIO_MOVE_ARG(F) f)
2727 {
2728 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2729 if (!node1)
2730 return false;
2731 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2732 if (!node1->thread_pool)
2733 return false;
2734 t->async_write_some(b, f);
2735 return true;
2736 }
2737
2756 template <typename T, typename B, typename F>
2757 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2758 BOOST_ASIO_MOVE_ARG(F) f)
2759 {
2760 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2761 if (!node1)
2762 return false;
2763 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2764 if (!node1->thread_pool)
2765 return false;
2766 t->async_connect(b, f);
2767 return true;
2768 }
2769
2790 template <typename T, typename B, typename C, typename F>
2791 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2792 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2793 {
2794 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2795 if (!node1)
2796 return false;
2797 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2798 if (!node1->thread_pool)
2799 return false;
2800 t->async_connect(b, c, f);
2801 return true;
2802 }
2803
2804#if BOOST_ASIO_VERSION < 101200
2823 template <typename T, typename B, typename F>
2824 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2825 BOOST_ASIO_MOVE_ARG(F) f)
2826 {
2827 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2828 if (!node1)
2829 return false;
2830 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2831 if (node1->is_shutdown)
2832 {
2833 l.unlock();
2834 RR_SHARED_PTR<ThreadPool> t;
2835 if (!node1->TryGetThreadPool(t))
2836 return false;
2837 typename T::iterator iter;
2838 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2839 }
2840
2841 t->async_resolve(b, f);
2842 return true;
2843 }
2844#else
2865 template <typename T, typename B, typename C, typename F>
2866 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2867 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2868 {
2869 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2870 if (!node1)
2871 return false;
2872 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2873 if (node1->is_shutdown)
2874 {
2875 l.unlock();
2876 RR_SHARED_PTR<ThreadPool> t;
2877 if (!node1->TryGetThreadPool(t))
2878 return false;
2879 typename T::results_type results;
2880 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2881 }
2882
2883 t->async_resolve(b, c, f);
2884 return true;
2885 }
2886#endif
2887
2904 template <typename T, typename F>
2905 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2906 BOOST_ASIO_MOVE_ARG(F) f)
2907 {
2908 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2909 if (!node1)
2910 return false;
2911 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2912 if (node1->is_shutdown)
2913 {
2914 l.unlock();
2915 RR_SHARED_PTR<ThreadPool> t;
2916 if (!node1->TryGetThreadPool(t))
2917 return false;
2918 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2919 }
2920
2921 t->async_handshake(f);
2922 return true;
2923 }
2924
2943 template <typename T, typename U, typename F>
2944 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const U& u,
2945 BOOST_ASIO_MOVE_ARG(F) f)
2946 {
2947 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2948 if (!node1)
2949 return false;
2950 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2951 if (node1->is_shutdown)
2952 {
2953 l.unlock();
2954 RR_SHARED_PTR<ThreadPool> t;
2955 if (!node1->TryGetThreadPool(t))
2956 return false;
2957 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2958 }
2959
2960 t->async_handshake(u, f);
2961 return true;
2962 }
2963
2980 template <typename T, typename F>
2981 static bool asio_async_shutdown(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2982 BOOST_ASIO_MOVE_ARG(F) f)
2983 {
2984 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2985 if (!node1)
2986 return false;
2987 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2988 if (node1->is_shutdown)
2989 {
2990 l.unlock();
2991 RR_SHARED_PTR<ThreadPool> t;
2992 if (!node1->TryGetThreadPool(t))
2993 return false;
2994 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2995 }
2996
2997 t->async_shutdown(f);
2998 return true;
2999 }
3000};
3001
3002#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
3004using RobotRaconteurNodePtr = RR_SHARED_PTR<RobotRaconteurNode>;
3005#endif
3006
3007} // namespace RobotRaconteur
ClientServiceListenerEventType
Enum of client listener events.
Definition RobotRaconteurConstants.h:500
RobotRaconteur_LogLevel
Log level enum.
Definition RobotRaconteurConstants.h:613
MessageErrorType
Message error type codes enum.
Definition RobotRaconteurConstants.h:396
#define RR_TIMEOUT_INFINITE
Disable timeout for asynchronous operations.
Definition RobotRaconteurConstants.h:566
boost::shared_ptr< RobotRaconteurNode > RobotRaconteurNodePtr
Convenience alias for RobotRaconteurNode shared_ptr.
Definition RobotRaconteurNode.h:3004
RobotRaconteurObjectLockFlags
The type of object lock.
Definition RobotRaconteurNode.h:78
@ RobotRaconteurObjectLockFlags_USER_LOCK
User level lock.
Definition RobotRaconteurNode.h:85
@ RobotRaconteurObjectLockFlags_CLIENT_LOCK
Client level lock.
Definition RobotRaconteurNode.h:92
Exception thrown when an invalid operation is attempted.
Definition Error.h:609
Directories on local system used by the node.
Definition NodeDirectories.h:45
Raw information used to announce and detect nodes.
Definition Discovery.h:137
NodeID UUID storage and generation.
Definition NodeID.h:58
Contains information about a node detected using discovery.
Definition Discovery.h:92
Robot Raconteur log record.
Definition Logging.h:49
Map container value type.
Definition DataTypes.h:829
Numeric primitive multidimensional array value type.
Definition DataTypes.h:1638
Base class for Robot Raconteur exceptions.
Definition Error.h:53
ScopedMonitorLock(const boost::shared_ptr< RRObject > &obj, int32_t timeout=-1)
Create a monitor lock for the specified object.
boost::shared_ptr< RobotRaconteurNode > GetNode()
Get the Node associated with the lock.
void release()
Release the monitor lock from the class.
void lock(int32_t timeout=-1)
Relock the object after calling unlock().
void SetRequestTimeout(uint32_t timeout)
Set the timeout for requests in milliseconds.
boost::shared_ptr< ThreadPool > GetThreadPool()
Get the current ThreadPool for the node.
void AddPeriodicCleanupTask(const boost::shared_ptr< IPeriodicCleanupTask > &task)
Add a periodic cleanup task.
shutdown_listener_connection AddShutdownListener(BOOST_ASIO_MOVE_ARG(Handler) h)
Adds a shutdown listener.
Definition RobotRaconteurNode.h:711
void AsyncFindNodeByName(boost::string_ref name, const std::vector< std::string > &transportschemes, boost::function< void(const boost::shared_ptr< std::vector< NodeInfo2 > > &)> handler, int32_t timeout=5000)
Asynchronously finds nodes on the network with the specified NodeName.
uint32_t GetNodeDiscoveryMaxCacheCount()
Get the maximum number of detected nodes that will be cached.
virtual boost::posix_time::ptime NowUTC()
The current time in UTC time zone.
std::vector< T > GetRandomInts(size_t count, T min, T max)
Returns a vector of random integer using the node's random number generator.
Definition RobotRaconteurNode.h:2403
std::vector< std::string > GetPulledServiceTypes(const boost::shared_ptr< RRObject > &obj)
Get the names of service types pulled by a client.
void MonitorEnter(const boost::shared_ptr< RRObject > &obj, int32_t timeout=RR_TIMEOUT_INFINITE)
Creates a monitor lock on a specified object.
boost::shared_ptr< RobotRaconteurException > DownCastException(const boost::shared_ptr< RobotRaconteurException > &exp)
Downcasts a RobotRaconteurException.
const boost::shared_ptr< RobotRaconteur::DynamicServiceFactory > GetDynamicServiceFactory()
Get the current DynamicServiceFactory. May be null.
boost::function< void(const std::exception *)> GetExceptionHandler()
Get the node's current exception handler, or null.
boost::shared_ptr< RRObject > ConnectService(boost::string_ref url, boost::string_ref username="", const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials=(boost::intrusive_ptr< RRMap< std::string, RRValue > >()), boost::function< void(const boost::shared_ptr< ClientContext > &, ClientServiceListenerEventType, const boost::shared_ptr< void > &)> listener=0, boost::string_ref objecttype="")
Create a client connection to a remote service using a URL.
void AsyncConnectService(boost::string_ref url, boost::string_ref username, const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials, boost::function< void(const boost::shared_ptr< ClientContext > &, ClientServiceListenerEventType, const boost::shared_ptr< void > &)> listener, boost::string_ref objecttype, boost::function< void(const boost::shared_ptr< RRObject > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously create a client connection to a remote service using a URL.
void UpdateDetectedNodes(const std::vector< std::string > &schemes)
Update the detected nodes cache.
uint32_t GetTransportInactivityTimeout()
Get the timeout for transport activity in milliseconds.
std::vector< NodeInfo2 > FindNodeByID(const RobotRaconteur::NodeID &id, const std::vector< std::string > &transportschemes)
Finds nodes on the network with a specified NodeID.
void AsyncFindServiceByType(boost::string_ref servicetype, const std::vector< std::string > &transportschemes, boost::function< void(const boost::shared_ptr< std::vector< ServiceInfo2 > > &)> handler, int32_t timeout=5000)
Asynchronously use discovery to find available services by service type.
uint32_t GetEndpointInactivityTimeout()
Get the timeout for endpoint activity in milliseconds.
NodeDirectories GetNodeDirectories()
Get the current node directories.
void AsyncReleaseObjectLock(const boost::shared_ptr< RRObject > &obj, boost::function< void(const boost::shared_ptr< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously release an exclusive access lock previously locked with RequestObjectLock() or AsyncRe...
node_updated_listener_connection AddNodeServicesDetectedListener(BOOST_ASIO_MOVE_ARG(Handler) h)
Add a handler to be called when detected services are updated.
Definition RobotRaconteurNode.h:1339
std::string ReleaseObjectLock(const boost::shared_ptr< RRObject > &obj)
Release an exclusive access lock previously locked with RequestObjectLock() or AsyncRequestObjectLock...
void SetDynamicServiceFactory(const boost::shared_ptr< RobotRaconteur::DynamicServiceFactory > &f)
Set the DynamicServicefactory.
void DownCastAndThrowException(RobotRaconteurException &exp)
Downcasts a RobotRaconteurException and throws it.
bool IsServiceTypeRegistered(boost::string_ref servicetype)
Check if a service type has been registered.
boost::signals2::connection shutdown_listener_connection
signals2 connection type for AddShutdownListener()
Definition RobotRaconteurNode.h:696
boost::shared_ptr< RRObject > ConnectService(const std::vector< std::string > &urls, boost::string_ref username="", const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials=(boost::intrusive_ptr< RRMap< std::string, RRValue > >()), boost::function< void(const boost::shared_ptr< ClientContext > &, ClientServiceListenerEventType, const boost::shared_ptr< void > &)> listener=0, boost::string_ref objecttype="")
Same as ConnectService(), but accepts a vector of candidate URLs.
void CheckConnection(uint32_t endpoint)
Check that the TransportConnection associated with an endpoint is connected.
void AsyncDisconnectService(const boost::shared_ptr< RRObject > &obj, boost::function< void()> handler)
Asynchronously disconnects a client connection to a service.
std::string RequestObjectLock(const boost::shared_ptr< RRObject > &obj, RobotRaconteurObjectLockFlags flags)
Request an exclusive access lock to a service object.
bool TryGetNodeName(std::string &node_name)
Tries getting the current NodeName.
RobotRaconteur_LogLevel SetLogLevelFromString(boost::string_ref level)
Set the log level for the node from a string.
boost::shared_ptr< RRObject > FindObjRefTyped(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref objecttype)
Returns an objref as a specific type.
void SetExceptionHandler(boost::function< void(const std::exception *)> handler)
Set an exception handler function.
void AsyncFindObjectType(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::function< void(const boost::shared_ptr< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously returns the type of a service object.
int32_t GetThreadPoolCount()
Get the number of threads for the node ThreadPool.
virtual void Shutdown()
Shuts down the node. Called automatically by ClientNodeSetup and ServerNodeSetup.
void AsyncFindObjRefTyped(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref objecttype, boost::function< void(const boost::shared_ptr< RRObject > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously returns an objref as a specific type.
virtual boost::shared_ptr< Rate > CreateRate(double frequency)
Create a Rate object.
std::vector< std::string > GetRegisteredServiceTypes()
Return names of registered service types.
uint32_t RegisterTransport(const boost::shared_ptr< Transport > &transport)
Register a transport for use by the node.
std::string FindObjectType(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref index)
Returns the type of a service object.
RobotRaconteur_LogLevel SetLogLevelFromEnvVariable(const std::string &env_variable_name="ROBOTRACONTEUR_LOG_LEVEL")
Set the log level for the node from specified environmental variable.
boost::shared_ptr< LogRecordHandler > GetLogRecordHandler()
Get the currently configured log record handler.
std::map< std::string, boost::intrusive_ptr< RRValue > > GetServiceAttributes(const boost::shared_ptr< RRObject > &obj)
Get the service attributes of a client connection.
RobotRaconteurNode()
Construct a new Robot Raconteur Node object.
void AsyncFindObjRefTyped(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref index, boost::string_ref objecttype, boost::function< void(const boost::shared_ptr< RRObject > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously returns an objref as a specific type.
boost::shared_ptr< ServiceSubscription > SubscribeServiceByType(const std::vector< std::string > &service_types, const boost::shared_ptr< ServiceSubscriptionFilter > &filter=boost::shared_ptr< ServiceSubscriptionFilter >())
Subscribe to listen for available services and automatically connect.
void AsyncUpdateDetectedNodes(const std::vector< std::string > &schemes, boost::function< void()> handler, int32_t timeout=5000)
Asynchronously update the detected nodes cache.
RobotRaconteur::NodeID NodeID()
Get the current NodeID.
boost::shared_ptr< RRObject > FindObjRefTyped(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref index, boost::string_ref objecttype)
Returns an indexed objref as a specified type.
void ReleaseThreadPool()
Shuts down and releases the node thread pool Do not call ReleaseThreadPool unless you really know wha...
boost::signals2::connection node_updated_listener_connection
The boost::signals2 connection type for AddNodeServicesDetectedListener.
Definition RobotRaconteurNode.h:1322
boost::signals2::connection node_lost_listener_connection
The boost::signals2 connection type for AddNodeDetectionLostListener.
Definition RobotRaconteurNode.h:1354
virtual std::string GetObjectType(const boost::shared_ptr< RRObject > &obj)
Get the Robot Raconteur type of a connected service object obj must be returned by ConnectService(),...
void LogRecord(const RRLogRecord &record)
Log a record to the node. Use the macros specified in Logging.h instead of this function directly.
virtual void Sleep(const boost::posix_time::time_duration &duration)
Sleeps for a specified duration.
boost::shared_ptr< MessageTap > GetMessageTap()
Get the active message tap.
void HandleException(const std::exception *exp)
Handle exceptino by passing the current exception to the handler function.
std::string NodeName()
Get the current NodeName.
void CloseService(boost::string_ref sname)
Closes a previously registered service.
void AsyncConnectService(const std::vector< std::string > &url, boost::string_ref username, const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials, boost::function< void(const boost::shared_ptr< ClientContext > &, ClientServiceListenerEventType, const boost::shared_ptr< void > &)> listener, boost::string_ref objecttype, boost::function< void(const boost::shared_ptr< RRObject > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Same as AsyncConnectService(), but accepts a vector of candidate URLs.
void SetNodeDirectories(const NodeDirectories &dir)
Set the node directories.
std::vector< std::string > GetRegisteredServiceNames()
Get the names of registered services.
bool IsEndpointLargeTransferAuthorized(uint32_t endpoint)
Check if the endpoint is authorized for large message transfer.
void SetThreadPool(const boost::shared_ptr< ThreadPool > &pool)
Sets the ThreadPool for the node.
std::vector< NodeDiscoveryInfo > GetDetectedNodes()
Get the nodes currently detected by Transports.
virtual TimeSpec NodeSyncTimeSpec()
The sync time of the node as a TimeSpec.
void SetThreadPoolFactory(const boost::shared_ptr< ThreadPoolFactory > &factory)
Set the ThreadPoolFactory for the node.
virtual boost::posix_time::ptime NodeSyncTimeUTC()
The sync time of the node.
RobotRaconteur_LogLevel GetLogLevel()
Get the current log level for the node.
void LogMessage(RobotRaconteur_LogLevel level, const std::string &message)
Log a simple message using the current node.
void SetLogLevel(RobotRaconteur_LogLevel level)
Set the log level for the node.
void SetTransportInactivityTimeout(uint32_t timeout)
Set the timeout for transport activity in milliseconds.
void Init()
Initialize the node. Called automatically for s() and sp().
T GetRandomInt(T min, T max)
Returns a random integer using the node's random number generator.
Definition RobotRaconteurNode.h:2385
bool TryGetNodeID(RobotRaconteur::NodeID &id)
Tries getting the current NodeID.
void UnregisterServiceType(boost::string_ref type)
Unregister a previously registered service type.
void SetLogRecordHandler(const boost::shared_ptr< LogRecordHandler > &handler)
Set the handler for log records.
std::vector< NodeInfo2 > FindNodeByName(boost::string_ref name, const std::vector< std::string > &transportschemes)
Finds nodes on the network with a specified NodeName.
virtual boost::shared_ptr< Timer > CreateTimer(const boost::posix_time::time_duration &period, boost::function< void(const TimerEvent &)> handler, bool oneshot=false)
Create a Timer object.
boost::shared_ptr< ServerContext > RegisterService(boost::string_ref name, boost::string_ref servicetype, const boost::shared_ptr< RRObject > &obj, const boost::shared_ptr< ServiceSecurityPolicy > &securitypolicy=boost::shared_ptr< ServiceSecurityPolicy >())
Registers a service for clients to connect.
void SetEndpointInactivityTimeout(uint32_t timeout)
Set the timeout for endpoint activity in milliseconds.
boost::shared_ptr< ServiceFactory > GetPulledServiceType(const boost::shared_ptr< RRObject > &obj, boost::string_ref type)
Get a ServiceFactory created from a service type pulled by a client.
boost::shared_ptr< ThreadPoolFactory > GetThreadPoolFactory()
Get the current ThreadPoolFactory for the node.
static boost::shared_ptr< RobotRaconteurNode > sp()
Singleton shared_ptr accessor.
std::vector< ServiceInfo2 > FindServiceByType(boost::string_ref servicetype, const std::vector< std::string > &transportschemes)
Use discovery to find available services by service type.
void SetNodeID(const RobotRaconteur::NodeID &id)
Set the NodeID.
NodeInfo2 GetDetectedNodeCacheInfo(const RobotRaconteur::NodeID &nodeid)
Get cached node discovery information.
std::string GetServiceNodeName(const boost::shared_ptr< RRObject > &obj)
Get the service NodeName of the remote node from a client connection.
static std::string SelectRemoteNodeURL(const std::vector< std::string > &urls)
Select the "best" URL from a std::vector of candidates.
virtual TimeSpec NowTimeSpec()
The current node time as a TimeSpec.
void AsyncRequestObjectLock(const boost::shared_ptr< RRObject > &obj, RobotRaconteurObjectLockFlags flags, boost::function< void(const boost::shared_ptr< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously request an exclusive access lock to a service object.
node_lost_listener_connection AddNodeDetectionLostListener(BOOST_ASIO_MOVE_ARG(Handler) h)
Add a handler to be called when a node is no longer detected.
Definition RobotRaconteurNode.h:1369
static bool TryHandleException(RR_WEAK_PTR< RobotRaconteurNode > node, const std::exception *exp)
Try to pass an exception to the exception handler.
RobotRaconteur::NodeID GetServiceNodeID(const boost::shared_ptr< RRObject > &obj)
Get the service NodeID of the remote node from a client connection.
bool TryGetThreadPool(boost::shared_ptr< ThreadPool > &pool)
Tries to get the ThreadPool, returns false if the ThreadPool is not available.
void SetThreadPoolCount(int32_t count)
Set the number of threads for the node ThreadPool.
uint32_t GetMemoryMaxTransferSize()
Get the maximum chunk size for memory transfers in bytes.
uint32_t GetRequestTimeout()
Get the timeout for requests in milliseconds.
boost::shared_ptr< ServiceSubscription > SubscribeService(const std::vector< std::string > &url, boost::string_ref username="", const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials=(boost::intrusive_ptr< RRMap< std::string, RRValue > >()), boost::string_ref objecttype="")
Subscribe to a service using one or more URL. Used to create robust connections to services.
void DisconnectService(const boost::shared_ptr< RRObject > &obj)
Disconnects a client connection to a service.
void SetMessageTap(const boost::shared_ptr< MessageTap > &message_tap)
Set the a message tap to record log records and messages.
boost::shared_ptr< ServiceSubscription > SubscribeService(const std::string &url, boost::string_ref username="", const boost::intrusive_ptr< RRMap< std::string, RRValue > > &credentials=(boost::intrusive_ptr< RRMap< std::string, RRValue > >()), boost::string_ref objecttype="")
Subscribe to a service using a URL. Used to create robust connections to services.
std::string GetServiceName(const boost::shared_ptr< RRObject > &obj)
Get the name of a service from a client connection.
boost::shared_ptr< ServiceInfo2Subscription > SubscribeServiceInfo2(const std::vector< std::string > &service_types, const boost::shared_ptr< ServiceSubscriptionFilter > &filter=boost::shared_ptr< ServiceSubscriptionFilter >())
Subscribe to listen for available services information.
void MonitorExit(const boost::shared_ptr< RRObject > &obj)
Releases a monitor lock.
bool TryGetDetectedNodeCacheInfo(const RobotRaconteur::NodeID &nodeid, NodeInfo2 &nodeinfo2)
Try get cached node discovery information.
static bool TryPostToThreadPool(RR_WEAK_PTR< RobotRaconteurNode > node, BOOST_ASIO_MOVE_ARG(HandlerType) h, bool shutdown_op=false)
Tries to post a handler function to be called by a thread in the thread pool. Returns immediately.
Definition RobotRaconteurNode.h:2078
void SetNodeName(boost::string_ref name)
Set the NodeName.
boost::shared_ptr< ServiceFactory > GetServiceType(boost::string_ref type)
Returns a previously registered service type.
virtual boost::posix_time::ptime NowNodeTime()
The current node time.
void SetMemoryMaxTransferSize(uint32_t size)
Set the maximum chunk size for memory transfers in bytes.
void AsyncFindNodeByID(const RobotRaconteur::NodeID &id, const std::vector< std::string > &transportschemes, boost::function< void(const boost::shared_ptr< std::vector< NodeInfo2 > > &)> handler, int32_t timeout=5000)
Asynchronously finds nodes on the network with the specified NodeID.
void AsyncFindObjectType(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref, boost::string_ref index, boost::function< void(const boost::shared_ptr< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously returns the type of a service object.
std::string FindObjectType(const boost::shared_ptr< RRObject > &obj, boost::string_ref objref)
Returns the type of a service object.
std::string GetObjectServicePath(const boost::shared_ptr< RRObject > &obj)
Get the service path of a client object.
static RobotRaconteurNode * s()
Singleton accessor.
boost::shared_ptr< ServerContext > RegisterService(const boost::shared_ptr< ServerContext > &c)
Registers a service using a previously instantiated ServerContext.
static RR_WEAK_PTR< RobotRaconteurNode > weak_sp()
Singleton weak_ptr accessor.
bool CompareLogLevel(RobotRaconteur_LogLevel log_level)
Test if the specified log level would be accepted.
boost::shared_ptr< ServerContext > GetService(boost::string_ref name)
Gets a ServerContext for a service by name.
void RemovePeriodicCleanupTask(const boost::shared_ptr< IPeriodicCleanupTask > &task)
Remove a task previously registered with AddPeriodicCleanupTask().
std::string GetRobotRaconteurVersion()
Get the current RobotRaconteurVersion as a string.
std::string GetRandomString(size_t count)
Generates a random string with the specified character count using the node's random number generator...
virtual boost::shared_ptr< AutoResetEvent > CreateAutoResetEvent()
Create an AutoResetEvent object.
void RegisterServiceType(const boost::shared_ptr< ServiceFactory > &factory)
Register a service type.
void SetNodeDiscoveryMaxCacheCount(uint32_t count)
Set maximum number of detected nodes that will be cached.
Represents. a point in time. Used by wire members to timestamp packets.
Definition DataTypes.h:2719
Timer event structure.
Definition Timer.h:55