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;
2281 virtual RR_SHARED_PTR<Timer>
CreateTimer(
const boost::posix_time::time_duration& period,
2282 boost::function<
void(
const TimerEvent&)> handler,
bool oneshot =
false);
2306 virtual void Sleep(
const boost::posix_time::time_duration& duration);
2338 RR_SHARED_PTR<RobotRaconteurException>
DownCastException(
const RR_SHARED_PTR<RobotRaconteurException>& exp);
2371 template <
typename T>
2374 boost::mutex::scoped_lock lock(random_generator_lock);
2375 boost::random::uniform_int_distribution<T> d(min, max);
2376 return d(*random_generator);
2389 template <
typename T>
2394 boost::mutex::scoped_lock lock(random_generator_lock);
2395 for (
size_t i = 0; i < count; i++)
2397 boost::random::uniform_int_distribution<T> d(min, max);
2398 o[i] = d(*random_generator);
2416 std::string service_state_nonce;
2418 boost::mutex service_state_nonce_lock;
2435 std::string GetServiceStateNonce();
2444 void UpdateServiceStateNonce();
2447 RR_SHARED_PTR<LogRecordHandler> log_handler;
2448 boost::shared_mutex log_handler_mutex;
2450 boost::shared_mutex log_level_mutex;
2533 const std::string& env_variable_name =
"ROBOTRACONTEUR_LOG_LEVEL");
2554 boost::shared_mutex tap_lock;
2555 RR_SHARED_PTR<MessageTap> tap;
2573 boost::shared_mutex node_directories_lock;
2574 RR_SHARED_PTR<NodeDirectories> node_directories;
2599 template <
typename F>
2600 class asio_async_wait1
2603 asio_async_wait1(F f) : f_(BOOST_ASIO_MOVE_CAST(F)(f)) {}
2605 void do_complete(
const boost::system::error_code& err) { f_(err); }
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)
2632 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2635 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2636 if (node1->is_shutdown)
2639 RR_SHARED_PTR<ThreadPool> t;
2640 if (!node1->TryGetThreadPool(t))
2642 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
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));
2648 node1->shutdown_listeners.connect(
2649 boost::signals2::signal<
void()>::slot_type(boost::bind(&T::cancel, t.get())).track(t).track(f1));
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)
2674 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2677 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2678 if (node1->is_shutdown)
2681 RR_SHARED_PTR<ThreadPool> t;
2682 if (!node1->TryGetThreadPool(t))
2684 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, 0));
2687 t->async_read_some(b, f);
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)
2713 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2716 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2717 if (!node1->thread_pool)
2719 t->async_write_some(b, f);
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)
2745 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2748 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2749 if (!node1->thread_pool)
2751 t->async_connect(b, f);
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)
2779 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2782 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2783 if (!node1->thread_pool)
2785 t->async_connect(b, c, f);
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)
2812 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2815 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2816 if (node1->is_shutdown)
2819 RR_SHARED_PTR<ThreadPool> t;
2820 if (!node1->TryGetThreadPool(t))
2822 typename T::iterator iter;
2823 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, iter));
2826 t->async_resolve(b, f);
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)
2854 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2857 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2858 if (node1->is_shutdown)
2861 RR_SHARED_PTR<ThreadPool> t;
2862 if (!node1->TryGetThreadPool(t))
2864 typename T::results_type results;
2865 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted, RR_MOVE(results)));
2868 t->async_resolve(b, c, f);
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)
2893 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2896 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2897 if (node1->is_shutdown)
2900 RR_SHARED_PTR<ThreadPool> t;
2901 if (!node1->TryGetThreadPool(t))
2903 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2906 t->async_handshake(f);
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)
2932 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2935 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2936 if (node1->is_shutdown)
2939 RR_SHARED_PTR<ThreadPool> t;
2940 if (!node1->TryGetThreadPool(t))
2942 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2945 t->async_handshake(u, f);
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)
2969 RR_SHARED_PTR<RobotRaconteurNode> node1 = node.lock();
2972 boost::shared_lock<boost::shared_mutex> l(node1->thread_pool_lock);
2973 if (node1->is_shutdown)
2976 RR_SHARED_PTR<ThreadPool> t;
2977 if (!node1->TryGetThreadPool(t))
2979 return t->TryPost(boost::bind(f, boost::asio::error::operation_aborted));
2982 t->async_shutdown(f);