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
707 template <typename Handler>
708 shutdown_listener_connection AddShutdownListener(BOOST_ASIO_MOVE_ARG(Handler) h)
709 {
710 return shutdown_listeners.connect(h);
711 }
712
719 uint32_t RegisterTransport(const RR_SHARED_PTR<Transport>& transport);
720
735 void AsyncSendMessage(const RR_INTRUSIVE_PTR<Message>& m,
736 const boost::function<void(const RR_SHARED_PTR<RobotRaconteurException>&)>& handler);
737
753 void SendMessage(const RR_INTRUSIVE_PTR<Message>& m);
754
766 void MessageReceived(const RR_INTRUSIVE_PTR<Message>& m);
767
768 protected:
777 void TransportConnectionClosed(uint32_t endpoint);
778
779 private:
780 uint32_t RequestTimeout;
781 boost::mutex RequestTimeout_lock;
782
783 uint32_t TransportInactivityTimeout;
784 boost::mutex TransportInactivityTimeout_lock;
785
786 uint32_t EndpointInactivityTimeout;
787 boost::mutex EndpointInactivityTimeout_lock;
788
789 uint32_t MemoryMaxTransferSize;
790 boost::mutex MemoryMaxTransferSize_lock;
791
792 public:
804
813 void SetRequestTimeout(uint32_t timeout);
814
826
835 void SetTransportInactivityTimeout(uint32_t timeout);
836
848
857 void SetEndpointInactivityTimeout(uint32_t timeout);
858
870
880 void SetMemoryMaxTransferSize(uint32_t size);
881
882 protected:
884 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Endpoint> > endpoints;
886 std::map<uint32_t, boost::posix_time::ptime> recent_endpoints;
887
889 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Transport> > transports;
891 boost::shared_mutex transports_lock;
892
894 RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> dynamic_factory;
896 boost::mutex dynamic_factory_lock;
897
898 public:
906 const RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> GetDynamicServiceFactory();
907
917 void SetDynamicServiceFactory(const RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory>& f);
918
934 RR_INTRUSIVE_PTR<Message> GenerateErrorReturnMessage(const RR_INTRUSIVE_PTR<Message>& m, MessageErrorType err,
935 boost::string_ref errname, boost::string_ref errdesc);
936
957 RR_SHARED_PTR<ServerContext> RegisterService(
958 boost::string_ref name, boost::string_ref servicetype, const RR_SHARED_PTR<RRObject>& obj,
959 const RR_SHARED_PTR<ServiceSecurityPolicy>& securitypolicy = RR_SHARED_PTR<ServiceSecurityPolicy>());
960
970 RR_SHARED_PTR<ServerContext> RegisterService(const RR_SHARED_PTR<ServerContext>& c);
971
980 void CloseService(boost::string_ref sname);
981
987 std::vector<std::string> GetRegisteredServiceNames();
988
996 RR_SHARED_PTR<ServerContext> GetService(boost::string_ref name);
997
1011 RR_INTRUSIVE_PTR<Message> SpecialRequest(const RR_INTRUSIVE_PTR<Message>& m, uint32_t transportid,
1012 const RR_SHARED_PTR<ITransportConnection>& tc);
1013
1041 RR_SHARED_PTR<RRObject> ConnectService(
1042 boost::string_ref url, boost::string_ref username = "",
1043 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1044 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1045 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1046 const RR_SHARED_PTR<void>&)>
1047 listener = 0,
1048 boost::string_ref objecttype = "");
1049
1069 boost::string_ref url, boost::string_ref username,
1070 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials,
1071 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1072 const RR_SHARED_PTR<void>&)>
1073 listener,
1074 boost::string_ref objecttype,
1075 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1076 int32_t timeout = RR_TIMEOUT_INFINITE);
1077
1094 RR_SHARED_PTR<RRObject> ConnectService(
1095 const std::vector<std::string>& urls, boost::string_ref username = "",
1096 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1097 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1098 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1099 const RR_SHARED_PTR<void>&)>
1100 listener = 0,
1101 boost::string_ref objecttype = "");
1102
1119 const std::vector<std::string>& url, boost::string_ref username,
1120 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials,
1121 boost::function<void(const RR_SHARED_PTR<ClientContext>&, ClientServiceListenerEventType,
1122 const RR_SHARED_PTR<void>&)>
1123 listener,
1124 boost::string_ref objecttype,
1125 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1126 int32_t timeout = RR_TIMEOUT_INFINITE);
1127
1139 void DisconnectService(const RR_SHARED_PTR<RRObject>& obj);
1140
1149 void AsyncDisconnectService(const RR_SHARED_PTR<RRObject>& obj, boost::function<void()> handler);
1150
1160 std::map<std::string, RR_INTRUSIVE_PTR<RRValue> > GetServiceAttributes(const RR_SHARED_PTR<RRObject>& obj);
1161
1170 RobotRaconteur::NodeID GetServiceNodeID(const RR_SHARED_PTR<RRObject>& obj);
1171
1180 std::string GetServiceNodeName(const RR_SHARED_PTR<RRObject>& obj);
1181
1190 std::string GetServiceName(const RR_SHARED_PTR<RRObject>& obj);
1191
1198 std::string GetObjectServicePath(const RR_SHARED_PTR<RRObject>& obj);
1199
1207 virtual std::string GetObjectType(const RR_SHARED_PTR<RRObject>& obj);
1208
1219 uint32_t RegisterEndpoint(const RR_SHARED_PTR<Endpoint>& e);
1220
1230 void DeleteEndpoint(const RR_SHARED_PTR<Endpoint>& e);
1231
1239 void CheckConnection(uint32_t endpoint);
1240
1241 private:
1242 uint32_t transport_count;
1243
1244 boost::mutex endpoint_lock;
1245
1246 static RobotRaconteurNode m_s;
1247 static RR_SHARED_PTR<RobotRaconteurNode> m_sp;
1248 static RR_WEAK_PTR<RobotRaconteurNode> m_weak_sp;
1249
1250 RobotRaconteur::NodeID m_NodeID;
1251 std::string m_NodeName;
1252
1253 bool NodeID_set;
1254 bool NodeName_set;
1255
1256 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServiceFactory> > service_factories;
1257 boost::shared_mutex service_factories_lock;
1258 boost::mutex id_lock;
1259
1260 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServerContext> > services;
1261 boost::shared_mutex services_lock;
1262
1263 RR_SHARED_PTR<detail::Discovery> m_Discovery;
1264 boost::signals2::signal<void(const NodeDiscoveryInfo&, const std::vector<ServiceInfo2>&)>
1265 discovery_updated_listeners;
1266
1267 boost::signals2::signal<void(const NodeDiscoveryInfo&)> discovery_lost_listeners;
1268
1269 RR_WEAK_PTR<RobotRaconteurNode> weak_this;
1270
1271 public:
1285 std::vector<NodeDiscoveryInfo> GetDetectedNodes();
1286
1298
1310
1315 typedef boost::signals2::connection node_updated_listener_connection;
1316
1331 template <typename Handler>
1333 {
1334 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1335 if (is_shutdown)
1336 {
1337 throw InvalidOperationException("Node has been shut down");
1338 }
1339
1340 return discovery_updated_listeners.connect(h);
1341 }
1342
1347 typedef boost::signals2::connection node_lost_listener_connection;
1348
1361 template <typename Handler>
1363 {
1364 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1365 if (is_shutdown)
1366 {
1367 throw InvalidOperationException("Node has been shut down");
1368 }
1369 return discovery_lost_listeners.connect(h);
1370 }
1371
1383 void NodeAnnouncePacketReceived(boost::string_ref packet);
1384
1395 void NodeDetected(const NodeDiscoveryInfo& info);
1396
1408 void UpdateDetectedNodes(const std::vector<std::string>& schemes);
1409
1420 void AsyncUpdateDetectedNodes(const std::vector<std::string>& schemes, boost::function<void()> handler,
1421 int32_t timeout = 5000);
1422
1432
1440 void SetNodeDiscoveryMaxCacheCount(uint32_t count);
1441
1453 RR_SHARED_PTR<ServiceInfo2Subscription> SubscribeServiceInfo2(
1454 const std::vector<std::string>& service_types,
1455 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1456
1467 RR_SHARED_PTR<ServiceSubscription> SubscribeServiceByType(
1468 const std::vector<std::string>& service_types,
1469 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1470
1483 RR_SHARED_PTR<ServiceSubscription> SubscribeService(
1484 const std::vector<std::string>& url, boost::string_ref username = "",
1485 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1486 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1487 boost::string_ref objecttype = "");
1488
1501 RR_SHARED_PTR<ServiceSubscription> SubscribeService(
1502 const std::string& url, boost::string_ref username = "",
1503 const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1504 (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1505 boost::string_ref objecttype = "");
1506
1507 protected:
1515 void CleanDiscoveredNodes();
1516
1525 void FireNodeDetected(const RR_SHARED_PTR<NodeDiscoveryInfo>& node,
1526 const RR_SHARED_PTR<std::vector<ServiceInfo2> >& services);
1527
1535 void FireNodeLost(const RR_SHARED_PTR<NodeDiscoveryInfo>& node);
1536
1537 public:
1565 static std::string SelectRemoteNodeURL(const std::vector<std::string>& urls);
1566
1581 std::vector<ServiceInfo2> FindServiceByType(boost::string_ref servicetype,
1582 const std::vector<std::string>& transportschemes);
1583
1594 void AsyncFindServiceByType(boost::string_ref servicetype, const std::vector<std::string>& transportschemes,
1595 boost::function<void(const RR_SHARED_PTR<std::vector<ServiceInfo2> >&)> handler,
1596 int32_t timeout = 5000);
1597
1610 std::vector<NodeInfo2> FindNodeByID(const RobotRaconteur::NodeID& id,
1611 const std::vector<std::string>& transportschemes);
1612
1623 void AsyncFindNodeByID(const RobotRaconteur::NodeID& id, const std::vector<std::string>& transportschemes,
1624 boost::function<void(const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1625 int32_t timeout = 5000);
1626
1639 std::vector<NodeInfo2> FindNodeByName(boost::string_ref name, const std::vector<std::string>& transportschemes);
1640
1651 void AsyncFindNodeByName(boost::string_ref name, const std::vector<std::string>& transportschemes,
1652 boost::function<void(const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1653 int32_t timeout = 5000);
1654
1669 std::string RequestObjectLock(const RR_SHARED_PTR<RRObject>& obj, RobotRaconteurObjectLockFlags flags);
1670
1682 const RR_SHARED_PTR<RRObject>& obj, RobotRaconteurObjectLockFlags flags,
1683 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1684 int32_t timeout = RR_TIMEOUT_INFINITE);
1685
1698 std::string ReleaseObjectLock(const RR_SHARED_PTR<RRObject>& obj);
1699
1711 const RR_SHARED_PTR<RRObject>& obj,
1712 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1713 int32_t timeout = RR_TIMEOUT_INFINITE);
1714
1733 void MonitorEnter(const RR_SHARED_PTR<RRObject>& obj, int32_t timeout = RR_TIMEOUT_INFINITE);
1734
1745 void MonitorExit(const RR_SHARED_PTR<RRObject>& obj);
1746
1752 class ROBOTRACONTEUR_CORE_API ScopedMonitorLock
1753 {
1754 bool locked;
1755 RR_SHARED_PTR<RRObject> obj;
1756 RR_WEAK_PTR<RobotRaconteurNode> node;
1757
1758 public:
1764 RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1765
1776 ScopedMonitorLock(const RR_SHARED_PTR<RRObject>& obj, int32_t timeout = -1);
1777
1784 void lock(int32_t timeout = -1);
1785
1793 void unlock();
1794
1802 void release();
1803
1805 };
1806
1807 private:
1808 RR_SHARED_PTR<Timer> PeriodicCleanupTask_timer;
1809 boost::shared_mutex PeriodicCleanupTask_timer_lock;
1810
1811 static void StartPeriodicCleanupTask(const RR_SHARED_PTR<RobotRaconteurNode>& node);
1812
1813 void PeriodicCleanupTask(const TimerEvent& err);
1814 bool PeriodicCleanupTask_timerstarted;
1815
1816 std::list<RR_SHARED_PTR<IPeriodicCleanupTask> > cleanupobjs;
1817
1818 boost::mutex cleanupobjs_lock;
1819
1820 boost::mutex cleanup_thread_lock;
1821
1822 public:
1831 void AddPeriodicCleanupTask(const RR_SHARED_PTR<IPeriodicCleanupTask>& task);
1832
1838 void RemovePeriodicCleanupTask(const RR_SHARED_PTR<IPeriodicCleanupTask>& task);
1839
1858
1859 RR_SHARED_PTR<RRObject> FindObjRefTyped(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1860 boost::string_ref objecttype);
1861
1875 RR_SHARED_PTR<RRObject> FindObjRefTyped(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1876 boost::string_ref index, boost::string_ref objecttype);
1877
1890 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref objecttype,
1891 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1892 int32_t timeout = RR_TIMEOUT_INFINITE);
1893
1907 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1908 boost::string_ref objecttype,
1909 boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1910 int32_t timeout = RR_TIMEOUT_INFINITE);
1911
1923 std::string FindObjectType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref);
1924
1937 std::string FindObjectType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index);
1938
1950 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1951 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1952 int32_t timeout = RR_TIMEOUT_INFINITE);
1953
1966 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1967 boost::function<void(const RR_SHARED_PTR<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1968 int32_t timeout = RR_TIMEOUT_INFINITE);
1969
1970 private:
1971 RR_SHARED_PTR<ThreadPool> thread_pool;
1972 boost::shared_mutex thread_pool_lock;
1973 RR_SHARED_PTR<ThreadPoolFactory> thread_pool_factory;
1974 boost::mutex thread_pool_factory_lock;
1975
1976 public:
1986 RR_SHARED_PTR<ThreadPool> GetThreadPool();
1987
2000 bool TryGetThreadPool(RR_SHARED_PTR<ThreadPool>& pool);
2001
2011 void SetThreadPool(const RR_SHARED_PTR<ThreadPool>& pool);
2012
2023 RR_SHARED_PTR<ThreadPoolFactory> GetThreadPoolFactory();
2024
2033 void SetThreadPoolFactory(const RR_SHARED_PTR<ThreadPoolFactory>& factory);
2034
2041
2052 void SetThreadPoolCount(int32_t count);
2053
2070 template <typename HandlerType>
2071 static bool TryPostToThreadPool(RR_WEAK_PTR<RobotRaconteurNode> node, BOOST_ASIO_MOVE_ARG(HandlerType) h,
2072 bool shutdown_op = false)
2073 {
2074 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2075 if (!node1)
2076 return false;
2077 {
2078 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2079 if (!shutdown_op && node1->is_shutdown)
2080 return false;
2081 }
2082 RR_SHARED_PTR<ThreadPool> t;
2083 if (!node1->TryGetThreadPool(t))
2084 return false;
2085 return t->TryPost(RR_FORWARD(HandlerType, h));
2086 }
2087
2094
2095 protected:
2107 bool InitThreadPool(int32_t thread_count);
2108
2109 public:
2123 std::vector<std::string> GetPulledServiceTypes(const RR_SHARED_PTR<RRObject>& obj);
2124
2139 RR_SHARED_PTR<ServiceFactory> GetPulledServiceType(const RR_SHARED_PTR<RRObject>& obj, boost::string_ref type);
2140
2152 void SetExceptionHandler(boost::function<void(const std::exception*)> handler);
2153
2162 boost::function<void(const std::exception*)> GetExceptionHandler();
2163
2170 void HandleException(const std::exception* exp);
2171
2184 static bool TryHandleException(RR_WEAK_PTR<RobotRaconteurNode> node, const std::exception* exp);
2185
2186 protected:
2188 boost::function<void(const std::exception*)> exception_handler;
2190 boost::mutex exception_handler_lock;
2191
2193 boost::mutex random_generator_lock;
2195 RR_SHARED_PTR<boost::random::random_device> random_generator;
2196
2197 public:
2207 virtual boost::posix_time::ptime NowUTC();
2208
2217
2230 virtual boost::posix_time::ptime NowNodeTime();
2231
2246 virtual boost::posix_time::ptime NodeSyncTimeUTC();
2247
2256
2257 protected:
2259 RR_WEAK_PTR<ITransportTimeProvider> time_provider;
2261 boost::shared_mutex time_provider_lock;
2262
2264 boost::posix_time::ptime node_sync_time;
2265 TimeSpec node_sync_timespec;
2266 boost::chrono::steady_clock::time_point node_internal_start_time;
2267
2268 public:
2281 virtual RR_SHARED_PTR<Timer> CreateTimer(const boost::posix_time::time_duration& period,
2282 boost::function<void(const TimerEvent&)> handler, bool oneshot = false);
2283
2294 virtual RR_SHARED_PTR<Rate> CreateRate(double frequency);
2295
2306 virtual void Sleep(const boost::posix_time::time_duration& duration);
2307
2316 virtual RR_SHARED_PTR<AutoResetEvent> CreateAutoResetEvent();
2317
2328
2338 RR_SHARED_PTR<RobotRaconteurException> DownCastException(const RR_SHARED_PTR<RobotRaconteurException>& exp);
2339
2351 bool IsEndpointLargeTransferAuthorized(uint32_t endpoint);
2352
2361
2371 template <typename T>
2372 T GetRandomInt(T min, T max)
2373 {
2374 boost::mutex::scoped_lock lock(random_generator_lock);
2375 boost::random::uniform_int_distribution<T> d(min, max);
2376 return d(*random_generator);
2377 }
2378
2389 template <typename T>
2390 std::vector<T> GetRandomInts(size_t count, T min, T max)
2391 {
2392 std::vector<T> o;
2393 o.resize(count);
2394 boost::mutex::scoped_lock lock(random_generator_lock);
2395 for (size_t i = 0; i < count; i++)
2396 {
2397 boost::random::uniform_int_distribution<T> d(min, max);
2398 o[i] = d(*random_generator);
2399 }
2400 return o;
2401 }
2402
2412 std::string GetRandomString(size_t count);
2413
2414 protected:
2416 std::string service_state_nonce;
2418 boost::mutex service_state_nonce_lock;
2419
2420 public:
2435 std::string GetServiceStateNonce();
2436
2444 void UpdateServiceStateNonce();
2445
2446 protected:
2447 RR_SHARED_PTR<LogRecordHandler> log_handler;
2448 boost::shared_mutex log_handler_mutex;
2449 RobotRaconteur_LogLevel log_level;
2450 boost::shared_mutex log_level_mutex;
2451
2452 public:
2461
2474 void LogMessage(RobotRaconteur_LogLevel level, const std::string& message);
2475
2488 void LogRecord(const RRLogRecord& record);
2489
2498
2507
2519
2533 const std::string& env_variable_name = "ROBOTRACONTEUR_LOG_LEVEL");
2534
2542 RR_SHARED_PTR<LogRecordHandler> GetLogRecordHandler();
2543
2551 void SetLogRecordHandler(const RR_SHARED_PTR<LogRecordHandler>& handler);
2552
2553 protected:
2554 boost::shared_mutex tap_lock;
2555 RR_SHARED_PTR<MessageTap> tap;
2556
2557 public:
2563 RR_SHARED_PTR<MessageTap> GetMessageTap();
2564
2570 void SetMessageTap(const RR_SHARED_PTR<MessageTap>& message_tap);
2571
2572 protected:
2573 boost::shared_mutex node_directories_lock;
2574 RR_SHARED_PTR<NodeDirectories> node_directories;
2575
2576 public:
2585
2594
2595 protected:
2599 template <typename F>
2600 class asio_async_wait1
2601 {
2602 public:
2603 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2604
2605 void do_complete(const boost::system::error_code& err) { f_(err); }
2606
2607 protected:
2608 F f_;
2609 };
2610
2611 public:
2628 template <typename T, typename F>
2629 static bool asio_async_wait(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2630 BOOST_ASIO_MOVE_ARG(F) f)
2631 {
2632 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2633 if (!node1)
2634 return false;
2635 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2636 if (node1->is_shutdown)
2637 {
2638 l.unlock();
2639 RR_SHARED_PTR<ThreadPool> t;
2640 if (!node1->TryGetThreadPool(t))
2641 return false;
2642 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2643 }
2644
2645 RR_SHARED_PTR<asio_async_wait1<F> > f1(new asio_async_wait1<F>(RR_FORWARD(F, f)));
2646 t->async_wait(boost::bind(&asio_async_wait1<F>::do_complete, f1, boost::asio::placeholders::error));
2647
2648 node1->shutdown_listeners.connect(
2649 boost::signals2::signal<void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
2650 return true;
2651 }
2652
2670 template <typename T, typename B, typename F>
2671 static bool asio_async_read_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2672 BOOST_ASIO_MOVE_ARG(F) f)
2673 {
2674 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2675 if (!node1)
2676 return false;
2677 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2678 if (node1->is_shutdown)
2679 {
2680 l.unlock();
2681 RR_SHARED_PTR<ThreadPool> t;
2682 if (!node1->TryGetThreadPool(t))
2683 return false;
2684 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2685 }
2686
2687 t->async_read_some(b, f);
2688 return true;
2689 }
2690
2709 template <typename T, typename B, typename F>
2710 static bool asio_async_write_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2711 BOOST_ASIO_MOVE_ARG(F) f)
2712 {
2713 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2714 if (!node1)
2715 return false;
2716 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2717 if (!node1->thread_pool)
2718 return false;
2719 t->async_write_some(b, f);
2720 return true;
2721 }
2722
2741 template <typename T, typename B, typename F>
2742 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2743 BOOST_ASIO_MOVE_ARG(F) f)
2744 {
2745 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2746 if (!node1)
2747 return false;
2748 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2749 if (!node1->thread_pool)
2750 return false;
2751 t->async_connect(b, f);
2752 return true;
2753 }
2754
2775 template <typename T, typename B, typename C, typename F>
2776 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2777 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2778 {
2779 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2780 if (!node1)
2781 return false;
2782 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2783 if (!node1->thread_pool)
2784 return false;
2785 t->async_connect(b, c, f);
2786 return true;
2787 }
2788
2789#if BOOST_ASIO_VERSION < 101200
2808 template <typename T, typename B, typename F>
2809 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2810 BOOST_ASIO_MOVE_ARG(F) f)
2811 {
2812 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2813 if (!node1)
2814 return false;
2815 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2816 if (node1->is_shutdown)
2817 {
2818 l.unlock();
2819 RR_SHARED_PTR<ThreadPool> t;
2820 if (!node1->TryGetThreadPool(t))
2821 return false;
2822 typename T::iterator iter;
2823 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2824 }
2825
2826 t->async_resolve(b, f);
2827 return true;
2828 }
2829#else
2850 template <typename T, typename B, typename C, typename F>
2851 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2852 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2853 {
2854 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2855 if (!node1)
2856 return false;
2857 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2858 if (node1->is_shutdown)
2859 {
2860 l.unlock();
2861 RR_SHARED_PTR<ThreadPool> t;
2862 if (!node1->TryGetThreadPool(t))
2863 return false;
2864 typename T::results_type results;
2865 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2866 }
2867
2868 t->async_resolve(b, c, f);
2869 return true;
2870 }
2871#endif
2872
2889 template <typename T, typename F>
2890 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2891 BOOST_ASIO_MOVE_ARG(F) f)
2892 {
2893 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2894 if (!node1)
2895 return false;
2896 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2897 if (node1->is_shutdown)
2898 {
2899 l.unlock();
2900 RR_SHARED_PTR<ThreadPool> t;
2901 if (!node1->TryGetThreadPool(t))
2902 return false;
2903 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2904 }
2905
2906 t->async_handshake(f);
2907 return true;
2908 }
2909
2928 template <typename T, typename U, typename F>
2929 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const U& u,
2930 BOOST_ASIO_MOVE_ARG(F) f)
2931 {
2932 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2933 if (!node1)
2934 return false;
2935 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2936 if (node1->is_shutdown)
2937 {
2938 l.unlock();
2939 RR_SHARED_PTR<ThreadPool> t;
2940 if (!node1->TryGetThreadPool(t))
2941 return false;
2942 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2943 }
2944
2945 t->async_handshake(u, f);
2946 return true;
2947 }
2948
2965 template <typename T, typename F>
2966 static bool asio_async_shutdown(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2967 BOOST_ASIO_MOVE_ARG(F) f)
2968 {
2969 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2970 if (!node1)
2971 return false;
2972 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2973 if (node1->is_shutdown)
2974 {
2975 l.unlock();
2976 RR_SHARED_PTR<ThreadPool> t;
2977 if (!node1->TryGetThreadPool(t))
2978 return false;
2979 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2980 }
2981
2982 t->async_shutdown(f);
2983 return true;
2984 }
2985};
2986
2987#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
2989using RobotRaconteurNodePtr = RR_SHARED_PTR<RobotRaconteurNode>;
2990#endif
2991
2992} // namespace RobotRaconteur
ClientServiceListenerEventType
Enum of client listener events.
Definition RobotRaconteurConstants.h:500
RobotRaconteur_LogLevel
Log level enum.
Definition RobotRaconteurConstants.h:608
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:2989
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:796
Numeric primitive multidimensional array value type.
Definition DataTypes.h:1602
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:708
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:2390
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 availabe 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 excluse access lock previously locked with RequestObjectLock() or AsyncRequ...
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:1332
std::string ReleaseObjectLock(const boost::shared_ptr< RRObject > &obj)
Release an excluse 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:1315
boost::signals2::connection node_lost_listener_connection
The boost::signals2 connection type for AddNodeDetectionLostListener.
Definition RobotRaconteurNode.h:1347
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:2372
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:1362
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:2071
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:2668
Timer event structure.
Definition Timer.h:55