131 public RR_ENABLE_SHARED_FROM_THIS<RobotRaconteurNode>
135 boost::mutex shutdown_lock;
136 boost::signals2::signal<void()> shutdown_listeners;
140 bool instance_is_init;
141 static boost::mutex init_lock;
144 friend class detail::Discovery;
145 friend class Transport;
146 friend class ServerContext;
147 friend class ServiceSubscriptionManager;
193 static RR_SHARED_PTR<RobotRaconteurNode>
sp();
203 static RR_WEAK_PTR<RobotRaconteurNode>
weak_sp();
333 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackStructure(
const RR_INTRUSIVE_PTR<RRStructure>& structure);
350 RR_INTRUSIVE_PTR<RRStructure> UnpackStructure(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& structure);
369 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackPodArray(
const RR_INTRUSIVE_PTR<RRPodBaseArray>& pod_array);
386 RR_INTRUSIVE_PTR<RRPodBaseArray> UnpackPodArray(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& pod_array);
403 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackPodMultiDimArray(
404 const RR_INTRUSIVE_PTR<RRPodBaseMultiDimArray>& pod_multiarray);
421 RR_INTRUSIVE_PTR<RRPodBaseMultiDimArray> UnpackPodMultiDimArray(
422 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& pod_multiarray);
441 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackNamedArray(
442 const RR_INTRUSIVE_PTR<RRNamedBaseArray>& namedarray);
459 RR_INTRUSIVE_PTR<RRNamedBaseArray> UnpackNamedArray(
460 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& namedarray);
477 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackNamedMultiDimArray(
478 const RR_INTRUSIVE_PTR<RRNamedBaseMultiDimArray>& named_multiarray);
495 RR_INTRUSIVE_PTR<RRNamedBaseMultiDimArray> UnpackNamedMultiDimArray(
496 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& named_multiarray);
507 template <
typename T>
508 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackMultiDimArray(
511 return detail::packing::PackMultiDimArray<T>(arr);
526 template <
typename T>
527 RR_INTRUSIVE_PTR<RRMultiDimArray<T> > UnpackMultiDimArray(
528 const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& ar)
530 return detail::packing::UnpackMultiDimArray<T>(ar);
544 RR_INTRUSIVE_PTR<MessageElementData> PackVarType(
const RR_INTRUSIVE_PTR<RRValue>& vardata);
559 RR_INTRUSIVE_PTR<RRValue> UnpackVarType(
const RR_INTRUSIVE_PTR<MessageElement>& mvardata);
574 template <
typename K,
typename T,
typename U>
575 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackMapType(
const U& map)
577 return detail::packing::PackMapType<K, T, U>(map,
this);
592 template <
typename K,
typename T>
593 RR_INTRUSIVE_PTR<RRMap<K, T> > UnpackMapType(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& map)
595 return detail::packing::UnpackMapType<K, T>(map,
this);
610 template <
typename T,
typename U>
611 RR_INTRUSIVE_PTR<MessageElementNestedElementList> PackListType(U& list)
613 return detail::packing::PackListType<T, U>(list,
this);
627 template <
typename T>
628 RR_INTRUSIVE_PTR<RRList<T> > UnpackListType(
const RR_INTRUSIVE_PTR<MessageElementNestedElementList>& list)
630 return detail::packing::UnpackListType<T>(list,
this);
647 template <
typename T,
typename U>
648 RR_INTRUSIVE_PTR<MessageElementData> PackAnyType(
const RR_INTRUSIVE_PTR<U>& data)
650 return detail::packing::PackAnyType<T, U>(data,
this);
667 template <
typename T>
668 T UnpackAnyType(
const RR_INTRUSIVE_PTR<MessageElement>& mdata)
670 return detail::packing::UnpackAnyType<T>(mdata,
this);
710 template <
typename Handler>
714 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
717 return shutdown_listeners.connect(h);
742 void AsyncSendMessage(
const RR_INTRUSIVE_PTR<Message>& m,
743 const boost::function<
void(
const RR_SHARED_PTR<RobotRaconteurException>&)>& handler);
760 void SendMessage(
const RR_INTRUSIVE_PTR<Message>& m);
773 void MessageReceived(
const RR_INTRUSIVE_PTR<Message>& m);
784 void TransportConnectionClosed(uint32_t endpoint);
787 uint32_t RequestTimeout;
788 boost::mutex RequestTimeout_lock;
790 uint32_t TransportInactivityTimeout;
791 boost::mutex TransportInactivityTimeout_lock;
793 uint32_t EndpointInactivityTimeout;
794 boost::mutex EndpointInactivityTimeout_lock;
796 uint32_t MemoryMaxTransferSize;
797 boost::mutex MemoryMaxTransferSize_lock;
891 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Endpoint> > endpoints;
893 std::map<uint32_t, boost::posix_time::ptime> recent_endpoints;
896 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Transport> > transports;
898 boost::shared_mutex transports_lock;
901 RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> dynamic_factory;
903 boost::mutex dynamic_factory_lock;
941 RR_INTRUSIVE_PTR<Message> GenerateErrorReturnMessage(
const RR_INTRUSIVE_PTR<Message>& m,
MessageErrorType err,
942 boost::string_ref errname, boost::string_ref errdesc);
965 boost::string_ref name, boost::string_ref servicetype,
const RR_SHARED_PTR<RRObject>& obj,
966 const RR_SHARED_PTR<ServiceSecurityPolicy>& securitypolicy = RR_SHARED_PTR<ServiceSecurityPolicy>());
1018 RR_INTRUSIVE_PTR<Message> SpecialRequest(
const RR_INTRUSIVE_PTR<Message>& m, uint32_t transportid,
1019 const RR_SHARED_PTR<ITransportConnection>& tc);
1049 boost::string_ref url, boost::string_ref username =
"",
1053 const RR_SHARED_PTR<void>&)>
1055 boost::string_ref objecttype =
"");
1076 boost::string_ref url, boost::string_ref username,
1079 const RR_SHARED_PTR<void>&)>
1081 boost::string_ref objecttype,
1082 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1102 const std::vector<std::string>& urls, boost::string_ref username =
"",
1106 const RR_SHARED_PTR<void>&)>
1108 boost::string_ref objecttype =
"");
1126 const std::vector<std::string>& url, boost::string_ref username,
1129 const RR_SHARED_PTR<void>&)>
1131 boost::string_ref objecttype,
1132 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1226 uint32_t RegisterEndpoint(
const RR_SHARED_PTR<Endpoint>& e);
1237 void DeleteEndpoint(
const RR_SHARED_PTR<Endpoint>& e);
1249 uint32_t transport_count;
1251 boost::mutex endpoint_lock;
1254 static RR_SHARED_PTR<RobotRaconteurNode> m_sp;
1255 static RR_WEAK_PTR<RobotRaconteurNode> m_weak_sp;
1258 std::string m_NodeName;
1263 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServiceFactory> > service_factories;
1264 boost::shared_mutex service_factories_lock;
1265 boost::mutex id_lock;
1267 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServerContext> > services;
1268 boost::shared_mutex services_lock;
1270 RR_SHARED_PTR<detail::Discovery> m_Discovery;
1271 boost::signals2::signal<void(
const NodeDiscoveryInfo&,
const std::vector<ServiceInfo2>&)>
1272 discovery_updated_listeners;
1274 boost::signals2::signal<void(
const NodeDiscoveryInfo&)> discovery_lost_listeners;
1276 RR_WEAK_PTR<RobotRaconteurNode> weak_this;
1338 template <
typename Handler>
1341 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1347 return discovery_updated_listeners.connect(h);
1368 template <
typename Handler>
1371 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1376 return discovery_lost_listeners.connect(h);
1390 void NodeAnnouncePacketReceived(boost::string_ref packet);
1428 int32_t timeout = 5000);
1461 const std::vector<std::string>& service_types,
1462 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1475 const std::vector<std::string>& service_types,
1476 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1491 const std::vector<std::string>& url, boost::string_ref username =
"",
1494 boost::string_ref objecttype =
"");
1509 const std::string& url, boost::string_ref username =
"",
1512 boost::string_ref objecttype =
"");
1522 void CleanDiscoveredNodes();
1532 void FireNodeDetected(
const RR_SHARED_PTR<NodeDiscoveryInfo>& node,
1533 const RR_SHARED_PTR<std::vector<ServiceInfo2> >& services);
1542 void FireNodeLost(
const RR_SHARED_PTR<NodeDiscoveryInfo>& node);
1589 const std::vector<std::string>& transportschemes);
1602 boost::function<
void(
const RR_SHARED_PTR<std::vector<ServiceInfo2> >&)> handler,
1603 int32_t timeout = 5000);
1618 const std::vector<std::string>& transportschemes);
1631 boost::function<
void(
const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1632 int32_t timeout = 5000);
1646 std::vector<NodeInfo2>
FindNodeByName(boost::string_ref name,
const std::vector<std::string>& transportschemes);
1659 boost::function<
void(
const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1660 int32_t timeout = 5000);
1690 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1718 const RR_SHARED_PTR<RRObject>& obj,
1719 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1762 RR_SHARED_PTR<RRObject> obj;
1763 RR_WEAK_PTR<RobotRaconteurNode> node;
1815 RR_SHARED_PTR<Timer> PeriodicCleanupTask_timer;
1816 boost::shared_mutex PeriodicCleanupTask_timer_lock;
1818 static void StartPeriodicCleanupTask(
const RR_SHARED_PTR<RobotRaconteurNode>& node);
1820 void PeriodicCleanupTask(
const TimerEvent& err);
1821 bool PeriodicCleanupTask_timerstarted;
1823 std::list<RR_SHARED_PTR<IPeriodicCleanupTask> > cleanupobjs;
1825 boost::mutex cleanupobjs_lock;
1827 boost::mutex cleanup_thread_lock;
1866 RR_SHARED_PTR<RRObject>
FindObjRefTyped(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1867 boost::string_ref objecttype);
1882 RR_SHARED_PTR<RRObject>
FindObjRefTyped(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1883 boost::string_ref index, boost::string_ref objecttype);
1897 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref objecttype,
1898 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1914 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1915 boost::string_ref objecttype,
1916 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1930 std::string
FindObjectType(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref);
1944 std::string
FindObjectType(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index);
1957 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1958 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1973 const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index,
1974 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1978 RR_SHARED_PTR<ThreadPool> thread_pool;
1979 boost::shared_mutex thread_pool_lock;
1980 RR_SHARED_PTR<ThreadPoolFactory> thread_pool_factory;
1981 boost::mutex thread_pool_factory_lock;
2077 template <
typename HandlerType>
2079 bool shutdown_op =
false)
2081 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2085 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2086 if (!shutdown_op && node1->is_shutdown)
2089 RR_SHARED_PTR<ThreadPool> t;
2090 if (!node1->TryGetThreadPool(t))
2092 return t->TryPost(RR_FORWARD(HandlerType, h));
2114 bool InitThreadPool(int32_t thread_count);
2195 boost::function<void(
const std::exception*)> exception_handler;
2197 boost::mutex exception_handler_lock;
2200 boost::mutex random_generator_lock;
2202 RR_SHARED_PTR<boost::random::random_device> random_generator;
2266 RR_WEAK_PTR<ITransportTimeProvider> time_provider;
2268 boost::shared_mutex time_provider_lock;
2271 boost::posix_time::ptime node_sync_time;
2273 boost::chrono::steady_clock::time_point node_internal_start_time;
2294 virtual RR_SHARED_PTR<Timer>
CreateTimer(
const boost::posix_time::time_duration& period,
2295 boost::function<
void(
const TimerEvent&)> handler,
bool oneshot =
false);
2319 virtual void Sleep(
const boost::posix_time::time_duration& duration);
2351 RR_SHARED_PTR<RobotRaconteurException>
DownCastException(
const RR_SHARED_PTR<RobotRaconteurException>& exp);
2384 template <
typename T>
2387 boost::mutex::scoped_lock lock(random_generator_lock);
2388 boost::random::uniform_int_distribution<T> d(min, max);
2389 return d(*random_generator);
2402 template <
typename T>
2407 boost::mutex::scoped_lock lock(random_generator_lock);
2408 for (
size_t i = 0; i < count; i++)
2410 boost::random::uniform_int_distribution<T> d(min, max);
2411 o[i] = d(*random_generator);
2429 std::string service_state_nonce;
2431 boost::mutex service_state_nonce_lock;
2448 std::string GetServiceStateNonce();
2457 void UpdateServiceStateNonce();
2460 RR_SHARED_PTR<LogRecordHandler> log_handler;
2461 boost::shared_mutex log_handler_mutex;
2463 boost::shared_mutex log_level_mutex;
2548 const std::string& env_variable_name =
"ROBOTRACONTEUR_LOG_LEVEL");
2569 boost::shared_mutex tap_lock;
2570 RR_SHARED_PTR<MessageTap> tap;
2588 boost::shared_mutex node_directories_lock;
2589 RR_SHARED_PTR<NodeDirectories> node_directories;
2614 template <
typename F>
2615 class asio_async_wait1
2618 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2620 void do_complete(
const boost::system::error_code& err) { f_(err); }
2643 template <
typename T,
typename F>
2644 static bool asio_async_wait(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
2645 BOOST_ASIO_MOVE_ARG(F) f)
2647 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2650 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2651 if (node1->is_shutdown)
2654 RR_SHARED_PTR<ThreadPool> t;
2655 if (!node1->TryGetThreadPool(t))
2657 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2660 RR_SHARED_PTR<asio_async_wait1<F> > f1(
new asio_async_wait1<F>(RR_FORWARD(F, f)));
2661 t->async_wait(boost::bind(&asio_async_wait1<F>::do_complete, f1, boost::asio::placeholders::error));
2663 node1->shutdown_listeners.connect(
2664 boost::signals2::signal<
void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
2685 template <
typename T,
typename B,
typename F>
2686 static bool asio_async_read_some(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t, B& b,
2687 BOOST_ASIO_MOVE_ARG(F) f)
2689 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2692 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2693 if (node1->is_shutdown)
2696 RR_SHARED_PTR<ThreadPool> t;
2697 if (!node1->TryGetThreadPool(t))
2699 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2702 t->async_read_some(b, f);
2724 template <
typename T,
typename B,
typename F>
2725 static bool asio_async_write_some(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t, B& b,
2726 BOOST_ASIO_MOVE_ARG(F) f)
2728 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2731 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2732 if (!node1->thread_pool)
2734 t->async_write_some(b, f);
2756 template <
typename T,
typename B,
typename F>
2757 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
const B& b,
2758 BOOST_ASIO_MOVE_ARG(F) f)
2760 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2763 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2764 if (!node1->thread_pool)
2766 t->async_connect(b, f);
2790 template <
typename T,
typename B,
typename C,
typename F>
2791 static bool asio_async_connect(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
const B& b,
2792 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2794 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2797 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2798 if (!node1->thread_pool)
2800 t->async_connect(b, c, f);
2804#if BOOST_ASIO_VERSION < 101200
2823 template <
typename T,
typename B,
typename F>
2824 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
const B& b,
2825 BOOST_ASIO_MOVE_ARG(F) f)
2827 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2830 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2831 if (node1->is_shutdown)
2834 RR_SHARED_PTR<ThreadPool> t;
2835 if (!node1->TryGetThreadPool(t))
2837 typename T::iterator iter;
2838 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2841 t->async_resolve(b, f);
2865 template <
typename T,
typename B,
typename C,
typename F>
2866 static bool asio_async_resolve(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
const B& b,
2867 const C& c, BOOST_ASIO_MOVE_ARG(F) f)
2869 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2872 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2873 if (node1->is_shutdown)
2876 RR_SHARED_PTR<ThreadPool> t;
2877 if (!node1->TryGetThreadPool(t))
2879 typename T::results_type results;
2880 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2883 t->async_resolve(b, c, f);
2904 template <
typename T,
typename F>
2905 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
2906 BOOST_ASIO_MOVE_ARG(F) f)
2908 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2911 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2912 if (node1->is_shutdown)
2915 RR_SHARED_PTR<ThreadPool> t;
2916 if (!node1->TryGetThreadPool(t))
2918 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2921 t->async_handshake(f);
2943 template <
typename T,
typename U,
typename F>
2944 static bool asio_async_handshake(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
const U& u,
2945 BOOST_ASIO_MOVE_ARG(F) f)
2947 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2950 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2951 if (node1->is_shutdown)
2954 RR_SHARED_PTR<ThreadPool> t;
2955 if (!node1->TryGetThreadPool(t))
2957 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2960 t->async_handshake(u, f);
2980 template <
typename T,
typename F>
2981 static bool asio_async_shutdown(RR_WEAK_PTR<RobotRaconteurNode> node,
const RR_SHARED_PTR<T>& t,
2982 BOOST_ASIO_MOVE_ARG(F) f)
2984 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2987 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2988 if (node1->is_shutdown)
2991 RR_SHARED_PTR<ThreadPool> t;
2992 if (!node1->TryGetThreadPool(t))
2994 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2997 t->async_shutdown(f);