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 #ifdef _MSC_VER
21 #pragma warning(push, 0)
22 #endif
23 #include <google/protobuf/message.h>
24 #ifdef _MSC_VER
25 #pragma warning(pop)
26 #endif
27 
28 #include <algorithm>
29 #include <functional>
30 #include <map>
31 #include <memory>
32 #include <mutex>
33 #include <string>
34 #include <unordered_set>
35 #include <vector>
36 
37 // ToDo: Remove after fixing the warnings
38 #ifdef _MSC_VER
39 #pragma warning(push, 0)
40 #endif
41 #include <ignition/msgs.hh>
42 #ifdef _MSC_VER
43 #pragma warning(pop)
44 #endif
45 
56 
57 namespace ignition
58 {
59  namespace transport
60  {
61  class NodePrivate;
62 
67 
73  {
86  public: class PublisherId
87  {
89  public: PublisherId();
90 
94  public: explicit PublisherId(const std::string &_topic);
95 
99  public: operator bool();
100 
105  public: bool Valid() const;
106 
110  public: std::string Topic() const;
111 
113  private: std::string topic = "";
114  };
115 
118  public: explicit Node(const NodeOptions &_options = NodeOptions());
119 
121  public: virtual ~Node();
122 
131  public: template<typename T> Node::PublisherId Advertise(
132  const std::string &_topic,
133  const AdvertiseOptions &_options = AdvertiseOptions())
134  {
135  return this->Advertise(_topic, T().GetTypeName(), _options);
136  }
137 
149  public: Node::PublisherId Advertise(const std::string &_topic,
150  const std::string &_msgTypeName,
151  const AdvertiseOptions &_options = AdvertiseOptions())
152  {
153  std::string fullyQualifiedTopic;
154  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
155  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
156  {
157  std::cerr << "Topic [" << _topic << "] is not valid." << std::endl;
158  return PublisherId();
159  }
160 
161  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
162 
163  auto currentTopics = this->TopicsAdvertised();
164 
165  if (currentTopics.find(fullyQualifiedTopic) != currentTopics.end())
166  {
167  std::cerr << "Topic [" << _topic << "] already advertised. You cannot"
168  << " advertise the same topic twice on the same node."
169  << " If you want to advertise the same topic with different"
170  << " types, use separate nodes" << std::endl;
171  return PublisherId();
172  }
173 
174  // Add the topic to the list of advertised topics (if it was not before)
175  this->TopicsAdvertised().insert(fullyQualifiedTopic);
176 
177  // Notify the discovery service to register and advertise my topic.
178  MessagePublisher publisher(fullyQualifiedTopic,
179  this->Shared()->myAddress,
180  this->Shared()->myControlAddress,
181  this->Shared()->pUuid, this->NodeUuid(), _options.Scope(),
182  _msgTypeName);
183 
184  if (!this->Shared()->msgDiscovery->Advertise(publisher))
185  {
186  std::cerr << "Node::Advertise(): Error advertising a topic. "
187  << "Did you forget to start the discovery service?"
188  << std::endl;
189  return PublisherId();
190  }
191 
192  return PublisherId(fullyQualifiedTopic);
193  }
194 
197  public: std::vector<std::string> AdvertisedTopics() const;
198 
202  public: bool Unadvertise(const std::string &_topic);
203 
208  public: bool Publish(const std::string &_topic,
209  const ProtoMsg &_msg);
210 
216  public: bool Publish(const PublisherId &_id,
217  const ProtoMsg &_msg);
218 
226  public: template<typename T> bool Subscribe(
227  const std::string &_topic,
228  void(*_cb)(const T &_msg))
229  {
230  std::function<void(const T &)> f = [_cb](const T & _internalMsg)
231  {
232  (*_cb)(_internalMsg);
233  };
234 
235  return this->Subscribe<T>(_topic, f);
236  }
237 
244  public: template<typename T> bool Subscribe(
245  const std::string &_topic,
246  std::function<void(const T &_msg)> &_cb)
247  {
248  std::string fullyQualifiedTopic;
249  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
250  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
251  {
252  std::cerr << "Topic [" << _topic << "] is not valid." << std::endl;
253  return false;
254  }
255 
256  // Create a new subscription handler.
257  std::shared_ptr<SubscriptionHandler<T>> subscrHandlerPtr(
258  new SubscriptionHandler<T>(this->NodeUuid()));
259 
260  // Insert the callback into the handler.
261  subscrHandlerPtr->SetCallback(_cb);
262 
263  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
264 
265  // Store the subscription handler. Each subscription handler is
266  // associated with a topic. When the receiving thread gets new data,
267  // it will recover the subscription handler associated to the topic and
268  // will invoke the callback.
269  this->Shared()->localSubscriptions.AddHandler(
270  fullyQualifiedTopic, this->NodeUuid(), subscrHandlerPtr);
271 
272  // Add the topic to the list of subscribed topics (if it was not before)
273  this->TopicsSubscribed().insert(fullyQualifiedTopic);
274 
275  // Discover the list of nodes that publish on the topic.
276  if (!this->Shared()->msgDiscovery->Discover(fullyQualifiedTopic))
277  {
278  std::cerr << "Node::Subscribe(): Error discovering a topic. "
279  << "Did you forget to start the discovery service?"
280  << std::endl;
281  return false;
282  }
283 
284  return true;
285  }
286 
295  public: template<typename C, typename T> bool Subscribe(
296  const std::string &_topic,
297  void(C::*_cb)(const T &_msg),
298  C *_obj)
299  {
300  std::function<void(const T &)> f = [_cb, _obj](const T & _internalMsg)
301  {
302  auto cb = std::bind(_cb, _obj, std::placeholders::_1);
303  cb(_internalMsg);
304  };
305 
306  return this->Subscribe<T>(_topic, f);
307  }
308 
314  public: std::vector<std::string> SubscribedTopics() const;
315 
319  public: bool Unsubscribe(const std::string &_topic);
320 
333  public: template<typename T1, typename T2> bool Advertise(
334  const std::string &_topic,
335  void(*_cb)(const T1 &_req, T2 &_rep, bool &_result),
336  const AdvertiseOptions &_options = AdvertiseOptions())
337  {
338  std::function<void(const T1 &, T2 &, bool &)> f =
339  [_cb](const T1 &_internalReq, T2 &_internalRep, bool &_internalResult)
340  {
341  (*_cb)(_internalReq, _internalRep, _internalResult);
342  };
343 
344  return this->Advertise<T1, T2>(_topic, f, _options);
345  }
346 
358  public: template<typename T> bool Advertise(
359  const std::string &_topic,
360  void(*_cb)(T &_rep, bool &_result),
361  const AdvertiseOptions &_options = AdvertiseOptions())
362  {
363  std::function<void(const msgs::Empty &, T &, bool &)> f =
364  [_cb](const msgs::Empty &/*_internalReq*/, T &_internalRep,
365  bool &_internalResult)
366  {
367  (*_cb)(_internalRep, _internalResult);
368  };
369  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
370  }
371 
382  public: template<typename T> bool Advertise(
383  const std::string &_topic,
384  void(*_cb)(const T &_req),
385  const AdvertiseOptions &_options = AdvertiseOptions())
386  {
387  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
388  [_cb](const T &_internalReq, ignition::msgs::Empty &/*_internalRep*/,
389  bool &/*_internalResult*/)
390  {
391  (*_cb)(_internalReq);
392  };
393 
394  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
395  }
396 
409  public: template<typename T1, typename T2> bool Advertise(
410  const std::string &_topic,
411  std::function<void(const T1 &_req, T2 &_rep, bool &_result)> &_cb,
412  const AdvertiseOptions &_options = AdvertiseOptions())
413  {
414  std::string fullyQualifiedTopic;
415  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
416  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
417  {
418  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
419  return false;
420  }
421 
422  // Create a new service reply handler.
423  std::shared_ptr<RepHandler<T1, T2>> repHandlerPtr(
424  new RepHandler<T1, T2>());
425 
426  // Insert the callback into the handler.
427  repHandlerPtr->SetCallback(_cb);
428 
429  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
430 
431  // Add the topic to the list of advertised services.
432  this->SrvsAdvertised().insert(fullyQualifiedTopic);
433 
434  // Store the replier handler. Each replier handler is
435  // associated with a topic. When the receiving thread gets new requests,
436  // it will recover the replier handler associated to the topic and
437  // will invoke the service call.
438  this->Shared()->repliers.AddHandler(
439  fullyQualifiedTopic, this->NodeUuid(), repHandlerPtr);
440 
441  // Notify the discovery service to register and advertise my responser.
442  ServicePublisher publisher(fullyQualifiedTopic,
443  this->Shared()->myReplierAddress,
444  this->Shared()->replierId.ToString(),
445  this->Shared()->pUuid, this->NodeUuid(), _options.Scope(),
446  T1().GetTypeName(), T2().GetTypeName());
447 
448  if (!this->Shared()->srvDiscovery->Advertise(publisher))
449  {
450  std::cerr << "Node::Advertise(): Error advertising a service. "
451  << "Did you forget to start the discovery service?"
452  << std::endl;
453  return false;
454  }
455 
456  return true;
457  }
458 
470  public: template<typename T> bool Advertise(
471  const std::string &_topic,
472  std::function<void(T &_rep, bool &_result)> &_cb,
473  const AdvertiseOptions &_options = AdvertiseOptions())
474  {
475  std::function<void(const msgs::Empty &, T &, bool &)> f =
476  [_cb](const msgs::Empty &/*_internalReq*/, T &_internalRep,
477  bool &_internalResult)
478  {
479  (_cb)(_internalRep, _internalResult);
480  };
481  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
482  }
483 
494  public: template<typename T> bool Advertise(
495  const std::string &_topic,
496  std::function<void(const T &_req)> &_cb,
497  const AdvertiseOptions &_options = AdvertiseOptions())
498  {
499  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
500  [_cb](const T &_internalReq, ignition::msgs::Empty &/*_internalRep*/,
501  bool &/*_internalResult*/)
502  {
503  (_cb)(_internalReq);
504  };
505 
506  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
507  }
508 
522  public: template<typename C, typename T1, typename T2> bool Advertise(
523  const std::string &_topic,
524  void(C::*_cb)(const T1 &_req, T2 &_rep, bool &_result),
525  C *_obj,
526  const AdvertiseOptions &_options = AdvertiseOptions())
527  {
528  std::function<void(const T1 &, T2 &, bool &)> f =
529  [_cb, _obj](const T1 &_internalReq,
530  T2 &_internalRep,
531  bool &_internalResult)
532  {
533  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
534  std::placeholders::_2, std::placeholders::_3);
535  cb(_internalReq, _internalRep, _internalResult);
536  };
537 
538  return this->Advertise<T1, T2>(_topic, f, _options);
539  }
540 
553  public: template<typename C, typename T> bool Advertise(
554  const std::string &_topic,
555  void(C::*_cb)(T &_rep, bool &_result),
556  C *_obj,
557  const AdvertiseOptions &_options = AdvertiseOptions())
558  {
559  std::function<void(const msgs::Empty &, T &, bool &)> f =
560  [_cb, _obj](const msgs::Empty &/*_internalReq*/, T &_internalRep,
561  bool &_internalResult)
562  {
563  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
564  std::placeholders::_2);
565  cb(_internalRep, _internalResult);
566  };
567 
568  return this->Advertise<msgs::Empty, T>(_topic, f, _options);
569  }
570 
582  public: template<typename C, typename T> bool Advertise(
583  const std::string &_topic,
584  void(C::*_cb)(const T &_req),
585  C *_obj,
586  const AdvertiseOptions &_options = AdvertiseOptions())
587  {
588  std::function<void(const T &, ignition::msgs::Empty &, bool &)> f =
589  [_cb, _obj](const T &_internalReq,
590  ignition::msgs::Empty &/*_internalRep*/,
591  bool &/*_internalResult*/)
592  {
593  auto cb = std::bind(_cb, _obj, std::placeholders::_1);
594  cb(_internalReq);
595  };
596 
597  return this->Advertise<T, ignition::msgs::Empty>(_topic, f, _options);
598  }
599 
602  public: std::vector<std::string> AdvertisedServices() const;
603 
614  public: template<typename T1, typename T2> bool Request(
615  const std::string &_topic,
616  const T1 &_req,
617  void(*_cb)(const T2 &_rep, const bool _result))
618  {
619  std::function<void(const T2 &, const bool)> f =
620  [_cb](const T2 &_internalRep, const bool _internalResult)
621  {
622  (*_cb)(_internalRep, _internalResult);
623  };
624 
625  return this->Request<T1, T2>(_topic, _req, f);
626  }
627 
638  public: template<typename T> bool Request(
639  const std::string &_topic,
640  void(*_cb)(const T &_rep, const bool _result))
641  {
642  msgs::Empty req;
643  return this->Request(_topic, req, _cb);
644  }
645 
656  public: template<typename T1, typename T2> bool Request(
657  const std::string &_topic,
658  const T1 &_req,
659  std::function<void(const T2 &_rep, const bool _result)> &_cb)
660  {
661  std::string fullyQualifiedTopic;
662  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
663  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
664  {
665  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
666  return false;
667  }
668 
669  bool localResponserFound;
670  IRepHandlerPtr repHandler;
671  {
672  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
673  localResponserFound = this->Shared()->repliers.FirstHandler(
674  fullyQualifiedTopic, T1().GetTypeName(), T2().GetTypeName(),
675  repHandler);
676  }
677 
678  // If the responser is within my process.
679  if (localResponserFound)
680  {
681  // There is a responser in my process, let's use it.
682  T2 rep;
683  bool result;
684  repHandler->RunLocalCallback(_req, rep, result);
685 
686  _cb(rep, result);
687  return true;
688  }
689 
690  // Create a new request handler.
691  std::shared_ptr<ReqHandler<T1, T2>> reqHandlerPtr(
692  new ReqHandler<T1, T2>(this->NodeUuid()));
693 
694  // Insert the request's parameters.
695  reqHandlerPtr->SetMessage(_req);
696 
697  // Insert the callback into the handler.
698  reqHandlerPtr->SetCallback(_cb);
699 
700  {
701  std::lock_guard<std::recursive_mutex> lk(this->Shared()->mutex);
702 
703  // Store the request handler.
704  this->Shared()->requests.AddHandler(
705  fullyQualifiedTopic, this->NodeUuid(), reqHandlerPtr);
706 
707  // If the responser's address is known, make the request.
708  SrvAddresses_M addresses;
709  if (this->Shared()->srvDiscovery->Publishers(
710  fullyQualifiedTopic, addresses))
711  {
712  this->Shared()->SendPendingRemoteReqs(fullyQualifiedTopic,
713  T1().GetTypeName(), T2().GetTypeName());
714  }
715  else
716  {
717  // Discover the service responser.
718  if (!this->Shared()->srvDiscovery->Discover(fullyQualifiedTopic))
719  {
720  std::cerr << "Node::Request(): Error discovering a service. "
721  << "Did you forget to start the discovery service?"
722  << std::endl;
723  return false;
724  }
725  }
726  }
727 
728  return true;
729  }
730 
741  public: template<typename T> bool Request(
742  const std::string &_topic,
743  std::function<void(const T &_rep, const bool _result)> &_cb)
744  {
745  msgs::Empty req;
746  return this->Request(_topic, req, _cb);
747  }
748 
760  public: template<typename C, typename T1, typename T2> bool Request(
761  const std::string &_topic,
762  const T1 &_req,
763  void(C::*_cb)(const T2 &_rep, const bool _result),
764  C *_obj)
765  {
766  std::function<void(const T2 &, const bool)> f =
767  [_cb, _obj](const T2 &_internalRep, const bool _internalResult)
768  {
769  auto cb = std::bind(_cb, _obj, std::placeholders::_1,
770  std::placeholders::_2);
771  cb(_internalRep, _internalResult);
772  };
773 
774  return this->Request<T1, T2>(_topic, _req, f);
775  }
776 
788  public: template<typename C, typename T> bool Request(
789  const std::string &_topic,
790  void(C::*_cb)(const T &_rep, const bool _result),
791  C *_obj)
792  {
793  msgs::Empty req;
794  return this->Request(_topic, req, _cb, _obj);
795  }
796 
805  public: template<typename T1, typename T2> bool Request(
806  const std::string &_topic,
807  const T1 &_req,
808  const unsigned int &_timeout,
809  T2 &_rep,
810  bool &_result)
811  {
812  std::string fullyQualifiedTopic;
813  if (!TopicUtils::FullyQualifiedName(this->Options().Partition(),
814  this->Options().NameSpace(), _topic, fullyQualifiedTopic))
815  {
816  std::cerr << "Service [" << _topic << "] is not valid." << std::endl;
817  return false;
818  }
819 
820  // Create a new request handler.
821  std::shared_ptr<ReqHandler<T1, T2>> reqHandlerPtr(
822  new ReqHandler<T1, T2>(this->NodeUuid()));
823 
824  // Insert the request's parameters.
825  reqHandlerPtr->SetMessage(_req);
826 
827  std::unique_lock<std::recursive_mutex> lk(this->Shared()->mutex);
828 
829  // If the responser is within my process.
830  IRepHandlerPtr repHandler;
831  if (this->Shared()->repliers.FirstHandler(fullyQualifiedTopic,
832  T1().GetTypeName(), T2().GetTypeName(), repHandler))
833  {
834  // There is a responser in my process, let's use it.
835  repHandler->RunLocalCallback(_req, _rep, _result);
836  return true;
837  }
838 
839  // Store the request handler.
840  this->Shared()->requests.AddHandler(
841  fullyQualifiedTopic, this->NodeUuid(), reqHandlerPtr);
842 
843  // If the responser's address is known, make the request.
844  SrvAddresses_M addresses;
845  if (this->Shared()->srvDiscovery->Publishers(
846  fullyQualifiedTopic, addresses))
847  {
848  this->Shared()->SendPendingRemoteReqs(fullyQualifiedTopic,
849  T1().GetTypeName(), T2().GetTypeName());
850  }
851  else
852  {
853  // Discover the service responser.
854  if (!this->Shared()->srvDiscovery->Discover(fullyQualifiedTopic))
855  {
856  std::cerr << "Node::Request(): Error discovering a service. "
857  << "Did you forget to start the discovery service?"
858  << std::endl;
859  return false;
860  }
861  }
862 
863  // Wait until the REP is available.
864  bool executed = reqHandlerPtr->WaitUntil(lk, _timeout);
865 
866  // The request was not executed.
867  if (!executed)
868  return false;
869 
870  // The request was executed but did not succeed.
871  if (!reqHandlerPtr->Result())
872  {
873  _result = false;
874  return true;
875  }
876 
877  // Parse the response.
878  if (!_rep.ParseFromString(reqHandlerPtr->Response()))
879  {
880  std::cerr << "Node::Request(): Error Parsing the response"
881  << std::endl;
882  _result = false;
883  return true;
884  }
885 
886  _result = true;
887  return true;
888  }
889 
898  public: template<typename T> bool Request(
899  const std::string &_topic,
900  const unsigned int &_timeout,
901  T &_rep,
902  bool &_result)
903  {
904  msgs::Empty req;
905  return this->Request(_topic, req, _timeout, _rep, _result);
906  }
907 
912  public: template<typename T> bool Request(const std::string &_topic,
913  const T &_req)
914  {
915  // This callback is here for reusing the regular Request() call with
916  // input and output parameters.
917  std::function<void(const ignition::msgs::Empty &, const bool)> f =
918  [](const ignition::msgs::Empty &, const bool)
919  {
920  };
921 
922  return this->Request<T, ignition::msgs::Empty>(_topic, _req, f);
923  }
924 
928  public: bool UnadvertiseSrv(const std::string &_topic);
929 
936  public: void TopicList(std::vector<std::string> &_topics) const;
937 
942  public: bool TopicInfo(const std::string &_topic,
943  std::vector<MessagePublisher> &_publishers) const;
944 
951  public: void ServiceList(std::vector<std::string> &_services) const;
952 
957  public: bool ServiceInfo(const std::string &_service,
958  std::vector<ServicePublisher> &_publishers) const;
959 
962  private: const std::string &Partition() const;
963 
966  private: const std::string &NameSpace() const;
967 
971  private: NodeShared *Shared() const;
972 
975  private: const std::string &NodeUuid() const;
976 
979  private: std::unordered_set<std::string> &TopicsAdvertised() const;
980 
983  private: std::unordered_set<std::string> &TopicsSubscribed() const;
984 
987  private: std::unordered_set<std::string> &SrvsAdvertised() const;
988 
991  private: NodeOptions &Options() const;
992 
998  private: bool PublishHelper(const std::string &_topic,
999  const ProtoMsg &_msg);
1000 
1003  protected: std::unique_ptr<transport::NodePrivate> dataPtr;
1004  };
1005  }
1006 }
1007 #endif
bool Advertise(const std::string &_topic, void(*_cb)(T &_rep, bool &_result), const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without input parameter.
Definition: Node.hh:358
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:741
bool Advertise(const std::string &_topic, void(*_cb)(const T &_req), const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:382
Node::PublisherId Advertise(const std::string &_topic, const std::string &_msgTypeName, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new topic.
Definition: Node.hh:149
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:788
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:614
A class for customizing the behavior of the Node.
Definition: NodeOptions.hh:35
It creates a reply handler for the specific protobuf messages used.
Definition: ReqHandler.hh:175
Node::PublisherId Advertise(const std::string &_topic, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new topic.
Definition: Node.hh:131
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 AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:582
bool Subscribe(const std::string &_topic, void(*_cb)(const T &_msg))
Subscribe to a topic registering a callback.
Definition: Node.hh:226
ignition/transport/AdvertiseOptions.hh
Definition: AdvertiseOptions.hh:50
bool Advertise(const std::string &_topic, std::function< void(const T1 &_req, T2 &_rep, bool &_result)> &_cb, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service.
Definition: Node.hh:409
Private data for the Node class.
Definition: NodeShared.hh:53
Addresses_M< ServicePublisher > SrvAddresses_M
Definition: TransportTypes.hh:60
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:638
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:64
bool Advertise(const std::string &_topic, void(C::*_cb)(T &_rep, bool &_result), C *_obj, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without input parameter.
Definition: Node.hh:553
std::shared_ptr< IRepHandler > IRepHandlerPtr
Definition: TransportTypes.hh:84
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:656
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:898
bool Advertise(const std::string &_topic, std::function< void(T &_rep, bool &_result)> &_cb, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without input parameter.
Definition: Node.hh:470
bool Advertise(const std::string &_topic, void(C::*_cb)(const T1 &_req, T2 &_rep, bool &_result), C *_obj, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service.
Definition: Node.hh:522
bool Subscribe(const std::string &_topic, std::function< void(const T &_msg)> &_cb)
Subscribe to a topic registering a callback.
Definition: Node.hh:244
with the service response.
Definition: RepHandler.hh:98
std::unique_ptr< transport::NodePrivate > dataPtr
Definition: Node.hh:1003
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:55
A class that allows a client to communicate with other peers.
Definition: Node.hh:72
ignition/transport/Publisher.hh
Definition: Publisher.hh:175
ignition/transport/Publisher.hh
Definition: Publisher.hh:264
A class that is used to store information about an advertised publisher.
Definition: Node.hh:86
bool Advertise(const std::string &_topic, std::function< void(const T &_req)> &_cb, const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service without any output parameter.
Definition: Node.hh:494
bool Request(const std::string &_topic, const T &_req)
Request a new service without waiting for response.
Definition: Node.hh:912
bool Advertise(const std::string &_topic, void(*_cb)(const T1 &_req, T2 &_rep, bool &_result), const AdvertiseOptions &_options=AdvertiseOptions())
Advertise a new service.
Definition: Node.hh:333
It creates a subscription handler for a specific protobuf message.
Definition: SubscriptionHandler.hh:102
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:805
Definition: AdvertiseOptions.hh:25
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:760
bool Subscribe(const std::string &_topic, void(C::*_cb)(const T &_msg), C *_obj)
Subscribe to a topic registering a callback.
Definition: Node.hh:295