All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Node.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGN_TRANSPORT_NODE_HH_
18 #define IGN_TRANSPORT_NODE_HH_
19 
20 #include <algorithm>
21 #include <functional>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <unordered_set>
26 #include <vector>
27 
28 // ToDo: Remove after fixing the warnings
29 #ifdef _MSC_VER
30 #pragma warning(push, 0)
31 #endif
32 #include <ignition/msgs.hh>
33 #ifdef _MSC_VER
34 #pragma warning(pop)
35 #endif
36 
48 
49 namespace ignition
50 {
51  namespace transport
52  {
53  class NodePrivate;
54 
59 
65  {
66  class PublisherPrivate;
67 
81  public: class Publisher
82  {
84  public: Publisher();
85 
88  public: explicit Publisher(const MessagePublisher &_publisher);
89 
91  public: virtual ~Publisher();
92 
96  public: operator bool();
97 
101  public: bool Valid() const;
102 
106  public: bool Publish(const ProtoMsg &_msg);
107 
111  private: bool UpdateThrottling();
112 
115  public: bool HasConnections() const;
116 
122  private: std::shared_ptr<PublisherPrivate> dataPtr;
123  };
124 
127  public: explicit Node(const NodeOptions &_options = NodeOptions());
128 
130  public: virtual ~Node();
131 
140  public: template<typename T> Node::Publisher Advertise(
141  const std::string &_topic,
143  {
144  return this->Advertise(_topic, T().GetTypeName(), _options);
145  }
146 
158  public: Node::Publisher Advertise(const std::string &_topic,
159  const std::string &_msgTypeName,
161  {
162  std::string fullyQualifiedTopic;
163  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
164  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
165  {
166  std::cerr << "Topic [" << _topic << "] is not valid." << std::endl;
167  return Publisher();
168  }
169 
170  auto currentTopics = this->AdvertisedTopics();
171 
172  if (std::find(currentTopics.begin(), currentTopics.end(),
173  fullyQualifiedTopic) != currentTopics.end())
174  {
175  std::cerr << "Topic [" << _topic << "] already advertised. You cannot"
176  << " advertise the same topic twice on the same node."
177  << " If you want to advertise the same topic with different"
178  << " types, use separate nodes" << std::endl;
179  return Publisher();
180  }
181 
182  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
183 
184  // Notify the discovery service to register and advertise my topic.
185  MessagePublisher publisher(fullyQualifiedTopic,
186  this->Shared()->myAddress,
187  this->Shared()->myControlAddress,
188  this->Shared()->pUuid, this->NodeUuid(), _msgTypeName, _options);
189 
190  if (!this->Shared()->msgDiscovery->Advertise(publisher))
191  {
192  std::cerr << "Node::Advertise(): Error advertising a topic. "
193  << "Did you forget to start the discovery service?"
194  << std::endl;
195  return Publisher();
196  }
197 
198  return Publisher(publisher);
199  }
200 
203  public: std::vector<std::string> AdvertisedTopics() const;
204 
214  public: template<typename T> bool Subscribe(
215  const std::string &_topic,
216  void(*_cb)(const T &_msg),
217  const SubscribeOptions &_opts = SubscribeOptions())
218  {
219  std::function<void(const T &, const MessageInfo &)> f =
220  [_cb](const T & _internalMsg, const MessageInfo &/*_internalInfo*/)
221  {
222  (*_cb)(_internalMsg);
223  };
224 
225  return this->Subscribe<T>(_topic, f, _opts);
226  }
227 
236  public: template<typename T> bool Subscribe(
237  const std::string &_topic,
238  std::function<void(const T &_msg)> &_cb,
239  const SubscribeOptions &_opts = SubscribeOptions())
240  {
241  std::function<void(const T &, const MessageInfo &)> f =
242  [_cb](const T & _internalMsg, const MessageInfo &/*_internalInfo*/)
243  {
244  _cb(_internalMsg);
245  };
246 
247  return this->Subscribe<T>(_topic, f, _opts);
248  }
249 
260  public: template<typename C, typename T> bool Subscribe(
261  const std::string &_topic,
262  void(C::*_cb)(const T &_msg),
263  C *_obj,
264  const SubscribeOptions &_opts = SubscribeOptions())
265  {
266  std::function<void(const T &, const MessageInfo &)> f =
267  [_cb, _obj](const T & _internalMsg,
268  const MessageInfo &/*_internalInfo*/)
269  {
270  auto cb = std::bind(_cb, _obj, std::placeholders::_1);
271  cb(_internalMsg);
272  };
273 
274  return this->Subscribe<T>(_topic, f, _opts);
275  }
276 
287  public: template<typename T> bool Subscribe(
288  const std::string &_topic,
289  void(*_cb)(const T &_msg, const MessageInfo &_info),
290  const SubscribeOptions &_opts = SubscribeOptions())
291  {
292  std::function<void(const T &, const MessageInfo &)> f =
293  [_cb](const T & _internalMsg, const MessageInfo &_internalInfo)
294  {
295  (*_cb)(_internalMsg, _internalInfo);
296  };
297 
298  return this->Subscribe<T>(_topic, f, _opts);
299  }
300 
310  public: template<typename T> bool Subscribe(
311  const std::string &_topic,
312  std::function<void(const T &_msg, const MessageInfo &_info)> &_cb,
313  const SubscribeOptions &_opts = SubscribeOptions())
314  {
315  std::string fullyQualifiedTopic;
316  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
317  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
318  {
319  std::cerr << "Topic [" << _topic << "] is not valid." << std::endl;
320  return false;
321  }
322 
323  // Create a new subscription handler.
324  std::shared_ptr<SubscriptionHandler<T>> subscrHandlerPtr(
325  new SubscriptionHandler<T>(this->NodeUuid(), _opts));
326 
327  // Insert the callback into the handler.
328  subscrHandlerPtr->SetCallback(_cb);
329 
330  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
331 
332  // Store the subscription handler. Each subscription handler is
333  // associated with a topic. When the receiving thread gets new data,
334  // it will recover the subscription handler associated to the topic and
335  // will invoke the callback.
336  this->Shared()->localSubscriptions.AddHandler(
337  fullyQualifiedTopic, this->NodeUuid(), subscrHandlerPtr);
338 
339  // Add the topic to the list of subscribed topics (if it was not before)
340  this->TopicsSubscribed().insert(fullyQualifiedTopic);
341 
342  // Discover the list of nodes that publish on the topic.
343  if (!this->Shared()->msgDiscovery->Discover(fullyQualifiedTopic))
344  {
345  std::cerr << "Node::Subscribe(): Error discovering a topic. "
346  << "Did you forget to start the discovery service?"
347  << std::endl;
348  return false;
349  }
350 
351  return true;
352  }
353 
365  public: template<typename C, typename T> bool Subscribe(
366  const std::string &_topic,
367  void(C::*_cb)(const T &_msg, const MessageInfo &_info),
368  C *_obj,
369  const SubscribeOptions &_opts = SubscribeOptions())
370  {
371  std::function<void(const T &, const MessageInfo &)> f =
372  [_cb, _obj](const T & _internalMsg, const MessageInfo &_internalInfo)
373  {
374  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
375  std::placeholders::_2);
376  cb(_internalMsg, _internalInfo);
377  };
378 
379  return this->Subscribe<T>(_topic, f, _opts);
380  }
381 
387  public: std::vector<std::string> SubscribedTopics() const;
388 
392  public: bool Unsubscribe(const std::string &_topic);
393 
406  public: template<typename T1, typename T2> bool Advertise(
407  const std::string &_topic,
408  void(*_cb)(const T1 &_req, T2 &_rep, bool &_result),
410  {
411  std::function<void(const T1 &, T2 &, bool &)> f =
412  [_cb](const T1 &_internalReq, T2 &_internalRep, bool &_internalResult)
413  {
414  (*_cb)(_internalReq, _internalRep, _internalResult);
415  };
416 
417  return this->Advertise<T1, T2>(_topic, f, _options);
418  }
419 
431  public: template<typename T> bool Advertise(
432  const std::string &_topic,
433  void(*_cb)(T &_rep, bool &_result),
435  {
436  std::function<void(const msgs::Empty &, T &, bool &)> f =
437  [_cb](const msgs::Empty &/*_internalReq*/, T &_internalRep,
438  bool &_internalResult)
439  {
440  (*_cb)(_internalRep, _internalResult);
441  };
442  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
443  }
444 
455  public: template<typename T> bool Advertise(
456  const std::string &_topic,
457  void(*_cb)(const T &_req),
459  {
460  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
461  [_cb](const T &_internalReq, ignition::msgs::Empty &/*_internalRep*/,
462  bool &/*_internalResult*/)
463  {
464  (*_cb)(_internalReq);
465  };
466 
467  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
468  }
469 
482  public: template<typename T1, typename T2> bool Advertise(
483  const std::string &_topic,
484  std::function<void(const T1 &_req, T2 &_rep, bool &_result)> &_cb,
486  {
487  std::string fullyQualifiedTopic;
488  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
489  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
490  {
491  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
492  return false;
493  }
494 
495  // Create a new service reply handler.
496  std::shared_ptr<RepHandler<T1, T2>> repHandlerPtr(
497  new RepHandler<T1, T2>());
498 
499  // Insert the callback into the handler.
500  repHandlerPtr->SetCallback(_cb);
501 
502  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
503 
504  // Add the topic to the list of advertised services.
505  this->SrvsAdvertised().insert(fullyQualifiedTopic);
506 
507  // Store the replier handler. Each replier handler is
508  // associated with a topic. When the receiving thread gets new requests,
509  // it will recover the replier handler associated to the topic and
510  // will invoke the service call.
511  this->Shared()->repliers.AddHandler(
512  fullyQualifiedTopic, this->NodeUuid(), repHandlerPtr);
513 
514  // Notify the discovery service to register and advertise my responser.
515  ServicePublisher publisher(fullyQualifiedTopic,
516  this->Shared()->myReplierAddress,
517  this->Shared()->replierId.ToString(),
518  this->Shared()->pUuid, this->NodeUuid(),
519  T1().GetTypeName(), T2().GetTypeName(), _options);
520 
521  if (!this->Shared()->srvDiscovery->Advertise(publisher))
522  {
523  std::cerr << "Node::Advertise(): Error advertising a service. "
524  << "Did you forget to start the discovery service?"
525  << std::endl;
526  return false;
527  }
528 
529  return true;
530  }
531 
543  public: template<typename T> bool Advertise(
544  const std::string &_topic,
545  std::function<void(T &_rep, bool &_result)> &_cb,
547  {
548  std::function<void(const msgs::Empty &, T &, bool &)> f =
549  [_cb](const msgs::Empty &/*_internalReq*/, T &_internalRep,
550  bool &_internalResult)
551  {
552  (_cb)(_internalRep, _internalResult);
553  };
554  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
555  }
556 
567  public: template<typename T> bool Advertise(
568  const std::string &_topic,
569  std::function<void(const T &_req)> &_cb,
571  {
572  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
573  [_cb](const T &_internalReq, ignition::msgs::Empty &/*_internalRep*/,
574  bool &/*_internalResult*/)
575  {
576  (_cb)(_internalReq);
577  };
578 
579  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
580  }
581 
595  public: template<typename C, typename T1, typename T2> bool Advertise(
596  const std::string &_topic,
597  void(C::*_cb)(const T1 &_req, T2 &_rep, bool &_result),
598  C *_obj,
600  {
601  std::function<void(const T1 &, T2 &, bool &)> f =
602  [_cb, _obj](const T1 &_internalReq,
603  T2 &_internalRep,
604  bool &_internalResult)
605  {
606  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
607  std::placeholders::_2, std::placeholders::_3);
608  cb(_internalReq, _internalRep, _internalResult);
609  };
610 
611  return this->Advertise<T1, T2>(_topic, f, _options);
612  }
613 
626  public: template<typename C, typename T> bool Advertise(
627  const std::string &_topic,
628  void(C::*_cb)(T &_rep, bool &_result),
629  C *_obj,
631  {
632  std::function<void(const msgs::Empty &, T &, bool &)> f =
633  [_cb, _obj](const msgs::Empty &/*_internalReq*/, T &_internalRep,
634  bool &_internalResult)
635  {
636  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
637  std::placeholders::_2);
638  cb(_internalRep, _internalResult);
639  };
640 
641  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
642  }
643 
655  public: template<typename C, typename T> bool Advertise(
656  const std::string &_topic,
657  void(C::*_cb)(const T &_req),
658  C *_obj,
660  {
661  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
662  [_cb, _obj](const T &_internalReq,
663  ignition::msgs::Empty &/*_internalRep*/,
664  bool &/*_internalResult*/)
665  {
666  auto cb = std::bind(_cb, _obj, std::placeholders::_1);
667  cb(_internalReq);
668  };
669 
670  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
671  }
672 
675  public: std::vector<std::string> AdvertisedServices() const;
676 
687  public: template<typename T1, typename T2> bool Request(
688  const std::string &_topic,
689  const T1 &_req,
690  void(*_cb)(const T2 &_rep, const bool _result))
691  {
692  std::function<void(const T2 &, const bool)> f =
693  [_cb](const T2 &_internalRep, const bool _internalResult)
694  {
695  (*_cb)(_internalRep, _internalResult);
696  };
697 
698  return this->Request<T1, T2>(_topic, _req, f);
699  }
700 
711  public: template<typename T> bool Request(
712  const std::string &_topic,
713  void(*_cb)(const T &_rep, const bool _result))
714  {
715  msgs::Empty req;
716  return this->Request(_topic, req, _cb);
717  }
718 
729  public: template<typename T1, typename T2> bool Request(
730  const std::string &_topic,
731  const T1 &_req,
732  std::function<void(const T2 &_rep, const bool _result)> &_cb)
733  {
734  std::string fullyQualifiedTopic;
735  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
736  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
737  {
738  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
739  return false;
740  }
741 
742  bool localResponserFound;
743  IRepHandlerPtr repHandler;
744  {
745  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
746  localResponserFound = this->Shared()->repliers.FirstHandler(
747  fullyQualifiedTopic, T1().GetTypeName(), T2().GetTypeName(),
748  repHandler);
749  }
750 
751  // If the responser is within my process.
752  if (localResponserFound)
753  {
754  // There is a responser in my process, let's use it.
755  T2 rep;
756  bool result;
757  repHandler->RunLocalCallback(_req, rep, result);
758 
759  _cb(rep, result);
760  return true;
761  }
762 
763  // Create a new request handler.
764  std::shared_ptr<ReqHandler<T1, T2>> reqHandlerPtr(
765  new ReqHandler<T1, T2>(this->NodeUuid()));
766 
767  // Insert the request's parameters.
768  reqHandlerPtr->SetMessage(&_req);
769 
770  // Insert the callback into the handler.
771  reqHandlerPtr->SetCallback(_cb);
772 
773  {
774  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
775 
776  // Store the request handler.
777  this->Shared()->requests.AddHandler(
778  fullyQualifiedTopic, this->NodeUuid(), reqHandlerPtr);
779 
780  // If the responser's address is known, make the request.
781  SrvAddresses_M addresses;
782  if (this->Shared()->srvDiscovery->Publishers(
783  fullyQualifiedTopic, addresses))
784  {
785  this->Shared()->SendPendingRemoteReqs(fullyQualifiedTopic,
786  T1().GetTypeName(), T2().GetTypeName());
787  }
788  else
789  {
790  // Discover the service responser.
791  if (!this->Shared()->srvDiscovery->Discover(fullyQualifiedTopic))
792  {
793  std::cerr << "Node::Request(): Error discovering a service. "
794  << "Did you forget to start the discovery service?"
795  << std::endl;
796  return false;
797  }
798  }
799  }
800 
801  return true;
802  }
803 
814  public: template<typename T> bool Request(
815  const std::string &_topic,
816  std::function<void(const T &_rep, const bool _result)> &_cb)
817  {
818  msgs::Empty req;
819  return this->Request(_topic, req, _cb);
820  }
821 
833  public: template<typename C, typename T1, typename T2> bool Request(
834  const std::string &_topic,
835  const T1 &_req,
836  void(C::*_cb)(const T2 &_rep, const bool _result),
837  C *_obj)
838  {
839  std::function<void(const T2 &, const bool)> f =
840  [_cb, _obj](const T2 &_internalRep, const bool _internalResult)
841  {
842  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
843  std::placeholders::_2);
844  cb(_internalRep, _internalResult);
845  };
846 
847  return this->Request<T1, T2>(_topic, _req, f);
848  }
849 
861  public: template<typename C, typename T> bool Request(
862  const std::string &_topic,
863  void(C::*_cb)(const T &_rep, const bool _result),
864  C *_obj)
865  {
866  msgs::Empty req;
867  return this->Request(_topic, req, _cb, _obj);
868  }
869 
878  public: template<typename T1, typename T2> bool Request(
879  const std::string &_topic,
880  const T1 &_req,
881  const unsigned int &_timeout,
882  T2 &_rep,
883  bool &_result)
884  {
885  std::string fullyQualifiedTopic;
886  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
887  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
888  {
889  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
890  return false;
891  }
892 
893  // Create a new request handler.
894  std::shared_ptr<ReqHandler<T1, T2>> reqHandlerPtr(
895  new ReqHandler<T1, T2>(this->NodeUuid()));
896 
897  // Insert the request's parameters.
898  reqHandlerPtr->SetMessage(&_req);
899  reqHandlerPtr->SetResponse(&_rep);
900 
901  std::unique_lock<std::recursive_mutex> lk(this->Shared()->mutex);
902 
903  // If the responser is within my process.
904  IRepHandlerPtr repHandler;
905  if (this->Shared()->repliers.FirstHandler(fullyQualifiedTopic,
906  _req.GetTypeName(), _rep.GetTypeName(), repHandler))
907  {
908  // There is a responser in my process, let's use it.
909  repHandler->RunLocalCallback(_req, _rep, _result);
910  return true;
911  }
912 
913  // Store the request handler.
914  this->Shared()->requests.AddHandler(
915  fullyQualifiedTopic, this->NodeUuid(), reqHandlerPtr);
916 
917  // If the responser's address is known, make the request.
918  SrvAddresses_M addresses;
919  if (this->Shared()->srvDiscovery->Publishers(
920  fullyQualifiedTopic, addresses))
921  {
922  this->Shared()->SendPendingRemoteReqs(fullyQualifiedTopic,
923  _req.GetTypeName(), _rep.GetTypeName());
924  }
925  else
926  {
927  // Discover the service responser.
928  if (!this->Shared()->srvDiscovery->Discover(fullyQualifiedTopic))
929  {
930  std::cerr << "Node::Request(): Error discovering a service. "
931  << "Did you forget to start the discovery service?"
932  << std::endl;
933  return false;
934  }
935  }
936 
937  // Wait until the REP is available.
938  bool executed = reqHandlerPtr->WaitUntil(lk, _timeout);
939 
940  // The request was not executed.
941  if (!executed)
942  return false;
943 
944  // The request was executed but did not succeed.
945  if (!reqHandlerPtr->Result())
946  {
947  _result = false;
948  return true;
949  }
950 
951  // Parse the response.
952  if (!_rep.ParseFromString(reqHandlerPtr->Response()))
953  {
954  std::cerr << "Node::Request(): Error Parsing the response"
955  << std::endl;
956  _result = false;
957  return true;
958  }
959 
960  _result = true;
961  return true;
962  }
963 
972  public: template<typename T> bool Request(
973  const std::string &_topic,
974  const unsigned int &_timeout,
975  T &_rep,
976  bool &_result)
977  {
978  msgs::Empty req;
979  return this->Request(_topic, req, _timeout, _rep, _result);
980  }
981 
986  public: template<typename T> bool Request(const std::string &_topic,
987  const T &_req)
988  {
989  // This callback is here for reusing the regular Request() call with
990  // input and output parameters.
991  std::function<void(const ignition::msgs::Empty &, const bool)> f =
992  [](const ignition::msgs::Empty &, const bool)
993  {
994  };
995 
996  return this->Request<T, ignition::msgs::Empty>(_topic, _req, f);
997  }
998 
1002  public: bool UnadvertiseSrv(const std::string &_topic);
1003 
1010  public: void TopicList(std::vector<std::string> &_topics) const;
1011 
1016  public: bool TopicInfo(const std::string &_topic,
1017  std::vector<MessagePublisher> &_publishers) const;
1018 
1025  public: void ServiceList(std::vector<std::string> &_services) const;
1026 
1031  public: bool ServiceInfo(const std::string &_service,
1032  std::vector<ServicePublisher> &_publishers) const;
1033 
1036  private: const std::string &Partition() const;
1037 
1040  private: const std::string &NameSpace() const;
1041 
1045  private: NodeShared *Shared() const;
1046 
1049  private: const std::string &NodeUuid() const;
1050 
1053  private: std::unordered_set<std::string> &TopicsSubscribed() const;
1054 
1057  private: std::unordered_set<std::string> &SrvsAdvertised() const;
1058 
1061  private: NodeOptions &Options() const;
1062 
1065  private: std::unique_ptr<transport::NodePrivate> dataPtr;
1066  };
1067  }
1068 }
1069 #endif
static bool FullyQualifiedName(const std::string &_partition, const std::string &_ns, const std::string &_topic, std::string &_name)
Get the full topic path given a namespace and a topic name.
bool Request(const std::string &_topic, std::function< void(const T &_rep, const bool _result)> &_cb)
Request a new service without input parameter using a non-blocking call.
Definition: Node.hh:814
A class for customizing the publication options for a topic advertised.
Definition: AdvertiseOptions.hh:136
bool Request(const std::string &_topic, void(C::*_cb)(const T &_rep, const bool _result), C *_obj)
Request a new service without input parameter using a non-blocking call.
Definition: Node.hh:861
bool Request(const std::string &_topic, const T1 &_req, void(*_cb)(const T2 &_rep, const bool _result))
Request a new service using a non-blocking call.
Definition: Node.hh:687
A class for customizing the behavior of the Node.
Definition: NodeOptions.hh:35
bool Advertise(const std::string &_topic, void(C::*_cb)(const T1 &_req, T2 &_rep, bool &_result), C *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service.
Definition: Node.hh:595
bool Advertise(const std::string &_topic, std::function< void(const T &_req)> &_cb, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:567
It creates a reply handler for the specific protobuf messages used.
Definition: ReqHandler.hh:175
A class that is used to store information about an advertised publisher.
Definition: Node.hh:81
IGNITION_TRANSPORT_VISIBLE void waitForShutdown()
Block the current thread until a SIGINT or SIGTERM is received.
bool Advertise(const std::string &_topic, void(C::*_cb)(const T &_req), C *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:655
bool Subscribe(const std::string &_topic, void(*_cb)(const T &_msg), const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:214
ignition/transport/SubscribeOptions.hh
Definition: SubscribeOptions.hh:35
Node::Publisher Advertise(const std::string &_topic, const AdvertiseMessageOptions &_options=AdvertiseMessageOptions())
Advertise a new topic.
Definition: Node.hh:140
bool Advertise(const std::string &_topic, std::function< void(T &_rep, bool &_result)> &_cb, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without input parameter.
Definition: Node.hh:543
bool Subscribe(const std::string &_topic, std::function< void(const T &_msg)> &_cb, const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:236
Private data for the Node class.
Definition: NodeShared.hh:54
Addresses_M< ServicePublisher > SrvAddresses_M
Definition: TransportTypes.hh:61
A class that provides information about the message received.
Definition: MessageInfo.hh:33
bool Request(const std::string &_topic, void(*_cb)(const T &_rep, const bool _result))
Request a new service without input parameter using a non-blocking call.
Definition: Node.hh:711
bool Advertise(const std::string &_topic, void(*_cb)(const T &_req), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:455
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:65
std::shared_ptr< IRepHandler > IRepHandlerPtr
Definition: TransportTypes.hh:85
bool Request(const std::string &_topic, const T1 &_req, std::function< void(const T2 &_rep, const bool _result)> &_cb)
Request a new service using a non-blocking call.
Definition: Node.hh:729
bool Advertise(const std::string &_topic, void(*_cb)(T &_rep, bool &_result), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without input parameter.
Definition: Node.hh:431
bool Advertise(const std::string &_topic, void(C::*_cb)(T &_rep, bool &_result), C *_obj, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service without input parameter.
Definition: Node.hh:626
bool Subscribe(const std::string &_topic, void(*_cb)(const T &_msg, const MessageInfo &_info), const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:287
A class for customizing the publication options for a service advertised.
Definition: AdvertiseOptions.hh:224
bool Request(const std::string &_topic, const unsigned int &_timeout, T &_rep, bool &_result)
Request a new service without input parameter using a blocking call.
Definition: Node.hh:972
with the service response.
Definition: RepHandler.hh:102
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
A class that allows a client to communicate with other peers.
Definition: Node.hh:64
ignition/transport/Publisher.hh
Definition: Publisher.hh:198
ignition/transport/Publisher.hh
Definition: Publisher.hh:314
bool Subscribe(const std::string &_topic, void(C::*_cb)(const T &_msg, const MessageInfo &_info), C *_obj, const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:365
bool Request(const std::string &_topic, const T &_req)
Request a new service without waiting for response.
Definition: Node.hh:986
bool Advertise(const std::string &_topic, std::function< void(const T1 &_req, T2 &_rep, bool &_result)> &_cb, const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service.
Definition: Node.hh:482
It creates a subscription handler for a specific protobuf message.
Definition: SubscriptionHandler.hh:150
bool Advertise(const std::string &_topic, void(*_cb)(const T1 &_req, T2 &_rep, bool &_result), const AdvertiseServiceOptions &_options=AdvertiseServiceOptions())
Advertise a new service.
Definition: Node.hh:406
bool Request(const std::string &_topic, const T1 &_req, const unsigned int &_timeout, T2 &_rep, bool &_result)
Request a new service using a blocking call.
Definition: Node.hh:878
bool Request(const std::string &_topic, const T1 &_req, void(C::*_cb)(const T2 &_rep, const bool _result), C *_obj)
Request a new service using a non-blocking call.
Definition: Node.hh:833
bool Subscribe(const std::string &_topic, std::function< void(const T &_msg, const MessageInfo &_info)> &_cb, const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:310
bool Subscribe(const std::string &_topic, void(C::*_cb)(const T &_msg), C *_obj, const SubscribeOptions &_opts=SubscribeOptions())
Subscribe to a topic registering a callback.
Definition: Node.hh:260
Node::Publisher Advertise(const std::string &_topic, const std::string &_msgTypeName, const AdvertiseMessageOptions &_options=AdvertiseMessageOptions())
Advertise a new topic.
Definition: Node.hh:158