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>
51 #ifndef ROBOTRACONTEUR_EMSCRIPTEN
52 #include <boost/asio.hpp>
54 #include <boost/asio/error.hpp>
55 #include <boost/asio/placeholders.hpp>
57 #ifdef ROBOTRACONTEUR_WINDOWS
71 namespace RobotRaconteur
95 class ROBOTRACONTEUR_CORE_API ServiceSecurityPolicy;
96 class ROBOTRACONTEUR_CORE_API ServiceInfo2Subscription;
97 class ROBOTRACONTEUR_CORE_API ServiceSubscription;
98 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilter;
99 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionManager;
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;
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(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>(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, 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);
2987 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
ClientServiceListenerEventType
Enum of client listener events.
Definition: RobotRaconteurConstants.h:500
RobotRaconteur_LogLevel
Log level enum.
Definition: RobotRaconteurConstants.h:608
MessageErrorType
Message error type codes enum.
Definition: RobotRaconteurConstants.h:396
#define RR_TIMEOUT_INFINITE
Disable timeout for asynchronous operations.
Definition: RobotRaconteurConstants.h:566
boost::shared_ptr< RobotRaconteurNode > RobotRaconteurNodePtr
Convenience alias for RobotRaconteurNode shared_ptr.
Definition: RobotRaconteurNode.h:2989
RobotRaconteurObjectLockFlags
The type of object lock.
Definition: RobotRaconteurNode.h:78
@ RobotRaconteurObjectLockFlags_USER_LOCK
User level lock.
Definition: RobotRaconteurNode.h:85
@ RobotRaconteurObjectLockFlags_CLIENT_LOCK
Client level lock.
Definition: RobotRaconteurNode.h:92
Exception thrown when an invalid operation is attempted.
Definition: Error.h:604
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:795
Numeric primitive multidimensional array value type.
Definition: DataTypes.h:1600
Base class for Robot Raconteur exceptions.
Definition: Error.h:50
Wrapper for RobotRaconteurNode::MonitorEnter() and RobotRaconteurNode::MonitorExit() to take advantag...
Definition: RobotRaconteurNode.h:1753
ScopedMonitorLock(const boost::shared_ptr< RRObject > &obj, int32_t timeout=-1)
Create a monitor lock for the specified object.
void release()
Release the monitor lock from the class.
void lock(int32_t timeout=-1)
Relock the object after calling unlock()
void unlock()
Releases the monitor lock.
boost::shared_ptr< RobotRaconteurNode > GetNode()
Get the Node assosciated with the lock.
The central node implementation.
Definition: RobotRaconteurNode.h:132
void SetRequestTimeout(uint32_t timeout)
Set the timeout for requests in milliseconds.
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.
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.
virtual boost::posix_time::ptime NowUTC()
The current time in UTC time zone.
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.
const boost::shared_ptr< RobotRaconteur::DynamicServiceFactory > GetDynamicServiceFactory()
Get the current DynamicServiceFactory. May be null.
void MonitorEnter(const boost::shared_ptr< RRObject > &obj, int32_t timeout=RR_TIMEOUT_INFINITE)
Creates a monitor lock on a specified object.
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.
void AsyncFindServiceByType(boost::string_ref servicetype, const std::vector< std::string > &transportschemes, boost::function< void(const boost::shared_ptr< std::vector< ServiceInfo2 > > &)> handler, int32_t timeout=5000)
Asynchronously use discovery to find availabe services by service type.
uint32_t GetEndpointInactivityTimeout()
Get the timeout for endpoint activity in milliseconds.
std::vector< T > GetRandomInts(size_t count, T min, T max)
Returns a vector of random integer using the node's random number generator.
Definition: RobotRaconteurNode.h:2390
static RobotRaconteurNode * s()
Singleton accessor.
NodeDirectories GetNodeDirectories()
Get the current node directories.
void AsyncReleaseObjectLock(const boost::shared_ptr< RRObject > &obj, boost::function< void(const boost::shared_ptr< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously release an excluse access lock previously locked with RequestObjectLock() or AsyncRequ...
node_updated_listener_connection AddNodeServicesDetectedListener(BOOST_ASIO_MOVE_ARG(Handler) h)
Add a handler to be called when detected services are updated.
Definition: RobotRaconteurNode.h:1332
std::string ReleaseObjectLock(const boost::shared_ptr< RRObject > &obj)
Release an excluse access lock previously locked with RequestObjectLock() or AsyncRequestObjectLock()
void SetDynamicServiceFactory(const boost::shared_ptr< RobotRaconteur::DynamicServiceFactory > &f)
Set the DynamicServicefactory.
void DownCastAndThrowException(RobotRaconteurException &exp)
Downcasts a RobotRaconteurException and throws it.
bool IsServiceTypeRegistered(boost::string_ref servicetype)
Check if a service type has been registered.
boost::signals2::connection shutdown_listener_connection
signals2 connection type for AddShutdownListener()
Definition: RobotRaconteurNode.h:696
void CheckConnection(uint32_t endpoint)
Check that the TransportConnection associated with an endpoint is connected.
static RR_WEAK_PTR< RobotRaconteurNode > weak_sp()
Singleton weak_ptr accessor.
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.
std::map< std::string, boost::intrusive_ptr< RRValue > > GetServiceAttributes(const boost::shared_ptr< RRObject > &obj)
Get the service attributes of a client connection.
void SetExceptionHandler(boost::function< void(const std::exception *)> handler)
Set an exception handler function.
boost::shared_ptr< ThreadPool > GetThreadPool()
Get the current ThreadPool for the node.
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.
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.
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.
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.
std::vector< std::string > GetPulledServiceTypes(const boost::shared_ptr< RRObject > &obj)
Get the names of service types pulled by a client.
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.
void AsyncUpdateDetectedNodes(const std::vector< std::string > &schemes, boost::function< void()> handler, int32_t timeout=5000)
Asynchronously update the detected nodes cache.
std::vector< ServiceInfo2 > FindServiceByType(boost::string_ref servicetype, const std::vector< std::string > &transportschemes)
Use discovery to find available services by service type.
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.
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.
std::vector< NodeInfo2 > FindNodeByName(boost::string_ref name, const std::vector< std::string > &transportschemes)
Finds nodes on the network with a specified NodeName.
RobotRaconteur::NodeID NodeID()
Get the current NodeID.
std::vector< NodeInfo2 > FindNodeByID(const RobotRaconteur::NodeID &id, const std::vector< std::string > &transportschemes)
Finds nodes on the network with a specified NodeID.
void ReleaseThreadPool()
Shuts down and releases the node thred pool Do not call ReleaseThreadPool unless you really know what...
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.
virtual boost::shared_ptr< AutoResetEvent > CreateAutoResetEvent()
Create an AutoResetEvent object.
boost::function< void(const std::exception *)> GetExceptionHandler()
Get the node's current exception handler, or null.
void HandleException(const std::exception *exp)
Handle exceptino by passing the current exception to the handler function.
std::string NodeName()
Get the current NodeName.
boost::shared_ptr< LogRecordHandler > GetLogRecordHandler()
Get the currently configured log record handler.
std::vector< std::string > GetRegisteredServiceTypes()
Return names of registered service types.
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.
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.
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.
static boost::shared_ptr< RobotRaconteurNode > sp()
Singleton shared_ptr accessor.
virtual boost::posix_time::ptime NodeSyncTimeUTC()
The sync time of the node.
RobotRaconteur_LogLevel GetLogLevel()
Get the current log level for the node.
void LogMessage(RobotRaconteur_LogLevel level, const std::string &message)
Log a simple message using the current node.
void SetLogLevel(RobotRaconteur_LogLevel level)
Set the log level for the node.
void SetTransportInactivityTimeout(uint32_t timeout)
Set the timeout for transport activity in milliseconds.
void Init()
Initialize the node. Called automatically for s() and sp()
T GetRandomInt(T min, T max)
Returns a random integer using the node's random number generator.
Definition: RobotRaconteurNode.h:2372
bool TryGetNodeID(RobotRaconteur::NodeID &id)
Tries getting the current NodeID.
void UnregisterServiceType(boost::string_ref type)
Unregister a previously registered service type.
void SetLogRecordHandler(const boost::shared_ptr< LogRecordHandler > &handler)
Set the handler for log records.
virtual boost::shared_ptr< Rate > CreateRate(double frequency)
Create a Rate object.
boost::shared_ptr< ServerContext > RegisterService(const boost::shared_ptr< ServerContext > &c)
Registers a service using a previously instantiated ServerContext.
void SetEndpointInactivityTimeout(uint32_t timeout)
Set the timeout for endpoint activity in milliseconds.
std::vector< std::string > GetRegisteredServiceNames()
Get the names of registered services.
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.
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.
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 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.
boost::shared_ptr< ServerContext > GetService(boost::string_ref name)
Gets a ServerContext for a service by name.
boost::shared_ptr< ServiceFactory > GetServiceType(boost::string_ref type)
Returns a previously registered service type.
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
std::vector< NodeDiscoveryInfo > GetDetectedNodes()
Get the nodes currently detected by Transports.
static bool TryHandleException(RR_WEAK_PTR< RobotRaconteurNode > node, const std::exception *exp)
Try to pass an exception to the exception handler.
boost::shared_ptr< ThreadPoolFactory > GetThreadPoolFactory()
Get the current ThreadPoolFactory for the node.
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.
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.
std::string GetServiceName(const boost::shared_ptr< RRObject > &obj)
Get the name of a service from a client connection.
boost::shared_ptr< RobotRaconteurException > DownCastException(const boost::shared_ptr< RobotRaconteurException > &exp)
Downcasts a RobotRaconteurException.
boost::shared_ptr< MessageTap > GetMessageTap()
Get the active message tap.
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.
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.
bool CompareLogLevel(RobotRaconteur_LogLevel log_level)
Test if the specified log level would be accepted.
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 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...
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.
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.
Context for services registered in a node for use by clients.
Definition: Service.h:251
Class to manage multiple subscriptions to services.
Definition: Subscription.h:1813
Represents. a point in time. Used by wire members to timestamp packets.
Definition: DataTypes.h:2666
Base class for transports.
Definition: Transport.h:120
Timer event structure.
Definition: Timer.h:46