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);
707 template <
typename Handler>
710 return shutdown_listeners.connect(h);
735 void AsyncSendMessage(
const RR_INTRUSIVE_PTR<Message>& m,
736 const boost::function<
void(
const RR_SHARED_PTR<RobotRaconteurException>&)>& handler);
753 void SendMessage(
const RR_INTRUSIVE_PTR<Message>& m);
766 void MessageReceived(
const RR_INTRUSIVE_PTR<Message>& m);
777 void TransportConnectionClosed(uint32_t endpoint);
780 uint32_t RequestTimeout;
781 boost::mutex RequestTimeout_lock;
783 uint32_t TransportInactivityTimeout;
784 boost::mutex TransportInactivityTimeout_lock;
786 uint32_t EndpointInactivityTimeout;
787 boost::mutex EndpointInactivityTimeout_lock;
789 uint32_t MemoryMaxTransferSize;
790 boost::mutex MemoryMaxTransferSize_lock;
884 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Endpoint> > endpoints;
886 std::map<uint32_t, boost::posix_time::ptime> recent_endpoints;
889 RR_UNORDERED_MAP<uint32_t, RR_SHARED_PTR<Transport> > transports;
891 boost::shared_mutex transports_lock;
894 RR_SHARED_PTR<RobotRaconteur::DynamicServiceFactory> dynamic_factory;
896 boost::mutex dynamic_factory_lock;
934 RR_INTRUSIVE_PTR<Message> GenerateErrorReturnMessage(
const RR_INTRUSIVE_PTR<Message>& m,
MessageErrorType err,
935 boost::string_ref errname, boost::string_ref errdesc);
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>());
996 RR_SHARED_PTR<ServerContext>
GetService(boost::string_ref name);
1011 RR_INTRUSIVE_PTR<Message> SpecialRequest(
const RR_INTRUSIVE_PTR<Message>& m, uint32_t transportid,
1012 const RR_SHARED_PTR<ITransportConnection>& tc);
1042 boost::string_ref url, boost::string_ref username =
"",
1046 const RR_SHARED_PTR<void>&)>
1048 boost::string_ref objecttype =
"");
1069 boost::string_ref url, boost::string_ref username,
1072 const RR_SHARED_PTR<void>&)>
1074 boost::string_ref objecttype,
1075 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1095 const std::vector<std::string>& urls, boost::string_ref username =
"",
1099 const RR_SHARED_PTR<void>&)>
1101 boost::string_ref objecttype =
"");
1119 const std::vector<std::string>& url, boost::string_ref username,
1122 const RR_SHARED_PTR<void>&)>
1124 boost::string_ref objecttype,
1125 boost::function<
void(
const RR_SHARED_PTR<RRObject>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1219 uint32_t RegisterEndpoint(
const RR_SHARED_PTR<Endpoint>& e);
1230 void DeleteEndpoint(
const RR_SHARED_PTR<Endpoint>& e);
1242 uint32_t transport_count;
1244 boost::mutex endpoint_lock;
1247 static RR_SHARED_PTR<RobotRaconteurNode> m_sp;
1248 static RR_WEAK_PTR<RobotRaconteurNode> m_weak_sp;
1251 std::string m_NodeName;
1256 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServiceFactory> > service_factories;
1257 boost::shared_mutex service_factories_lock;
1258 boost::mutex id_lock;
1260 RR_UNORDERED_MAP<std::string, RR_SHARED_PTR<ServerContext> > services;
1261 boost::shared_mutex services_lock;
1263 RR_SHARED_PTR<detail::Discovery> m_Discovery;
1264 boost::signals2::signal<void(
const NodeDiscoveryInfo&,
const std::vector<ServiceInfo2>&)>
1265 discovery_updated_listeners;
1267 boost::signals2::signal<void(
const NodeDiscoveryInfo&)> discovery_lost_listeners;
1269 RR_WEAK_PTR<RobotRaconteurNode> weak_this;
1331 template <
typename Handler>
1334 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1340 return discovery_updated_listeners.connect(h);
1361 template <
typename Handler>
1364 boost::shared_lock<boost::shared_mutex> l(thread_pool_lock);
1369 return discovery_lost_listeners.connect(h);
1383 void NodeAnnouncePacketReceived(boost::string_ref packet);
1421 int32_t timeout = 5000);
1454 const std::vector<std::string>& service_types,
1455 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1468 const std::vector<std::string>& service_types,
1469 const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
1484 const std::vector<std::string>& url, boost::string_ref username =
"",
1487 boost::string_ref objecttype =
"");
1502 const std::string& url, boost::string_ref username =
"",
1505 boost::string_ref objecttype =
"");
1515 void CleanDiscoveredNodes();
1525 void FireNodeDetected(
const RR_SHARED_PTR<NodeDiscoveryInfo>& node,
1526 const RR_SHARED_PTR<std::vector<ServiceInfo2> >& services);
1535 void FireNodeLost(
const RR_SHARED_PTR<NodeDiscoveryInfo>& node);
1582 const std::vector<std::string>& transportschemes);
1595 boost::function<
void(
const RR_SHARED_PTR<std::vector<ServiceInfo2> >&)> handler,
1596 int32_t timeout = 5000);
1611 const std::vector<std::string>& transportschemes);
1624 boost::function<
void(
const RR_SHARED_PTR<std::vector<NodeInfo2> >&)> handler,
1625 int32_t timeout = 5000);
1639 std::vector<NodeInfo2>
FindNodeByName(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);
1683 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1711 const RR_SHARED_PTR<RRObject>& obj,
1712 boost::function<
void(
const RR_SHARED_PTR<std::string>&,
const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1755 RR_SHARED_PTR<RRObject> obj;
1756 RR_WEAK_PTR<RobotRaconteurNode> node;
1808 RR_SHARED_PTR<Timer> PeriodicCleanupTask_timer;
1809 boost::shared_mutex PeriodicCleanupTask_timer_lock;
1811 static void StartPeriodicCleanupTask(
const RR_SHARED_PTR<RobotRaconteurNode>& node);
1813 void PeriodicCleanupTask(
const TimerEvent& err);
1814 bool PeriodicCleanupTask_timerstarted;
1816 std::list<RR_SHARED_PTR<IPeriodicCleanupTask> > cleanupobjs;
1818 boost::mutex cleanupobjs_lock;
1820 boost::mutex cleanup_thread_lock;
1859 RR_SHARED_PTR<RRObject>
FindObjRefTyped(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref,
1860 boost::string_ref objecttype);
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);
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,
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,
1923 std::string
FindObjectType(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref);
1937 std::string
FindObjectType(
const RR_SHARED_PTR<RRObject>& obj, boost::string_ref objref, boost::string_ref index);
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,
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,
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;
2070 template <
typename HandlerType>
2072 bool shutdown_op =
false)
2074 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2078 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2079 if (!shutdown_op && node1->is_shutdown)
2082 RR_SHARED_PTR<ThreadPool> t;
2083 if (!node1->TryGetThreadPool(t))
2085 return t->TryPost(RR_FORWARD(HandlerType, h));
2107 bool InitThreadPool(int32_t thread_count);
2188 boost::function<void(
const std::exception*)> exception_handler;
2190 boost::mutex exception_handler_lock;
2193 boost::mutex random_generator_lock;
2195 RR_SHARED_PTR<boost::random::random_device> random_generator;
2259 RR_WEAK_PTR<ITransportTimeProvider> time_provider;
2261 boost::shared_mutex time_provider_lock;
2264 boost::posix_time::ptime node_sync_time;
2266 boost::chrono::steady_clock::time_point node_internal_start_time;
2287 virtual RR_SHARED_PTR<Timer>
CreateTimer(
const boost::posix_time::time_duration& period,
2288 boost::function<
void(
const TimerEvent&)> handler,
bool oneshot =
false);
2312 virtual void Sleep(
const boost::posix_time::time_duration& duration);
2344 RR_SHARED_PTR<RobotRaconteurException>
DownCastException(
const RR_SHARED_PTR<RobotRaconteurException>& exp);
2377 template <
typename T>
2380 boost::mutex::scoped_lock lock(random_generator_lock);
2381 boost::random::uniform_int_distribution<T> d(min, max);
2382 return d(*random_generator);
2395 template <
typename T>
2400 boost::mutex::scoped_lock lock(random_generator_lock);
2401 for (
size_t i = 0; i < count; i++)
2403 boost::random::uniform_int_distribution<T> d(min, max);
2404 o[i] = d(*random_generator);
2422 std::string service_state_nonce;
2424 boost::mutex service_state_nonce_lock;
2441 std::string GetServiceStateNonce();
2450 void UpdateServiceStateNonce();
2453 RR_SHARED_PTR<LogRecordHandler> log_handler;
2454 boost::shared_mutex log_handler_mutex;
2456 boost::shared_mutex log_level_mutex;
2541 const std::string& env_variable_name =
"ROBOTRACONTEUR_LOG_LEVEL");
2562 boost::shared_mutex tap_lock;
2563 RR_SHARED_PTR<MessageTap> tap;
2581 boost::shared_mutex node_directories_lock;
2582 RR_SHARED_PTR<NodeDirectories> node_directories;
2607 template <
typename F>
2608 class asio_async_wait1
2611 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2613 void do_complete(
const boost::system::error_code& err) { f_(err); }
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)
2640 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2643 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2644 if (node1->is_shutdown)
2647 RR_SHARED_PTR<ThreadPool> t;
2648 if (!node1->TryGetThreadPool(t))
2650 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
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));
2656 node1->shutdown_listeners.connect(
2657 boost::signals2::signal<
void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
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)
2682 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2685 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2686 if (node1->is_shutdown)
2689 RR_SHARED_PTR<ThreadPool> t;
2690 if (!node1->TryGetThreadPool(t))
2692 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2695 t->async_read_some(b, f);
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)
2721 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2724 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2725 if (!node1->thread_pool)
2727 t->async_write_some(b, f);
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)
2753 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2756 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2757 if (!node1->thread_pool)
2759 t->async_connect(b, f);
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)
2787 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2790 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2791 if (!node1->thread_pool)
2793 t->async_connect(b, c, f);
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)
2820 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2823 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2824 if (node1->is_shutdown)
2827 RR_SHARED_PTR<ThreadPool> t;
2828 if (!node1->TryGetThreadPool(t))
2830 typename T::iterator iter;
2831 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2834 t->async_resolve(b, f);
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)
2862 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2865 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2866 if (node1->is_shutdown)
2869 RR_SHARED_PTR<ThreadPool> t;
2870 if (!node1->TryGetThreadPool(t))
2872 typename T::results_type results;
2873 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2876 t->async_resolve(b, c, f);
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)
2901 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2904 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2905 if (node1->is_shutdown)
2908 RR_SHARED_PTR<ThreadPool> t;
2909 if (!node1->TryGetThreadPool(t))
2911 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2914 t->async_handshake(f);
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)
2940 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2943 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2944 if (node1->is_shutdown)
2947 RR_SHARED_PTR<ThreadPool> t;
2948 if (!node1->TryGetThreadPool(t))
2950 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2953 t->async_handshake(u, f);
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)
2977 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2980 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2981 if (node1->is_shutdown)
2984 RR_SHARED_PTR<ThreadPool> t;
2985 if (!node1->TryGetThreadPool(t))
2987 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2990 t->async_shutdown(f);