Robot Raconteur Core C++ Library
Subscription.h
Go to the documentation of this file.
1 
24 #include "RobotRaconteur/Client.h"
25 
26 #include <boost/tuple/tuple_comparison.hpp>
27 #include <boost/unordered_set.hpp>
28 
29 #pragma once
30 
31 namespace RobotRaconteur
32 {
33 namespace detail
34 {
35 class Discovery;
36 class Discovery_nodestorage;
37 class ServiceInfo2Subscription_client;
38 class ServiceSubscription_client;
39 class ServiceSubscription_retrytimer;
40 class WireSubscription_connection;
41 class PipeSubscription_connection;
42 class WireSubscription_send_iterator;
43 class PipeSubscription_send_iterator;
44 class ServiceSubscription_custom_member_subscribers;
45 class ServiceSubscriptionManager_subscription;
46 } // namespace detail
47 
48 class ROBOTRACONTEUR_CORE_API WireConnectionBase;
49 template <typename T>
50 class WireConnection;
51 class ROBOTRACONTEUR_CORE_API WireSubscriptionBase;
52 template <typename T>
53 class WireSubscription;
54 
55 class ROBOTRACONTEUR_CORE_API PipeEndpointBase;
56 template <typename T>
57 class PipeEndpoint;
58 class ROBOTRACONTEUR_CORE_API PipeSubscriptionBase;
59 template <typename T>
60 class PipeSubscription;
61 class ROBOTRACONTEUR_CORE_API SubObjectSubscription;
62 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionManager;
63 
74 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterNode
75 {
76  public:
80  std::string NodeName;
82  std::string Username;
84  RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> > Credentials;
85 };
86 
91 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterAttribute
92 {
93  public:
95  std::string Name;
97  std::string Value;
99  boost::regex ValueRegex;
101  bool UseRegex;
102 
115  ServiceSubscriptionFilterAttribute(boost::string_ref value);
123  ServiceSubscriptionFilterAttribute(const boost::regex& value_regex);
132  ServiceSubscriptionFilterAttribute(boost::string_ref name, boost::string_ref value);
133 
142  ServiceSubscriptionFilterAttribute(boost::string_ref name, const boost::regex& value_regex);
143 
151  bool IsMatch(boost::string_ref value) const;
160  bool IsMatch(boost::string_ref name, boost::string_ref value) const;
168  bool IsMatch(const std::vector<std::string>& values) const;
176  bool IsMatch(const RR_INTRUSIVE_PTR<RRList<RRValue> >& values) const;
184  bool IsMatch(const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& values) const;
192  bool IsMatch(const std::map<std::string, std::string>& values) const;
193 };
194 
201 ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterAttribute
202 CreateServiceSubscriptionFilterAttributeRegex(boost::string_ref regex_value);
210 ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterAttribute
211 CreateServiceSubscriptionFilterAttributeRegex(boost::string_ref name, boost::string_ref regex_value);
212 
221 ROBOTRACONTEUR_CORE_API
223  boost::string_ref combined_identifier);
231 ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterAttribute
232 CreateServiceSubscriptionFilterAttributeIdentifier(boost::string_ref identifier_name, boost::string_ref uuid_string);
242  boost::string_ref name, boost::string_ref identifier_name, boost::string_ref uuid_string);
243 
249 {
258 };
259 
266 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilterAttributeGroup
267 {
268  public:
270  std::vector<ServiceSubscriptionFilterAttribute> Attributes;
272  std::vector<ServiceSubscriptionFilterAttributeGroup> Groups;
275 
280 
299  std::vector<ServiceSubscriptionFilterAttribute> attributes);
307  std::vector<ServiceSubscriptionFilterAttributeGroup> groups);
308 
316  bool IsMatch(boost::string_ref value) const;
317 
325  bool IsMatch(RR_INTRUSIVE_PTR<RRArray<char> >& value) const;
326 
334  bool IsMatch(const std::vector<std::string>& values) const;
342  bool IsMatch(const RR_INTRUSIVE_PTR<RRList<RRValue> >& values) const;
350  bool IsMatch(const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& values) const;
358  bool IsMatch(const std::map<std::string, std::string>& values) const;
359 
360  bool IsMatch(const RR_INTRUSIVE_PTR<RRValue>& value) const;
361 };
362 
372 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionFilter
373 {
374  public:
376  std::vector<RR_SHARED_PTR<ServiceSubscriptionFilterNode> > Nodes;
378  std::vector<std::string> ServiceNames;
380  std::vector<std::string> TransportSchemes;
382  std::map<std::string, ServiceSubscriptionFilterAttributeGroup> Attributes;
386  boost::function<bool(const ServiceInfo2&)> Predicate;
388  uint32_t MaxConnections;
389 
391 };
392 
400 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionClientID
401 {
402  public:
406  std::string ServiceName;
407 
414  ServiceSubscriptionClientID(const ::RobotRaconteur::NodeID& nodeid, boost::string_ref service_name);
415 
421 
423  bool operator==(const ServiceSubscriptionClientID& id2) const;
424 
426  bool operator!=(const ServiceSubscriptionClientID& id2) const;
427 
429  bool operator<(const ServiceSubscriptionClientID& id2) const;
430 };
431 
432 size_t hash_value(const ServiceSubscriptionClientID& id);
433 
434 class IServiceSubscription
435 {
436  public:
437  friend class detail::Discovery;
438 
439  protected:
440  virtual void Init(const std::vector<std::string>& service_types,
441  const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter) = 0;
442  virtual void NodeUpdated(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) = 0;
443  virtual void NodeLost(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) = 0;
444 
445  public:
446  virtual void Close() = 0;
447  virtual ~IServiceSubscription(){};
448 };
449 
460 class ROBOTRACONTEUR_CORE_API ServiceInfo2Subscription : public IServiceSubscription,
461  public RR_ENABLE_SHARED_FROM_THIS<ServiceInfo2Subscription>,
462  private boost::noncopyable
463 {
464  public:
465  friend class detail::Discovery;
466  friend class ServiceSubscriptionManager;
467 
468  typedef boost::signals2::connection event_connection;
469 
480  std::map<ServiceSubscriptionClientID, ServiceInfo2> GetDetectedServiceInfo2();
481 
495  event_connection AddServiceDetectedListener(
496  boost::function<void(const RR_SHARED_PTR<ServiceInfo2Subscription>&, const ServiceSubscriptionClientID&,
497  const ServiceInfo2&)>
498  handler);
499 
513  event_connection AddServiceLostListener(
514  boost::function<void(const RR_SHARED_PTR<ServiceInfo2Subscription>&, const ServiceSubscriptionClientID&,
515  const ServiceInfo2&)>
516  handler);
517 
524  RR_OVIRTUAL void Close() RR_OVERRIDE;
525 
526  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
527 
528  protected:
529  boost::mutex this_lock;
530 
531  bool active;
532 
533  std::map<ServiceSubscriptionClientID, RR_SHARED_PTR<detail::ServiceInfo2Subscription_client> > clients;
534 
535  RR_WEAK_PTR<RobotRaconteurNode> node;
536  RR_WEAK_PTR<detail::Discovery> parent;
537 
538  std::vector<std::string> service_types;
539  RR_SHARED_PTR<ServiceSubscriptionFilter> filter;
540 
541  uint32_t retry_delay;
542 
543  boost::signals2::signal<void(const RR_SHARED_PTR<ServiceInfo2Subscription>&, const ServiceSubscriptionClientID&,
544  const ServiceInfo2&)>
545  detected_listeners;
546  boost::signals2::signal<void(const RR_SHARED_PTR<ServiceInfo2Subscription>&, const ServiceSubscriptionClientID&,
547  const ServiceInfo2&)>
548  lost_listeners;
549 
550  public:
551  // Do not call, use RobotRaconteurNode()->SubscribeServiceInfo2()
552  ServiceInfo2Subscription(const RR_SHARED_PTR<detail::Discovery>& parent);
553 
554  protected:
555  RR_OVIRTUAL void Init(const std::vector<std::string>& service_types,
556  const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter) RR_OVERRIDE;
557  RR_OVIRTUAL void NodeUpdated(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) RR_OVERRIDE;
558  RR_OVIRTUAL void NodeLost(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) RR_OVERRIDE;
559 
560  void fire_ServiceDetectedListener(const ServiceSubscriptionClientID& noden, const ServiceInfo2& info);
561  void fire_ServiceLostListener(const ServiceSubscriptionClientID& noden, const ServiceInfo2& info);
562 };
563 
564 namespace detail
565 {
566 template <typename T>
567 void AsyncGetDefaultClient_handler_adapter(
568  const boost::function<void(const RR_SHARED_PTR<T>&, const RR_SHARED_PTR<RobotRaconteurException>&)>& handler,
569  const RR_SHARED_PTR<RRObject>& obj, const RR_SHARED_PTR<RobotRaconteurException>& err)
570 {
571  if (err)
572  {
573  handler(RR_SHARED_PTR<T>(), err);
574  return;
575  }
576 
577  RR_SHARED_PTR<T> obj1 = RR_DYNAMIC_POINTER_CAST<T>(obj);
578  if (!obj1)
579  {
580  handler(RR_SHARED_PTR<T>(), RR_MAKE_SHARED<ConnectionException>("Cannot cast client to requested type"));
581  return;
582  }
583 
584  handler(obj1, RR_SHARED_PTR<RobotRaconteurException>());
585 }
586 } // namespace detail
587 
610 class ROBOTRACONTEUR_CORE_API ServiceSubscription : public IServiceSubscription,
611  public RR_ENABLE_SHARED_FROM_THIS<ServiceSubscription>,
612  private boost::noncopyable
613 {
614  public:
615  friend class detail::Discovery;
616  friend class detail::ServiceSubscription_retrytimer;
617  friend class WireSubscriptionBase;
618  friend class PipeSubscriptionBase;
619  friend class detail::ServiceSubscription_custom_member_subscribers;
620  friend class SubObjectSubscription;
621  friend class ServiceSubscriptionManager;
622 
623  typedef boost::signals2::connection event_connection;
624 
641  std::map<ServiceSubscriptionClientID, RR_SHARED_PTR<RRObject> > GetConnectedClients();
642 
655  event_connection AddClientConnectListener(
656  boost::function<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
657  const RR_SHARED_PTR<RRObject>&)>
658  handler);
659 
672  event_connection AddClientDisconnectListener(
673  boost::function<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
674  const RR_SHARED_PTR<RRObject>&)>
675  handler);
676 
691  boost::function<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
692  const std::vector<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)>
693  handler);
694 
701  RR_OVIRTUAL void Close() RR_OVERRIDE;
702 
712  virtual void ClaimClient(const RR_SHARED_PTR<RRObject>& client);
713 
721  virtual void ReleaseClient(const RR_SHARED_PTR<RRObject>& client);
722 
730  uint32_t GetConnectRetryDelay();
731 
739  void SetConnectRetryDelay(uint32_t delay_milliseconds);
740 
757  template <typename T>
758  RR_SHARED_PTR<WireSubscription<T> > SubscribeWire(boost::string_ref membername, boost::string_ref servicepath = "")
759  {
760  RR_SHARED_PTR<WireSubscription<T> > o =
761  RR_MAKE_SHARED<WireSubscription<T> >(shared_from_this(), membername, servicepath);
762  SubscribeWire1(o);
763  return o;
764  }
765 
782  template <typename T>
783  RR_SHARED_PTR<PipeSubscription<T> > SubscribePipe(boost::string_ref membername, boost::string_ref servicepath = "",
784  uint32_t max_recv_packets = std::numeric_limits<uint32_t>::max())
785  {
786  RR_SHARED_PTR<PipeSubscription<T> > o =
787  RR_MAKE_SHARED<PipeSubscription<T> >(shared_from_this(), membername, servicepath, max_recv_packets);
788  SubscribePipe1(o);
789  return o;
790  }
791 
807  template <typename T>
808  RR_SHARED_PTR<T> GetDefaultClient()
809  {
810  return rr_cast<T>(GetDefaultClientBase());
811  }
812 
824  template <typename T>
825  bool TryGetDefaultClient(RR_SHARED_PTR<T>& client_out)
826  {
827  RR_SHARED_PTR<RRObject> c;
828  if (!TryGetDefaultClientBase(c))
829  {
830  return false;
831  }
832  RR_SHARED_PTR<T> c1 = RR_DYNAMIC_POINTER_CAST<T>(c);
833  if (!c1)
834  return false;
835 
836  client_out = c1;
837  return true;
838  }
839 
856  template <typename T>
857  RR_SHARED_PTR<T> GetDefaultClientWait(int32_t timeout = RR_TIMEOUT_INFINITE)
858  {
859  return rr_cast<T>(GetDefaultClientWaitBase(timeout));
860  }
861 
874  template <typename T>
875  bool TryGetDefaultClientWait(RR_SHARED_PTR<T>& client_out, int32_t timeout = RR_TIMEOUT_INFINITE)
876  {
877  RR_SHARED_PTR<RRObject> c;
878  if (!TryGetDefaultClientWaitBase(c, timeout))
879  {
880  return false;
881  }
882  RR_SHARED_PTR<T> c1 = RR_DYNAMIC_POINTER_CAST<T>(c);
883  if (!c1)
884  return false;
885 
886  client_out = c1;
887  return true;
888  }
889 
899  template <typename T>
901  boost::function<void(const RR_SHARED_PTR<T>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
902  int32_t timeout = RR_TIMEOUT_INFINITE)
903  {
904  AsyncGetDefaultClientBase(boost::bind(&detail::AsyncGetDefaultClient_handler_adapter<T>, handler,
905  RR_BOOST_PLACEHOLDERS(_1), RR_BOOST_PLACEHOLDERS(_2)),
906  timeout);
907  }
908 
918  std::vector<std::string> GetServiceURL();
919 
933  void UpdateServiceURL(boost::string_ref url, boost::string_ref username = "",
934  const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
935  (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
936  boost::string_ref object_type = "", bool close_connected = false);
937 
951  void UpdateServiceURL(const std::vector<std::string>& url, boost::string_ref username = "",
952  const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
953  (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
954  boost::string_ref object_type = "", bool close_connected = false);
955 
966  const std::vector<std::string>& service_types,
967  const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter = RR_SHARED_PTR<ServiceSubscriptionFilter>());
968 
985  RR_SHARED_PTR<SubObjectSubscription> SubscribeSubObject(boost::string_ref servicepath,
986  boost::string_ref objecttype = "");
987 
988  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
989 
990  protected:
991  boost::mutex this_lock;
992 
993  bool active;
994 
995  std::map<ServiceSubscriptionClientID, RR_SHARED_PTR<detail::ServiceSubscription_client> > clients;
996 
997  RR_WEAK_PTR<RobotRaconteurNode> node;
998  RR_WEAK_PTR<detail::Discovery> parent;
999 
1000  std::vector<std::string> service_types;
1001  RR_SHARED_PTR<ServiceSubscriptionFilter> filter;
1002 
1003  uint32_t retry_delay;
1004 
1005  boost::signals2::signal<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
1006  const RR_SHARED_PTR<RRObject>&)>
1007  connect_listeners;
1008  boost::signals2::signal<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
1009  const RR_SHARED_PTR<RRObject>&)>
1010  disconnect_listeners;
1011  boost::signals2::signal<void(const RR_SHARED_PTR<ServiceSubscription>&, const ServiceSubscriptionClientID&,
1012  const std::vector<std::string>&, const RR_SHARED_PTR<RobotRaconteurException>&)>
1013  connect_failed_listeners;
1014 
1015  RR_SHARED_PTR<RR_BOOST_ASIO_STRAND> listener_strand;
1016 
1017  boost::unordered_set<RR_SHARED_PTR<WireSubscriptionBase> > wire_subscriptions;
1018  boost::unordered_set<RR_SHARED_PTR<PipeSubscriptionBase> > pipe_subscriptions;
1019 
1020  bool use_service_url;
1021  std::vector<std::string> service_url;
1022  std::string service_url_username;
1023  RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> > service_url_credentials;
1024 
1025  public:
1026  // Do not call, use RobotRaconteurNode()->SubscribeService()
1027  ServiceSubscription(const RR_SHARED_PTR<detail::Discovery>& parent);
1028 
1029  protected:
1030  RR_OVIRTUAL void Init(const std::vector<std::string>& service_types,
1031  const RR_SHARED_PTR<ServiceSubscriptionFilter>& filter) RR_OVERRIDE;
1032  virtual void InitServiceURL(const std::vector<std::string>& url, boost::string_ref username = "",
1033  const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& credentials =
1034  (RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >()),
1035  boost::string_ref objecttype = "");
1036  RR_OVIRTUAL void NodeUpdated(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) RR_OVERRIDE;
1037  RR_OVIRTUAL void NodeLost(RR_SHARED_PTR<detail::Discovery_nodestorage> storage) RR_OVERRIDE;
1038 
1039  void ClientConnected(const RR_SHARED_PTR<RRObject>& c, const RR_SHARED_PTR<RobotRaconteurException>& err,
1040  const RR_SHARED_PTR<detail::ServiceSubscription_client>& c2,
1041  const std::vector<std::string>& url);
1042  void ConnectRetry(const RR_SHARED_PTR<detail::ServiceSubscription_client>& c2);
1043  void ConnectRetry2(const RR_SHARED_PTR<detail::ServiceSubscription_client>& c2);
1044 
1045  static void ClientEvent(RR_WEAK_PTR<ServiceSubscription> this_, const RR_SHARED_PTR<ClientContext>& ctx,
1046  ClientServiceListenerEventType evt, const RR_SHARED_PTR<void>& p,
1047  RR_WEAK_PTR<detail::ServiceSubscription_client> c2);
1048 
1049  void fire_ClientConnectListeners(const ServiceSubscriptionClientID& noden, const RR_SHARED_PTR<RRObject>& client);
1050  void fire_ClientDisconnectListeners(const ServiceSubscriptionClientID& noden,
1051  const RR_SHARED_PTR<RRObject>& client);
1052  void fire_ClientConnectFailedListeners(const ServiceSubscriptionClientID& noden,
1053  const std::vector<std::string>& url,
1054  const RR_SHARED_PTR<RobotRaconteurException>& err);
1055 
1056  void SubscribeWire1(const RR_SHARED_PTR<WireSubscriptionBase>& s);
1057  void SubscribePipe1(const RR_SHARED_PTR<PipeSubscriptionBase>& s);
1058 
1059  void WireSubscriptionClosed(const RR_SHARED_PTR<WireSubscriptionBase>& s);
1060  void PipeSubscriptionClosed(const RR_SHARED_PTR<PipeSubscriptionBase>& s);
1061 
1062  RR_SHARED_PTR<RRObject> GetDefaultClientBase();
1063  bool TryGetDefaultClientBase(RR_SHARED_PTR<RRObject>& client_out);
1064 
1065  RR_SHARED_PTR<RRObject> GetDefaultClientWaitBase(int32_t timeout = RR_TIMEOUT_INFINITE);
1066  bool TryGetDefaultClientWaitBase(RR_SHARED_PTR<RRObject>& client_out, int32_t timeout = RR_TIMEOUT_INFINITE);
1067 
1068  void AsyncGetDefaultClientBase(
1069  boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1070  int32_t timeout = RR_TIMEOUT_INFINITE);
1071 
1072  void SoftClose();
1073 };
1074 
1081 class ROBOTRACONTEUR_CORE_API WireSubscriptionBase : public RR_ENABLE_SHARED_FROM_THIS<WireSubscriptionBase>,
1082  private boost::noncopyable
1083 {
1084  public:
1085  friend class WireConnectionBase;
1086  friend class ServiceSubscription;
1087  friend class detail::WireSubscription_connection;
1088  friend class detail::WireSubscription_send_iterator;
1089 
1090  typedef boost::signals2::connection event_connection;
1091 
1092  virtual ~WireSubscriptionBase() {}
1093 
1094  RR_INTRUSIVE_PTR<RRValue> GetInValueBase(TimeSpec* time = NULL,
1095  RR_SHARED_PTR<WireConnectionBase>* connection = NULL);
1096  bool TryGetInValueBase(RR_INTRUSIVE_PTR<RRValue>& val, TimeSpec* time = NULL,
1097  RR_SHARED_PTR<WireConnectionBase>* connection = NULL);
1098 
1108  bool WaitInValueValid(int32_t timeout = RR_TIMEOUT_INFINITE);
1109 
1116 
1124 
1134  void SetIgnoreInValue(bool ignore);
1135 
1145 
1156  void SetInValueLifespan(int32_t millis);
1157 
1158  void SetOutValueAllBase(const RR_INTRUSIVE_PTR<RRValue>& val);
1159 
1167  void Close();
1168 
1169  WireSubscriptionBase(const RR_SHARED_PTR<ServiceSubscription>& parent, boost::string_ref membername,
1170  boost::string_ref servicepath);
1171 
1172  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1173 
1174  protected:
1175  void ClientConnected(const ServiceSubscriptionClientID& client_id, const RR_SHARED_PTR<RRObject>& client);
1176  void ClientDisconnected(const ServiceSubscriptionClientID& client_id, const RR_SHARED_PTR<RRObject>& client);
1177 
1178  void WireConnectionClosed(const RR_SHARED_PTR<detail::WireSubscription_connection>& wire);
1179  void WireValueChanged(const RR_SHARED_PTR<detail::WireSubscription_connection>& wire,
1180  const RR_INTRUSIVE_PTR<RRValue>& value, const TimeSpec& time);
1181 
1182  boost::mutex this_lock;
1183  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<detail::WireSubscription_connection> > connections;
1184  boost::initialized<bool> closed;
1185  RR_WEAK_PTR<RobotRaconteurNode> node;
1186  RR_WEAK_PTR<ServiceSubscription> parent;
1187 
1188  RR_INTRUSIVE_PTR<RRValue> in_value;
1189  TimeSpec in_value_time;
1190  boost::initialized<bool> in_value_valid;
1191  RR_SHARED_PTR<WireConnectionBase> in_value_connection;
1192  int32_t in_value_lifespan;
1193  boost::posix_time::ptime in_value_time_local;
1194 
1195  boost::condition_variable in_value_wait;
1196 
1197  boost::initialized<bool> ignore_in_value;
1198 
1199  std::string membername;
1200  std::string servicepath;
1201 
1202  virtual void fire_WireValueChanged(const RR_INTRUSIVE_PTR<RRValue>& value, const TimeSpec& time,
1203  const RR_SHARED_PTR<WireConnectionBase>& connection);
1204  virtual bool isempty_WireValueChanged();
1205  RR_SHARED_PTR<detail::async_signal_pool_semaphore> wire_value_changed_semaphore;
1206 };
1207 
1231 template <typename T>
1233 {
1234  public:
1235  WireSubscription(const RR_SHARED_PTR<ServiceSubscription>& parent, boost::string_ref membername,
1236  boost::string_ref servicepath)
1237  : WireSubscriptionBase(parent, membername, servicepath)
1238  {}
1239 
1249  T GetInValue(TimeSpec* time = NULL, typename RR_SHARED_PTR<WireConnection<T> >* connection = NULL)
1250  {
1251  RR_SHARED_PTR<WireConnectionBase> connection1;
1252  T o = RRPrimUtil<T>::PreUnpack(GetInValueBase(time, &connection1));
1253  if (connection1)
1254  {
1255  *connection = RR_DYNAMIC_POINTER_CAST<WireConnection<T> >(connection1);
1256  }
1257  return o;
1258  }
1259 
1272  bool TryGetInValue(T& val, TimeSpec* time = NULL, typename RR_SHARED_PTR<WireConnection<T> >* connection = NULL)
1273  {
1274  RR_INTRUSIVE_PTR<RRValue> o;
1275  RR_SHARED_PTR<WireConnectionBase> connection1;
1276  if (!TryGetInValueBase(o, time, &connection1))
1277  return false;
1278  val = RRPrimUtil<T>::PreUnpack(o);
1279  if (connection && connection1)
1280  {
1281  *connection = RR_DYNAMIC_POINTER_CAST<WireConnection<T> >(connection1);
1282  }
1283  return true;
1284  }
1285 
1295  void SetOutValueAll(const T& val) { SetOutValueAllBase(RRPrimUtil<T>::PrePack(val)); }
1296 
1309  boost::function<void(const RR_SHARED_PTR<WireSubscription<T> >&, const T&, const TimeSpec&)> f)
1310  {
1311  return wire_value_changed.connect(f);
1312  }
1313 
1314  protected:
1315  boost::signals2::signal<void(const RR_SHARED_PTR<WireSubscription<T> >&, const T&, const TimeSpec&)>
1316  wire_value_changed;
1317 
1318  RR_OVIRTUAL void fire_WireValueChanged(const RR_INTRUSIVE_PTR<RRValue>& value, const TimeSpec& time,
1319  const RR_SHARED_PTR<WireConnectionBase>& connection) RR_OVERRIDE
1320  {
1321  RR_UNUSED(connection);
1322  wire_value_changed(RR_STATIC_POINTER_CAST<WireSubscription<T> >(shared_from_this()),
1323  RRPrimUtil<T>::PreUnpack(value), time);
1324  }
1325 
1326  RR_OVIRTUAL bool isempty_WireValueChanged() RR_OVERRIDE { return wire_value_changed.empty(); }
1327 };
1328 
1335 class ROBOTRACONTEUR_CORE_API PipeSubscriptionBase : public RR_ENABLE_SHARED_FROM_THIS<PipeSubscriptionBase>,
1336  private boost::noncopyable
1337 {
1338  public:
1339  friend class PipeConnectionBase;
1340  friend class ServiceSubscription;
1341  friend class detail::PipeSubscription_connection;
1342  friend class detail::PipeSubscription_send_iterator;
1343 
1344  typedef boost::signals2::connection event_connection;
1345 
1346  virtual ~PipeSubscriptionBase() {}
1347 
1348  RR_INTRUSIVE_PTR<RRValue> ReceivePacketBase();
1349  bool TryReceivePacketBase(RR_INTRUSIVE_PTR<RRValue>& packet);
1350  bool TryReceivePacketBaseWait(RR_INTRUSIVE_PTR<RRValue>& packet, int32_t timeout = RR_TIMEOUT_INFINITE,
1351  bool peek = false, RR_SHARED_PTR<PipeEndpointBase>* ep = NULL);
1352 
1360  size_t Available();
1361 
1368 
1376 
1386  void SetIgnoreReceived(bool ignore);
1387 
1388  void AsyncSendPacketAllBase(const RR_INTRUSIVE_PTR<RRValue>& packet);
1389 
1397  void Close();
1398 
1399  PipeSubscriptionBase(const RR_SHARED_PTR<ServiceSubscription>& parent, boost::string_ref membername,
1400  boost::string_ref servicepath = "", int32_t max_recv_packets = -1,
1401  int32_t max_send_backlog = 5);
1402 
1403  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1404 
1405  protected:
1406  void ClientConnected(const ServiceSubscriptionClientID& client_id, const RR_SHARED_PTR<RRObject>& client);
1407  void ClientDisconnected(const ServiceSubscriptionClientID& client_id, const RR_SHARED_PTR<RRObject>& client);
1408 
1409  void PipeEndpointClosed(const RR_SHARED_PTR<detail::PipeSubscription_connection>& pipe);
1410  void PipeEndpointPacketReceived(const RR_SHARED_PTR<detail::PipeSubscription_connection>& pipe,
1411  const RR_INTRUSIVE_PTR<RRValue>& value);
1412 
1413  boost::mutex this_lock;
1414  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<detail::PipeSubscription_connection> > connections;
1415  boost::initialized<bool> closed;
1416  RR_WEAK_PTR<ServiceSubscription> parent;
1417  RR_WEAK_PTR<RobotRaconteurNode> node;
1418 
1419  std::deque<boost::tuple<RR_INTRUSIVE_PTR<RRValue>, RR_SHARED_PTR<PipeEndpointBase> > > recv_packets;
1420  boost::condition_variable recv_packets_wait;
1421 
1422  std::string membername;
1423  std::string servicepath;
1424 
1425  boost::initialized<int32_t> max_recv_packets;
1426  boost::initialized<bool> ignore_incoming_packets;
1427 
1428  boost::initialized<int32_t> max_send_backlog;
1429 
1430  virtual void fire_PipePacketReceived();
1431  virtual bool isempty_PipePacketReceived();
1432  RR_SHARED_PTR<detail::async_signal_pool_semaphore> pipe_packet_received_semaphore;
1433 };
1434 
1458 template <typename T>
1460 {
1461  public:
1462  PipeSubscription(const RR_SHARED_PTR<ServiceSubscription>& parent, boost::string_ref membername,
1463  boost::string_ref servicepath = "", int32_t max_recv_packets = -1, int32_t max_send_backlog = 5)
1464  : PipeSubscriptionBase(parent, membername, servicepath, max_recv_packets)
1465  {
1466  RR_UNUSED(max_send_backlog);
1467  }
1468 
1476  T ReceivePacket() { return RRPrimUtil<T>::PreUnpack(ReceivePacketBase()); }
1477 
1489  bool TryReceivePacket(T& packet)
1490  {
1491  RR_INTRUSIVE_PTR<RRValue> o;
1492  if (!TryReceivePacketBase(o))
1493  return false;
1494  packet = RRPrimUtil<T>::PreUnpack(o);
1495  return true;
1496  }
1497 
1509  bool TryReceivePacketWait(T& packet, int32_t timeout = RR_TIMEOUT_INFINITE, bool peek = false,
1510  RR_SHARED_PTR<PipeEndpoint<T> >* ep = NULL)
1511  {
1512  RR_INTRUSIVE_PTR<RRValue> o;
1513  RR_SHARED_PTR<PipeEndpointBase> ep1;
1514  if (!TryReceivePacketBaseWait(o, timeout, peek, &ep1))
1515  return false;
1516  packet = RRPrimUtil<T>::PreUnpack(o);
1517  if (ep1)
1518  {
1519  *ep = RR_DYNAMIC_POINTER_CAST<PipeEndpoint<T> >(ep1);
1520  }
1521  return true;
1522  }
1523 
1532  void AsyncSendPacketAll(const T& packet) { AsyncSendPacketAllBase(RRPrimUtil<T>::PrePack(packet)); }
1533 
1548  event_connection AddPipePacketReceivedListener(boost::function<void(const RR_SHARED_PTR<PipeSubscription<T> >&)> f)
1549  {
1550  return pipe_packet_received.connect(f);
1551  }
1552 
1553  protected:
1554  boost::signals2::signal<void(const RR_SHARED_PTR<PipeSubscription<T> >&)> pipe_packet_received;
1555 
1556  RR_OVIRTUAL void fire_PipePacketReceived() RR_OVERRIDE
1557  {
1558  pipe_packet_received(RR_STATIC_POINTER_CAST<PipeSubscription<T> >(shared_from_this()));
1559  }
1560 
1561  RR_OVIRTUAL bool isempty_PipePacketReceived() RR_OVERRIDE { return pipe_packet_received.empty(); }
1562 };
1563 
1578 class ROBOTRACONTEUR_CORE_API SubObjectSubscription : public RR_ENABLE_SHARED_FROM_THIS<SubObjectSubscription>,
1579  private boost::noncopyable
1580 {
1581 
1582  public:
1583  friend class ServiceSubscription;
1584 
1585  virtual ~SubObjectSubscription() {}
1586 
1599  template <typename T>
1600  RR_SHARED_PTR<T> GetDefaultClient()
1601  {
1602  return rr_cast<T>(GetDefaultClientBase());
1603  }
1604 
1616  template <typename T>
1617  bool TryGetDefaultClient(RR_SHARED_PTR<T>& client_out)
1618  {
1619  RR_SHARED_PTR<RRObject> c;
1620  if (!TryGetDefaultClientBase(c))
1621  {
1622  return false;
1623  }
1624  RR_SHARED_PTR<T> c1 = RR_DYNAMIC_POINTER_CAST<T>(c);
1625  if (!c1)
1626  return false;
1627 
1628  client_out = c1;
1629  return true;
1630  }
1631 
1647  template <typename T>
1648  RR_SHARED_PTR<T> GetDefaultClientWait(int32_t timeout = RR_TIMEOUT_INFINITE)
1649  {
1650  return rr_cast<T>(GetDefaultClientWaitBase(timeout));
1651  }
1652 
1665  template <typename T>
1666  bool TryGetDefaultClientWait(RR_SHARED_PTR<T>& client_out, int32_t timeout = RR_TIMEOUT_INFINITE)
1667  {
1668  RR_SHARED_PTR<RRObject> c;
1669  if (!TryGetDefaultClientWaitBase(c, timeout))
1670  {
1671  return false;
1672  }
1673  RR_SHARED_PTR<T> c1 = RR_DYNAMIC_POINTER_CAST<T>(c);
1674  if (!c1)
1675  return false;
1676 
1677  client_out = c1;
1678  return true;
1679  }
1680 
1692  template <typename T>
1694  boost::function<void(const RR_SHARED_PTR<T>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1695  int32_t timeout = RR_TIMEOUT_INFINITE)
1696  {
1697  AsyncGetDefaultClientBase(boost::bind(&detail::AsyncGetDefaultClient_handler_adapter<T>, handler,
1698  RR_BOOST_PLACEHOLDERS(_1), RR_BOOST_PLACEHOLDERS(_2)),
1699  timeout);
1700  }
1701 
1702  void Init();
1703 
1711  void Close();
1712 
1713  SubObjectSubscription(const RR_SHARED_PTR<ServiceSubscription>& parent, boost::string_ref servicepath,
1714  boost::string_ref objecttype);
1715 
1716  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1717 
1718  protected:
1719  RR_SHARED_PTR<RRObject> GetDefaultClientBase();
1720  bool TryGetDefaultClientBase(RR_SHARED_PTR<RRObject>& client_out);
1721 
1722  RR_SHARED_PTR<RRObject> GetDefaultClientWaitBase(int32_t timeout = RR_TIMEOUT_INFINITE);
1723  bool TryGetDefaultClientWaitBase(RR_SHARED_PTR<RRObject>& client_out, int32_t timeout = RR_TIMEOUT_INFINITE);
1724 
1725  void AsyncGetDefaultClientBase(
1726  boost::function<void(const RR_SHARED_PTR<RRObject>&, const RR_SHARED_PTR<RobotRaconteurException>&)> handler,
1727  int32_t timeout = RR_TIMEOUT_INFINITE);
1728 
1729  RR_WEAK_PTR<ServiceSubscription> parent;
1730  RR_WEAK_PTR<RobotRaconteurNode> node;
1731  std::string servicepath;
1732  std::string objecttype;
1733 };
1734 
1742 {
1749 };
1750 
1757 struct ROBOTRACONTEUR_CORE_API ServiceSubscriptionManagerDetails
1758 {
1760  std::string Name;
1764  std::vector<std::string> Urls;
1766  std::string UrlUsername;
1768  RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> > UrlCredentials;
1770  std::vector<std::string> ServiceTypes;
1772  RR_SHARED_PTR<ServiceSubscriptionFilter> Filter;
1774  bool Enabled;
1775 
1778 
1792  const boost::string_ref& Name,
1794  ServiceSubscriptionManager_CONNECTION_METHOD_DEFAULT,
1795  const std::vector<std::string>& Urls = std::vector<std::string>(), const boost::string_ref& UrlUsername = "",
1796  const RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >& UrlCredentials =
1797  RR_INTRUSIVE_PTR<RRMap<std::string, RRValue> >(),
1798  const std::vector<std::string>& ServiceTypes = std::vector<std::string>(),
1799  const RR_SHARED_PTR<ServiceSubscriptionFilter>& Filter = RR_SHARED_PTR<ServiceSubscriptionFilter>(),
1800  bool Enabled = true);
1801 };
1802 
1812 class ROBOTRACONTEUR_CORE_API ServiceSubscriptionManager
1813 {
1814  public:
1820  ServiceSubscriptionManager(const RR_SHARED_PTR<RobotRaconteurNode>& node = RobotRaconteurNode::sp());
1821 
1822  virtual ~ServiceSubscriptionManager();
1823 
1829  void Init(const std::vector<ServiceSubscriptionManagerDetails>& details);
1830 
1837 
1844  void RemoveSubscription(const boost::string_ref& name, bool close = true);
1845 
1851  void EnableSubscription(const boost::string_ref& name);
1852 
1859  void DisableSubscription(const boost::string_ref& name, bool close = true);
1860 
1868  RR_SHARED_PTR<ServiceSubscription> GetSubscription(const boost::string_ref& name, bool force_create = true);
1869 
1876  bool IsConnected(const boost::string_ref& name);
1877 
1884  bool IsEnabled(const boost::string_ref& name);
1885 
1891  void Close(bool close_subscriptions = true);
1892 
1898  std::vector<std::string> GetSubscriptionNames();
1899 
1905  std::vector<ServiceSubscriptionManagerDetails> GetSubscriptionDetails();
1906 
1912  RR_SHARED_PTR<RobotRaconteurNode> GetNode();
1913 
1914  protected:
1915  RR_WEAK_PTR<RobotRaconteurNode> node;
1916 
1917  boost::mutex this_lock;
1918 
1919  boost::unordered_map<std::string, detail::ServiceSubscriptionManager_subscription> subscriptions;
1920 
1921  RR_SHARED_PTR<ServiceSubscription> CreateSubscription(const ServiceSubscriptionManagerDetails& details);
1922 
1923  void UpdateSubscription(detail::ServiceSubscriptionManager_subscription& sub,
1924  const ServiceSubscriptionManagerDetails& details, bool close = false);
1925 };
1926 
1927 namespace detail
1928 {
1929 class ROBOTRACONTEUR_CORE_API WireSubscription_send_iterator
1930 {
1931  protected:
1932  RR_SHARED_PTR<WireSubscriptionBase> subscription;
1933  boost::mutex::scoped_lock subscription_lock;
1934  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<WireSubscription_connection> >::iterator
1935  connections_iterator;
1936  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<WireSubscription_connection> >::iterator
1937  current_connection;
1938 
1939  public:
1940  WireSubscription_send_iterator(const RR_SHARED_PTR<WireSubscriptionBase>& subscription);
1941  RR_SHARED_PTR<WireConnectionBase> Next();
1942  void SetOutValue(const RR_INTRUSIVE_PTR<RRValue>& value);
1943  virtual ~WireSubscription_send_iterator();
1944 };
1945 
1946 class ROBOTRACONTEUR_CORE_API PipeSubscription_send_iterator
1947 {
1948  protected:
1949  RR_SHARED_PTR<PipeSubscriptionBase> subscription;
1950  boost::mutex::scoped_lock subscription_lock;
1951  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<PipeSubscription_connection> >::iterator
1952  connections_iterator;
1953  boost::unordered_map<ServiceSubscriptionClientID, RR_SHARED_PTR<PipeSubscription_connection> >::iterator
1954  current_connection;
1955 
1956  public:
1957  PipeSubscription_send_iterator(const RR_SHARED_PTR<PipeSubscriptionBase>& subscription);
1958  RR_SHARED_PTR<PipeEndpointBase> Next();
1959  void AsyncSendPacket(const RR_INTRUSIVE_PTR<RRValue>& packet);
1960  virtual ~PipeSubscription_send_iterator();
1961 };
1962 
1963 class ROBOTRACONTEUR_CORE_API ServiceSubscription_custom_member_subscribers
1964 {
1965  public:
1966  static void SubscribeWire(const RR_SHARED_PTR<ServiceSubscription>& s,
1967  const RR_SHARED_PTR<WireSubscriptionBase>& o);
1968  static void SubscribePipe(const RR_SHARED_PTR<ServiceSubscription>& s,
1969  const RR_SHARED_PTR<PipeSubscriptionBase>& o);
1970 };
1971 } // namespace detail
1972 
1973 #ifndef ROBOTRACONTEUR_NO_CXX11_TEMPLATE_ALIASES
1975 using ServiceSubscriptionFilterNodePtr = RR_SHARED_PTR<ServiceSubscriptionFilterNode>;
1977 using ServiceSubscriptionFilterPtr = RR_SHARED_PTR<ServiceSubscriptionFilter>;
1979 using ServiceInfo2SubscriptionPtr = RR_SHARED_PTR<ServiceInfo2Subscription>;
1981 using ServiceSubscriptionPtr = RR_SHARED_PTR<ServiceSubscription>;
1983 template <typename T>
1984 using PipeSubscriptionPtr = RR_SHARED_PTR<PipeSubscription<T> >;
1986 template <typename T>
1987 using WireSubscriptionPtr = RR_SHARED_PTR<WireSubscription<T> >;
1989 using SubObjectSubscriptionPtr = RR_SHARED_PTR<SubObjectSubscription>;
1990 #endif
1991 
1992 } // namespace RobotRaconteur
ClientServiceListenerEventType
Enum of client listener events.
Definition: RobotRaconteurConstants.h:500
#define RR_TIMEOUT_INFINITE
Disable timeout for asynchronous operations.
Definition: RobotRaconteurConstants.h:566
boost::shared_ptr< ServiceInfo2Subscription > ServiceInfo2SubscriptionPtr
Convenience alias for ServiceInfo2Subscription shared_ptr.
Definition: Subscription.h:1979
boost::shared_ptr< ServiceSubscription > ServiceSubscriptionPtr
Convenience alias for ServiceSubscription shared_ptr.
Definition: Subscription.h:1981
boost::shared_ptr< ServiceSubscriptionFilterNode > ServiceSubscriptionFilterNodePtr
Convenience alias for ServiceSubscriptionFilterNode shared_ptr.
Definition: Subscription.h:1975
ServiceSubscriptionFilterAttribute CreateServiceSubscriptionFilterAttributeIdentifier(boost::string_ref identifier_name, boost::string_ref uuid_string)
Create a ServiceSubscriptionFilterAttribute from an identifier.
boost::shared_ptr< SubObjectSubscription > SubObjectSubscriptionPtr
Convenience alias for SubObjectSubscription shared_ptr.
Definition: Subscription.h:1989
boost::shared_ptr< WireSubscription< T > > WireSubscriptionPtr
Convenience alias for WireSubscription shared_ptr.
Definition: Subscription.h:1987
ServiceSubscriptionFilterAttribute CreateServiceSubscriptionFilterAttributeRegex(boost::string_ref regex_value)
Create a ServiceSubscriptionFilterAttribute from a regex string.
boost::shared_ptr< PipeSubscription< T > > PipeSubscriptionPtr
Convenience alias for PipeSubscription shared_ptr.
Definition: Subscription.h:1984
ServiceSubscriptionManager_CONNECTION_METHOD
Connection method for ServiceSubscriptionManager subscription.
Definition: Subscription.h:1742
@ ServiceSubscriptionManager_CONNECTION_METHOD_URL
Use URLs types for subscription.
Definition: Subscription.h:1746
@ ServiceSubscriptionManager_CONNECTION_METHOD_TYPE
Use service types for subscription.
Definition: Subscription.h:1748
@ ServiceSubscriptionManager_CONNECTION_METHOD_DEFAULT
Implicitly select between URL and service types.
Definition: Subscription.h:1744
boost::shared_ptr< ServiceSubscriptionFilter > ServiceSubscriptionFilterPtr
Convenience alias for ServiceSubscriptionFilter shared_ptr.
Definition: Subscription.h:1977
ServiceSubscriptionFilterAttributeGroupOperation
Comparison operations for ServiceSubscriptionFilterAttributeGroup.
Definition: Subscription.h:249
@ ServiceSubscriptionFilterAttributeGroupOperation_NAND
NAND operation.
Definition: Subscription.h:257
@ ServiceSubscriptionFilterAttributeGroupOperation_AND
AND operation.
Definition: Subscription.h:253
@ ServiceSubscriptionFilterAttributeGroupOperation_NOR
NOR operation. Also used for NOT.
Definition: Subscription.h:255
@ ServiceSubscriptionFilterAttributeGroupOperation_OR
OR operation.
Definition: Subscription.h:251
ServiceSubscriptionFilterAttribute CreateServiceSubscriptionFilterAttributeCombinedIdentifier(boost::string_ref combined_identifier)
Create a ServiceSubscriptionFilterAttribute from a combined identifier string.
NodeID UUID storage and generation.
Definition: NodeID.h:58
Pipe endpoint used to transmit reliable or unreliable data streams.
Definition: PipeMember.h:282
Base class for PipeSubscription.
Definition: Subscription.h:1337
size_t Available()
Get the number of packets available to receive.
void Close()
Closes the pipe subscription.
void SetIgnoreReceived(bool ignore)
Set if incoming packets should be ignored.
bool GetIgnoreReceived()
Get if incoming packets are currently being ignored.
size_t GetActivePipeEndpointCount()
Get the number of pipe endpoints currently connected.
Subscription for pipe members that aggregates incoming packets from client pipe endpoints.
Definition: Subscription.h:1460
event_connection AddPipePacketReceivedListener(boost::function< void(const boost::shared_ptr< PipeSubscription< T > > &)> f)
Adds a pipe packet received event listener function.
Definition: Subscription.h:1548
T ReceivePacket()
Dequeue a packet from the receive queue.
Definition: Subscription.h:1476
bool TryReceivePacketWait(T &packet, int32_t timeout=RR_TIMEOUT_INFINITE, bool peek=false, boost::shared_ptr< PipeEndpoint< T > > *ep=NULL)
Try dequeuing a packet from the receive queue, optionally waiting or peeking the packet.
Definition: Subscription.h:1509
void AsyncSendPacketAll(const T &packet)
Sends a packet to all connected pipe endpoints.
Definition: Subscription.h:1532
bool TryReceivePacket(T &packet)
Try dequeuing a packet from the receive queue.
Definition: Subscription.h:1489
Numeric primitive or character array value type.
Definition: DataTypes.h:580
List container value type.
Definition: DataTypes.h:921
Map container value type.
Definition: DataTypes.h:795
Base class for all Robot Raconteur objects.
Definition: DataTypes.h:227
The central node implementation.
Definition: RobotRaconteurNode.h:132
static boost::shared_ptr< RobotRaconteurNode > sp()
Singleton shared_ptr accessor.
Contains information about a service found using discovery.
Definition: Discovery.h:49
Subscription for information about detected services.
Definition: Subscription.h:463
event_connection AddServiceLostListener(boost::function< void(const boost::shared_ptr< ServiceInfo2Subscription > &, const ServiceSubscriptionClientID &, const ServiceInfo2 &)> handler)
Add a listener callback that is invoked when a service is lost.
std::map< ServiceSubscriptionClientID, ServiceInfo2 > GetDetectedServiceInfo2()
Returns a map of detected services.
event_connection AddServiceDetectedListener(boost::function< void(const boost::shared_ptr< ServiceInfo2Subscription > &, const ServiceSubscriptionClientID &, const ServiceInfo2 &)> handler)
Add a listener callback that is invoked when a service is detected.
ClientID for use with ServiceSubscription.
Definition: Subscription.h:401
ServiceSubscriptionClientID(const ::RobotRaconteur::NodeID &nodeid, boost::string_ref service_name)
Construct a ServiceSubscriptionClientID.
std::string ServiceName
Definition: Subscription.h:406
bool operator!=(const ServiceSubscriptionClientID &id2) const
bool operator<(const ServiceSubscriptionClientID &id2) const
::RobotRaconteur::NodeID NodeID
Definition: Subscription.h:404
ServiceSubscriptionClientID()
Construct an empty ServiceSubscriptionClientID.
bool operator==(const ServiceSubscriptionClientID &id2) const
Subscription filter attribute group for use with ServiceSubscriptionFilter.
Definition: Subscription.h:267
bool SplitStringAttribute
True if string attributes will be split into a list with delimiter (default ",")
Definition: Subscription.h:277
bool IsMatch(const std::vector< std::string > &values) const
Compare the group to a list of values.
bool IsMatch(const boost::intrusive_ptr< RRList< RRValue > > &values) const
Compare the group to a list of values.
bool IsMatch(boost::string_ref value) const
Compare the group to a value.
std::vector< ServiceSubscriptionFilterAttributeGroup > Groups
The nested groups in the group.
Definition: Subscription.h:272
ServiceSubscriptionFilterAttributeGroupOperation Operation
The operation to use for matching the attributes and groups.
Definition: Subscription.h:274
ServiceSubscriptionFilterAttributeGroup()
Construct a new Service Subscription Filter Attribute Group object.
ServiceSubscriptionFilterAttributeGroup(ServiceSubscriptionFilterAttributeGroupOperation operation, std::vector< ServiceSubscriptionFilterAttribute > attributes)
Construct a new Service Subscription Filter Attribute Group object.
char SplitStringDelimiter
Delimiter to use to split string attributes (default ",")
Definition: Subscription.h:279
ServiceSubscriptionFilterAttributeGroup(ServiceSubscriptionFilterAttributeGroupOperation operation)
Construct a new Service Subscription Filter Attribute Group object.
bool IsMatch(const boost::intrusive_ptr< RRMap< std::string, RRValue > > &values) const
Compare the group to a map of values.
bool IsMatch(boost::intrusive_ptr< RRArray< char > > &value) const
Compare the group to a value.
std::vector< ServiceSubscriptionFilterAttribute > Attributes
The attributes in the group.
Definition: Subscription.h:270
bool IsMatch(const std::map< std::string, std::string > &values) const
Compare the group to a map of values.
ServiceSubscriptionFilterAttributeGroup(ServiceSubscriptionFilterAttributeGroupOperation operation, std::vector< ServiceSubscriptionFilterAttributeGroup > groups)
Construct a new Service Subscription Filter Attribute Group object.
Subscription filter attribute for use with ServiceSubscriptionFilter.
Definition: Subscription.h:92
bool IsMatch(const std::map< std::string, std::string > &values) const
Compare the attribute to a value map using OR logic.
bool IsMatch(boost::string_ref value) const
Compare the attribute to a value.
bool IsMatch(const boost::intrusive_ptr< RRList< RRValue > > &values) const
Compare the attribute to a value list using OR logic.
bool IsMatch(boost::string_ref name, boost::string_ref value) const
Compare the attribute to a named value.
std::string Name
The attribute name. Empty for no name.
Definition: Subscription.h:95
ServiceSubscriptionFilterAttribute(boost::string_ref value)
Construct a new Service Subscription Filter Attribute object.
bool IsMatch(const std::vector< std::string > &values) const
Compare the attribute to a value list using OR logic.
std::string Value
The string value of the attribute.
Definition: Subscription.h:97
ServiceSubscriptionFilterAttribute(boost::string_ref name, boost::string_ref value)
Construct a new Service Subscription Filter Attribute object.
bool UseRegex
True if ValueRegex is used, otherwise Value is matched.
Definition: Subscription.h:101
ServiceSubscriptionFilterAttribute(boost::string_ref name, const boost::regex &value_regex)
Construct a new Service Subscription Filter Attribute object.
bool IsMatch(const boost::intrusive_ptr< RRMap< std::string, RRValue > > &values) const
Compare the attribute to a value map using OR logic.
ServiceSubscriptionFilterAttribute()
Construct a new Service Subscription Filter Attribute object.
boost::regex ValueRegex
The regex value of the attribute.
Definition: Subscription.h:99
ServiceSubscriptionFilterAttribute(const boost::regex &value_regex)
Construct a new Service Subscription Filter Attribute object.
Subscription filter.
Definition: Subscription.h:373
ServiceSubscriptionFilterAttributeGroupOperation AttributesMatchOperation
Definition: Subscription.h:384
std::map< std::string, ServiceSubscriptionFilterAttributeGroup > Attributes
Definition: Subscription.h:382
boost::function< bool(const ServiceInfo2 &)> Predicate
Definition: Subscription.h:386
std::vector< std::string > ServiceNames
Definition: Subscription.h:378
std::vector< boost::shared_ptr< ServiceSubscriptionFilterNode > > Nodes
Definition: Subscription.h:376
uint32_t MaxConnections
Definition: Subscription.h:388
std::vector< std::string > TransportSchemes
Definition: Subscription.h:380
Subscription filter node information.
Definition: Subscription.h:75
boost::intrusive_ptr< RRMap< std::string, RRValue > > Credentials
Definition: Subscription.h:84
::RobotRaconteur::NodeID NodeID
Definition: Subscription.h:78
std::string Username
Definition: Subscription.h:82
std::string NodeName
Definition: Subscription.h:80
Subscription that automatically connects services and manages lifecycle of connected services.
Definition: Subscription.h:613
boost::shared_ptr< SubObjectSubscription > SubscribeSubObject(boost::string_ref servicepath, boost::string_ref objecttype="")
Creates a sub object subscription.
std::vector< std::string > GetServiceURL()
Get the service connection URL.
bool TryGetDefaultClientWait(boost::shared_ptr< T > &client_out, int32_t timeout=RR_TIMEOUT_INFINITE)
Try getting the "default client" connection, waiting with timeout if not connected.
Definition: Subscription.h:875
void UpdateServiceURL(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 object_type="", bool close_connected=false)
Update the service connection URL.
boost::shared_ptr< T > GetDefaultClientWait(int32_t timeout=RR_TIMEOUT_INFINITE)
Get the "default client" connection, waiting with timeout if not connected.
Definition: Subscription.h:857
boost::shared_ptr< PipeSubscription< T > > SubscribePipe(boost::string_ref membername, boost::string_ref servicepath="", uint32_t max_recv_packets=std::numeric_limits< uint32_t >::max())
Creates a pipe subscription.
Definition: Subscription.h:783
event_connection AddClientConnectFailedListener(boost::function< void(const boost::shared_ptr< ServiceSubscription > &, const ServiceSubscriptionClientID &, const std::vector< std::string > &, const boost::shared_ptr< RobotRaconteurException > &)> handler)
Add a listener callback that is invoked when a client connection attempt fails.
bool TryGetDefaultClient(boost::shared_ptr< T > &client_out)
Try getting the "default client" connection.
Definition: Subscription.h:825
void UpdateServiceByType(const std::vector< std::string > &service_types, const boost::shared_ptr< ServiceSubscriptionFilter > &filter=boost::shared_ptr< ServiceSubscriptionFilter >())
Update the service type and filter for subscription.
event_connection AddClientConnectListener(boost::function< void(const boost::shared_ptr< ServiceSubscription > &, const ServiceSubscriptionClientID &, const boost::shared_ptr< RRObject > &)> handler)
Add a listener callback that is invoked when a client is connected.
event_connection AddClientDisconnectListener(boost::function< void(const boost::shared_ptr< ServiceSubscription > &, const ServiceSubscriptionClientID &, const boost::shared_ptr< RRObject > &)> handler)
Add a listener callback that is invoked when a client is disconnected.
void UpdateServiceURL(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::string_ref object_type="", bool close_connected=false)
Update the service connection URL.
void AsyncGetDefaultClient(boost::function< void(const boost::shared_ptr< T > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously get the default client, with optional timeout.
Definition: Subscription.h:900
boost::shared_ptr< T > GetDefaultClient()
Get the "default client" connection.
Definition: Subscription.h:808
std::map< ServiceSubscriptionClientID, boost::shared_ptr< RRObject > > GetConnectedClients()
Returns a map of connected clients.
Class to manage multiple subscriptions to services.
Definition: Subscription.h:1813
std::vector< std::string > GetSubscriptionNames()
Get the names of all subscriptions.
bool IsEnabled(const boost::string_ref &name)
Get if a subscription is enabled.
void EnableSubscription(const boost::string_ref &name)
Enable a subscription.
ServiceSubscriptionManager(const boost::shared_ptr< RobotRaconteurNode > &node=RobotRaconteurNode::sp())
Construct a new ServiceSubscriptionManager object.
void DisableSubscription(const boost::string_ref &name, bool close=true)
Disable a subscription.
void RemoveSubscription(const boost::string_ref &name, bool close=true)
Remove a subscription from the manager.
std::vector< ServiceSubscriptionManagerDetails > GetSubscriptionDetails()
Get the details of all subscriptions.
void AddSubscription(const ServiceSubscriptionManagerDetails &details)
Add a subscription to the manager.
void Close(bool close_subscriptions=true)
Close the subscription manager.
bool IsConnected(const boost::string_ref &name)
Get if a subscription is connected.
void Init(const std::vector< ServiceSubscriptionManagerDetails > &details)
Initialize the subscription manager with a list of subscriptions.
boost::shared_ptr< RobotRaconteurNode > GetNode()
Get the node used by the subscription manager.
boost::shared_ptr< ServiceSubscription > GetSubscription(const boost::string_ref &name, bool force_create=true)
Get a subscription by name.
Subscription for sub objects of the default client.
Definition: Subscription.h:1580
boost::shared_ptr< T > GetDefaultClientWait(int32_t timeout=RR_TIMEOUT_INFINITE)
Get the "default client" sub object, waiting for a specified timeout.
Definition: Subscription.h:1648
bool TryGetDefaultClientWait(boost::shared_ptr< T > &client_out, int32_t timeout=RR_TIMEOUT_INFINITE)
Try getting the "default client" sub object, waiting for a specified timeout.
Definition: Subscription.h:1666
boost::shared_ptr< T > GetDefaultClient()
Get the "default client" sub object.
Definition: Subscription.h:1600
void AsyncGetDefaultClient(boost::function< void(const boost::shared_ptr< T > &, const boost::shared_ptr< RobotRaconteurException > &)> handler, int32_t timeout=RR_TIMEOUT_INFINITE)
Asynchronously get the "default client" sub object.
Definition: Subscription.h:1693
bool TryGetDefaultClient(boost::shared_ptr< T > &client_out)
Try getting the "default client" sub object.
Definition: Subscription.h:1617
void Close()
Closes the sub object subscription.
Represents. a point in time. Used by wire members to timestamp packets.
Definition: DataTypes.h:2666
Base class for WireConnection.
Definition: WireMember.h:58
Wire connection used to transmit "most recent" values.
Definition: WireMember.h:350
Base class for WireSubscription.
Definition: Subscription.h:1083
size_t GetActiveWireConnectionCount()
Get the number of wire connections currently connected.
bool WaitInValueValid(int32_t timeout=RR_TIMEOUT_INFINITE)
Wait for a valid InValue to be received from a client.
void SetIgnoreInValue(bool ignore)
Set if InValue should be ignored.
void Close()
Closes the wire subscription.
void SetInValueLifespan(int32_t millis)
Set the InValue lifespan in milliseconds.
int32_t GetInValueLifespan()
Get the InValue lifespan in milliseconds.
bool GetIgnoreInValue()
Get if InValue is currently being ignored.
Subscription for wire members that aggregates the values from client wire connections.
Definition: Subscription.h:1233
bool TryGetInValue(T &val, TimeSpec *time=NULL, typename boost::shared_ptr< WireConnection< T > > *connection=NULL)
Try getting the current InValue and metadata.
Definition: Subscription.h:1272
T GetInValue(TimeSpec *time=NULL, typename boost::shared_ptr< WireConnection< T > > *connection=NULL)
Get the current InValue and metadata.
Definition: Subscription.h:1249
void SetOutValueAll(const T &val)
Set the OutValue for all active wire connections.
Definition: Subscription.h:1295
event_connection AddWireValueChangedListener(boost::function< void(const boost::shared_ptr< WireSubscription< T > > &, const T &, const TimeSpec &)> f)
Adds a wire value changed event listener function.
Definition: Subscription.h:1308
ServiceSubscriptionManager subscription connection information.
Definition: Subscription.h:1758
bool Enabled
If the subscription is enabled.
Definition: Subscription.h:1774
boost::shared_ptr< ServiceSubscriptionFilter > Filter
The filter to use for subscription when service type is used (optional)
Definition: Subscription.h:1772
ServiceSubscriptionManager_CONNECTION_METHOD ConnectionMethod
The connection method to use, URL or service type.
Definition: Subscription.h:1762
std::vector< std::string > Urls
The URLs to use for subscription.
Definition: Subscription.h:1764
ServiceSubscriptionManagerDetails(const boost::string_ref &Name, ServiceSubscriptionManager_CONNECTION_METHOD ConnectionMethod=ServiceSubscriptionManager_CONNECTION_METHOD_DEFAULT, const std::vector< std::string > &Urls=std::vector< std::string >(), const boost::string_ref &UrlUsername="", const boost::intrusive_ptr< RRMap< std::string, RRValue > > &UrlCredentials=boost::intrusive_ptr< RRMap< std::string, RRValue > >(), const std::vector< std::string > &ServiceTypes=std::vector< std::string >(), const boost::shared_ptr< ServiceSubscriptionFilter > &Filter=boost::shared_ptr< ServiceSubscriptionFilter >(), bool Enabled=true)
Construct a new ServiceSubscriptionManagerDetails object with parameters.
std::string UrlUsername
The username to use for URLs (optional)
Definition: Subscription.h:1766
std::string Name
The local name of the subscription.
Definition: Subscription.h:1760
std::vector< std::string > ServiceTypes
The service types to use for subscription.
Definition: Subscription.h:1770
boost::intrusive_ptr< RRMap< std::string, RRValue > > UrlCredentials
The credentials to use for URLs (optional)
Definition: Subscription.h:1768
ServiceSubscriptionManagerDetails()
Construct a new ServiceSubscriptionManagerDetails object.