Ignition Transport

API Reference

8.1.0
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 <optional>
25 #include <string>
26 #include <unordered_set>
27 #include <vector>
28 
29 // TODO(anyone): Remove after fixing the warnings
30 #ifdef _MSC_VER
31 #pragma warning(push, 0)
32 #endif
33 #include <ignition/msgs.hh>
34 #ifdef _MSC_VER
35 #pragma warning(pop)
36 #endif
37 
39 #include "ignition/transport/config.hh"
40 #include "ignition/transport/Export.hh"
51 
52 namespace ignition
53 {
54  namespace transport
55  {
56  // Inline bracket to help doxygen filtering.
57  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
58  //
59  // Forward declarations.
60  class NodePrivate;
61 
72  int IGNITION_TRANSPORT_VISIBLE rcvHwm();
73 
84  int IGNITION_TRANSPORT_VISIBLE sndHwm();
85 
89  void IGNITION_TRANSPORT_VISIBLE waitForShutdown();
90 
95  class IGNITION_TRANSPORT_VISIBLE Node
96  {
97  class PublisherPrivate;
98 
115  public: class IGNITION_TRANSPORT_VISIBLE Publisher
116  {
118  public: Publisher();
119 
122  public: explicit Publisher(const MessagePublisher &_publisher);
123 
125  public: virtual ~Publisher();
126 
130  public: operator bool();
131 
135  public: operator bool() const;
136 
140  public: bool Valid() const;
141 
147  public: bool Publish(const ProtoMsg &_msg);
148 
170  public: bool PublishRaw(
171  const std::string &_msgData,
172  const std::string &_msgType);
173 
182  public: bool ThrottledUpdateReady() const;
183 
187  private: bool UpdateThrottling();
188 
191  public: bool HasConnections() const;
192 
198 #ifdef _WIN32
199 // Disable warning C4251 which is triggered by
200 // std::shared_ptr
201 #pragma warning(push)
202 #pragma warning(disable: 4251)
203 #endif
204  private: std::shared_ptr<PublisherPrivate> dataPtr;
205 #ifdef _WIN32
206 #pragma warning(pop)
207 #endif
208  };
209 
212  public: explicit Node(const NodeOptions &_options = NodeOptions());
213 
215  public: virtual ~Node();
216 
225  public: template<typename MessageT>
226  Node::Publisher Advertise(
227  const std::string &_topic,
229 
241  public: Node::Publisher Advertise(
242  const std::string &_topic,
243  const std::string &_msgTypeName,
245 
248  public: std::vector<std::string> AdvertisedTopics() const;
249 
259  public: template<typename MessageT>
260  bool Subscribe(
261  const std::string &_topic,
262  void(*_callback)(const MessageT &_msg),
263  const SubscribeOptions &_opts = SubscribeOptions());
264 
273  public: template<typename MessageT>
274  bool Subscribe(
275  const std::string &_topic,
276  std::function<void(const MessageT &_msg)> &_callback,
277  const SubscribeOptions &_opts = SubscribeOptions());
278 
289  public: template<typename ClassT, typename MessageT>
290  bool Subscribe(
291  const std::string &_topic,
292  void(ClassT::*_callback)(const MessageT &_msg),
293  ClassT *_obj,
294  const SubscribeOptions &_opts = SubscribeOptions());
295 
306  public: template<typename MessageT>
307  bool Subscribe(
308  const std::string &_topic,
309  void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
310  const SubscribeOptions &_opts = SubscribeOptions());
311 
321  public: template<typename MessageT>
322  bool Subscribe(
323  const std::string &_topic,
324  std::function<void(const MessageT &_msg,
325  const MessageInfo &_info)> &_callback,
326  const SubscribeOptions &_opts = SubscribeOptions());
327 
339  public: template<typename ClassT, typename MessageT>
340  bool Subscribe(
341  const std::string &_topic,
342  void(ClassT::*_callback)(const MessageT &_msg,
343  const MessageInfo &_info),
344  ClassT *_obj,
345  const SubscribeOptions &_opts = SubscribeOptions());
346 
352  public: std::vector<std::string> SubscribedTopics() const;
353 
357  public: bool Unsubscribe(const std::string &_topic);
358 
371  public: template<typename RequestT, typename ReplyT>
372  bool Advertise(
373  const std::string &_topic,
374  bool(*_callback)(const RequestT &_request, ReplyT &_reply),
376 
388  public: template<typename ReplyT>
389  bool Advertise(
390  const std::string &_topic,
391  bool(*_callback)(ReplyT &_reply),
393 
404  public: template<typename RequestT>
405  bool Advertise(
406  const std::string &_topic,
407  void(*_callback)(const RequestT &_request),
409 
422  public: template<typename RequestT, typename ReplyT>
423  bool Advertise(
424  const std::string &_topic,
425  std::function<bool(const RequestT &_request,
426  ReplyT &_reply)> _callback,
428 
440  public: template<typename ReplyT>
441  bool Advertise(
442  const std::string &_topic,
443  std::function<bool(ReplyT &_reply)> &_callback,
445 
456  public: template<typename RequestT>
457  bool Advertise(
458  const std::string &_topic,
459  std::function<void(const RequestT &_request)> &_callback,
461 
475  public: template<typename ClassT, typename RequestT, typename ReplyT>
476  bool Advertise(
477  const std::string &_topic,
478  bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
479  ClassT *_obj,
481 
494  public: template<typename ClassT, typename ReplyT>
495  bool Advertise(
496  const std::string &_topic,
497  bool(ClassT::*_callback)(ReplyT &_reply),
498  ClassT *_obj,
500 
512  public: template<typename ClassT, typename RequestT>
513  bool Advertise(
514  const std::string &_topic,
515  void(ClassT::*_callback)(const RequestT &_request),
516  ClassT *_obj,
518 
521  public: std::vector<std::string> AdvertisedServices() const;
522 
534  public: template<typename RequestT, typename ReplyT>
535  bool Request(
536  const std::string &_topic,
537  const RequestT &_request,
538  void(*_callback)(const ReplyT &_reply, const bool _result));
539 
550  public: template<typename ReplyT>
551  bool Request(
552  const std::string &_topic,
553  void(*_callback)(const ReplyT &_reply, const bool _result));
554 
566  public: template<typename RequestT, typename ReplyT>
567  bool Request(
568  const std::string &_topic,
569  const RequestT &_request,
570  std::function<void(const ReplyT &_reply,
571  const bool _result)> &_callback);
572 
583  public: template<typename ReplyT>
584  bool Request(
585  const std::string &_topic,
586  std::function<void(const ReplyT &_reply,
587  const bool _result)> &_callback);
588 
601  public: template<typename ClassT, typename RequestT, typename ReplyT>
602  bool Request(
603  const std::string &_topic,
604  const RequestT &_request,
605  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
606  ClassT *_obj);
607 
619  public: template<typename ClassT, typename ReplyT>
620  bool Request(
621  const std::string &_topic,
622  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
623  ClassT *_obj);
624 
634  public: template<typename RequestT, typename ReplyT>
635  bool Request(
636  const std::string &_topic,
637  const RequestT &_request,
638  const unsigned int &_timeout,
639  ReplyT &_reply,
640  bool &_result);
641 
650  public: template<typename ReplyT>
651  bool Request(
652  const std::string &_topic,
653  const unsigned int &_timeout,
654  ReplyT &_reply,
655  bool &_result);
656 
662  public: template<typename RequestT>
663  bool Request(const std::string &_topic, const RequestT &_request);
664 
668  public: bool UnadvertiseSrv(const std::string &_topic);
669 
676  public: void TopicList(std::vector<std::string> &_topics) const;
677 
682  public: bool TopicInfo(const std::string &_topic,
683  std::vector<MessagePublisher> &_publishers) const;
684 
691  public: void ServiceList(std::vector<std::string> &_services) const;
692 
697  public: bool ServiceInfo(
698  const std::string &_service,
699  std::vector<ServicePublisher> &_publishers) const;
700 
714  public: bool SubscribeRaw(
715  const std::string &_topic,
716  const RawCallback &_callback,
717  const std::string &_msgType = kGenericMessageType,
718  const SubscribeOptions &_opts = SubscribeOptions());
719 
722  public: const NodeOptions &Options() const;
723 
730  public: bool EnableStats(const std::string &_topic, bool _enable,
731  const std::string &_publicationTopic = "/statistics",
732  uint64_t _publicationRate = 1);
733 
740  public: std::optional<TopicStatistics> TopicStats(
741  const std::string &_topic) const;
742 
746  private: NodeShared *Shared() const;
747 
750  private: const std::string &NodeUuid() const;
751 
754  private: std::unordered_set<std::string> &TopicsSubscribed() const;
755 
758  private: std::unordered_set<std::string> &SrvsAdvertised() const;
759 
763  private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
764 
765 #ifdef _WIN32
766 // Disable warning C4251 which is triggered by
767 // std::unique_ptr
768 #pragma warning(push)
769 #pragma warning(disable: 4251)
770 #endif
774 #ifdef _WIN32
775 #pragma warning(pop)
776 #endif
777  };
778  }
779  }
780 }
781 
782 #include "ignition/transport/detail/Node.hh"
783 
784 #endif
A class for customizing the publication options for a topic advertised. E.g.: Set the rate of message...
Definition: AdvertiseOptions.hh:150
A class for customizing the behavior of the Node. E.g.: Set a custom namespace or a partition name...
Definition: NodeOptions.hh:40
A class that is used to store information about an advertised publisher. An instance of this class is...
Definition: Node.hh:115
A class to provide different options for a subscription.
Definition: SubscribeOptions.hh:39
int rcvHwm()
Get the capacity of the buffer (High Water Mark) that stores incoming Ignition Transport messages...
void waitForShutdown()
Block the current thread until a SIGINT or SIGTERM is received. Note that this function registers a s...
STL class.
const std::string kGenericMessageType
The string type used for generic messages.
Definition: TransportTypes.hh:174
Private data for the Node class. This class should not be directly used. You should use the Node clas...
Definition: NodeShared.hh:66
A class that provides information about the message received.
Definition: MessageInfo.hh:37
A class for customizing the publication options for a service advertised.
Definition: AdvertiseOptions.hh:247
A class that allows a client to communicate with other peers. There are two main communication modes:...
Definition: Node.hh:95
This class stores all the information about a message publisher.
Definition: Publisher.hh:222
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:70
int sndHwm()
Get the capacity of the buffer (High Water Mark) that stores outgoing Ignition Transport messages...
Definition: AdvertiseOptions.hh:28