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:
2287 virtual RR_SHARED_PTR<Timer> CreateTimer(const boost::posix_time::time_duration& period,
2288 boost::function<void(const TimerEvent&)> handler, bool oneshot = false);
2289
2300 virtual RR_SHARED_PTR<Rate> CreateRate(double frequency);
2301
2312 virtual void Sleep(const boost::posix_time::time_duration& duration);
2313
2322 virtual RR_SHARED_PTR<AutoResetEvent> CreateAutoResetEvent();
2323
2334
2344 RR_SHARED_PTR<RobotRaconteurException> DownCastException(const RR_SHARED_PTR<RobotRaconteurException>& exp);
2345
2357 bool IsEndpointLargeTransferAuthorized(uint32_t endpoint);
2358
2367
2377 template <typename T>
2378 T GetRandomInt(T min, T max)
2379 {
2380 boost::mutex::scoped_lock lock(random_generator_lock);
2381 boost::random::uniform_int_distribution<T> d(min, max);
2382 return d(*random_generator);
2383 }
2384
2395 template <typename T>
2396 std::vector<T> GetRandomInts(size_t count, T min, T max)
2397 {
2398 std::vector<T> o;
2399 o.resize(count);
2400 boost::mutex::scoped_lock lock(random_generator_lock);
2401 for (size_t i = 0; i < count; i++)
2402 {
2403 boost::random::uniform_int_distribution<T> d(min, max);
2404 o[i] = d(*random_generator);
2405 }
2406 return o;
2407 }
2408
2418 std::string GetRandomString(size_t count);
2419
2420 protected:
2422 std::string service_state_nonce;
2424 boost::mutex service_state_nonce_lock;
2425
2426 public:
2441 std::string GetServiceStateNonce();
2442
2450 void UpdateServiceStateNonce();
2451
2452 protected:
2453 RR_SHARED_PTR<LogRecordHandler> log_handler;
2454 boost::shared_mutex log_handler_mutex;
2455 RobotRaconteur_LogLevel log_level;
2456 boost::shared_mutex log_level_mutex;
2457
2458 public:
2467
2480 void LogMessage(RobotRaconteur_LogLevel level, const std::string& message);
2481
2494 void LogRecord(const RRLogRecord& record);
2495
2504
2513
2527
2541 const std::string& env_variable_name = "ROBOTRACONTEUR_LOG_LEVEL");
2542
2550 RR_SHARED_PTR<LogRecordHandler> GetLogRecordHandler();
2551
2559 void SetLogRecordHandler(const RR_SHARED_PTR<LogRecordHandler>& handler);
2560
2561 protected:
2562 boost::shared_mutex tap_lock;
2563 RR_SHARED_PTR<MessageTap> tap;
2564
2565 public:
2571 RR_SHARED_PTR<MessageTap> GetMessageTap();
2572
2578 void SetMessageTap(const RR_SHARED_PTR<MessageTap>& message_tap);
2579
2580 protected:
2581 boost::shared_mutex node_directories_lock;
2582 RR_SHARED_PTR<NodeDirectories> node_directories;
2583
2584 public:
2593
2602
2603 protected:
2607 template <typename F>
2608 class asio_async_wait1
2609 {
2610 public:
2611 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2612
2613 void do_complete(const boost::system::error_code& err) { f_(err); }
2614
2615 protected:
2616 F f_;
2617 };
2618
2619 public:
2636 template <typename T, typename F>
2637 static bool asio_async_wait(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2638 BOOST_ASIO_MOVE_ARG(F) f)
2639 {
2640 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2641 if (!node1)
2642 return false;
2643 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2644 if (node1->is_shutdown)
2645 {
2646 l.unlock();
2647 RR_SHARED_PTR<ThreadPool> t;
2648 if (!node1->TryGetThreadPool(t))
2649 return false;
2650 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2651 }
2652
2653 RR_SHARED_PTR<asio_async_wait1<F> > f1(new asio_async_wait1<F>(RR_FORWARD(F, f)));
2654 t->async_wait(boost::bind(&asio_async_wait1<F>::do_complete, f1, boost::asio::placeholders::error));
2655
2656 node1->shutdown_listeners.connect(
2657 boost::signals2::signal<void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
2658 return true;
2659 }
2660
2678 template <typename T, typename B, typename F>
2679 static bool asio_async_read_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2680 BOOST_ASIO_MOVE_ARG(F) f)
2681 {
2682 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2683 if (!node1)
2684 return false;
2685 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2686 if (node1->is_shutdown)
2687 {
2688 l.unlock();
2689 RR_SHARED_PTR<ThreadPool> t;
2690 if (!node1->TryGetThreadPool(t))
2691 return false;
2692 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2693 }
2694
2695 t->async_read_some(b, f);
2696 return true;
2697 }
2698
2717 template <typename T, typename B, typename F>
2718 static bool asio_async_write_some(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, B& b,
2719 BOOST_ASIO_MOVE_ARG(F) f)
2720 {
2721 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2722 if (!node1)
2723 return false;
2724 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2725 if (!node1->thread_pool)
2726 return false;
2727 t->async_write_some(b, f);
2728 return true;
2729 }
2730
2749 template <typename T, typename B, typename F>
2750 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2751 BOOST_ASIO_MOVE_ARG(F) f)
2752 {
2753 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2754 if (!node1)
2755 return false;
2756 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2757 if (!node1->thread_pool)
2758 return false;
2759 t->async_connect(b, f);
2760 return true;
2761 }
2762
2783 template <typename T, typename B, typename C, typename F>
2784 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2785 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2786 {
2787 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2788 if (!node1)
2789 return false;
2790 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2791 if (!node1->thread_pool)
2792 return false;
2793 t->async_connect(b, c, f);
2794 return true;
2795 }
2796
2797#if BOOST_ASIO_VERSION < 101200
2816 template <typename T, typename B, typename F>
2817 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2818 BOOST_ASIO_MOVE_ARG(F) f)
2819 {
2820 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2821 if (!node1)
2822 return false;
2823 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2824 if (node1->is_shutdown)
2825 {
2826 l.unlock();
2827 RR_SHARED_PTR<ThreadPool> t;
2828 if (!node1->TryGetThreadPool(t))
2829 return false;
2830 typename T::iterator iter;
2831 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2832 }
2833
2834 t->async_resolve(b, f);
2835 return true;
2836 }
2837#else
2858 template <typename T, typename B, typename C, typename F>
2859 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const B& b,
2860 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2861 {
2862 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2863 if (!node1)
2864 return false;
2865 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2866 if (node1->is_shutdown)
2867 {
2868 l.unlock();
2869 RR_SHARED_PTR<ThreadPool> t;
2870 if (!node1->TryGetThreadPool(t))
2871 return false;
2872 typename T::results_type results;
2873 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2874 }
2875
2876 t->async_resolve(b, c, f);
2877 return true;
2878 }
2879#endif
2880
2897 template <typename T, typename F>
2898 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2899 BOOST_ASIO_MOVE_ARG(F) f)
2900 {
2901 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2902 if (!node1)
2903 return false;
2904 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2905 if (node1->is_shutdown)
2906 {
2907 l.unlock();
2908 RR_SHARED_PTR<ThreadPool> t;
2909 if (!node1->TryGetThreadPool(t))
2910 return false;
2911 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2912 }
2913
2914 t->async_handshake(f);
2915 return true;
2916 }
2917
2936 template <typename T, typename U, typename F>
2937 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t, const U& u,
2938 BOOST_ASIO_MOVE_ARG(F) f)
2939 {
2940 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2941 if (!node1)
2942 return false;
2943 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2944 if (node1->is_shutdown)
2945 {
2946 l.unlock();
2947 RR_SHARED_PTR<ThreadPool> t;
2948 if (!node1->TryGetThreadPool(t))
2949 return false;
2950 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2951 }
2952
2953 t->async_handshake(u, f);
2954 return true;
2955 }
2956
2973 template <typename T, typename F>
2974 static bool asio_async_shutdown(RR_WEAK_PTR<RobotRaconteurNode> node, const RR_SHARED_PTR<T>& t,
2975 BOOST_ASIO_MOVE_ARG(F) f)
2976 {
2977 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2978 if (!node1)
2979 return false;
2980 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2981 if (node1->is_shutdown)
2982 {
2983 l.unlock();
2984 RR_SHARED_PTR<ThreadPool> t;
2985 if (!node1->TryGetThreadPool(t))
2986 return false;
2987 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2988 }
2989
2990 t->async_shutdown(f);
2991 return true;
2992 }
2993};
2994
2995#ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
2997using RobotRaconteurNodePtr = RR_SHARED_PTR<RobotRaconteurNode>;
2998#endif
2999
3000} // 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:2997
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:826
Numeric primitive multidimensional array value type.
Definition DataTypes.h:1635
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:2396
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:1332
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: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:2378
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:2713
Timer event structure.
Definition Timer.h:55