Ignition Transport

API Reference

8.0.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 <string>
25 #include <unordered_set>
26 #include <vector>
27 
28 // TODO(anyone): 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 
38 #include "ignition/transport/config.hh"
39 #include "ignition/transport/Export.hh"
49 
50 namespace ignition
51 {
52  namespace transport
53  {
54  // Inline bracket to help doxygen filtering.
55  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
56  //
57  // Forward declarations.
58  class NodePrivate;
59 
70  int IGNITION_TRANSPORT_VISIBLE rcvHwm();
71 
82  int IGNITION_TRANSPORT_VISIBLE sndHwm();
83 
87  void IGNITION_TRANSPORT_VISIBLE waitForShutdown();
88 
93  class IGNITION_TRANSPORT_VISIBLE Node
94  {
95  class PublisherPrivate;
96 
113  public: class IGNITION_TRANSPORT_VISIBLE Publisher
114  {
116  public: Publisher();
117 
120  public: explicit Publisher(const MessagePublisher &_publisher);
121 
123  public: virtual ~Publisher();
124 
128  public: operator bool();
129 
133  public: operator bool() const;
134 
138  public: bool Valid() const;
139 
145  public: bool Publish(const ProtoMsg &_msg);
146 
168  public: bool PublishRaw(
169  const std::string &_msgData,
170  const std::string &_msgType);
171 
180  public: bool ThrottledUpdateReady() const;
181 
185  private: bool UpdateThrottling();
186 
189  public: bool HasConnections() const;
190 
196 #ifdef _WIN32
197 // Disable warning C4251 which is triggered by
198 // std::shared_ptr
199 #pragma warning(push)
200 #pragma warning(disable: 4251)
201 #endif
202  private: std::shared_ptr<PublisherPrivate> dataPtr;
203 #ifdef _WIN32
204 #pragma warning(pop)
205 #endif
206  };
207 
210  public: explicit Node(const NodeOptions &_options = NodeOptions());
211 
213  public: virtual ~Node();
214 
223  public: template<typename MessageT>
224  Node::Publisher Advertise(
225  const std::string &_topic,
227 
239  public: Node::Publisher Advertise(
240  const std::string &_topic,
241  const std::string &_msgTypeName,
243 
246  public: std::vector<std::string> AdvertisedTopics() const;
247 
257  public: template<typename MessageT>
258  bool Subscribe(
259  const std::string &_topic,
260  void(*_callback)(const MessageT &_msg),
261  const SubscribeOptions &_opts = SubscribeOptions());
262 
271  public: template<typename MessageT>
272  bool Subscribe(
273  const std::string &_topic,
274  std::function<void(const MessageT &_msg)> &_callback,
275  const SubscribeOptions &_opts = SubscribeOptions());
276 
287  public: template<typename ClassT, typename MessageT>
288  bool Subscribe(
289  const std::string &_topic,
290  void(ClassT::*_callback)(const MessageT &_msg),
291  ClassT *_obj,
292  const SubscribeOptions &_opts = SubscribeOptions());
293 
304  public: template<typename MessageT>
305  bool Subscribe(
306  const std::string &_topic,
307  void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
308  const SubscribeOptions &_opts = SubscribeOptions());
309 
319  public: template<typename MessageT>
320  bool Subscribe(
321  const std::string &_topic,
322  std::function<void(const MessageT &_msg,
323  const MessageInfo &_info)> &_callback,
324  const SubscribeOptions &_opts = SubscribeOptions());
325 
337  public: template<typename ClassT, typename MessageT>
338  bool Subscribe(
339  const std::string &_topic,
340  void(ClassT::*_callback)(const MessageT &_msg,
341  const MessageInfo &_info),
342  ClassT *_obj,
343  const SubscribeOptions &_opts = SubscribeOptions());
344 
350  public: std::vector<std::string> SubscribedTopics() const;
351 
355  public: bool Unsubscribe(const std::string &_topic);
356 
369  public: template<typename RequestT, typename ReplyT>
370  bool Advertise(
371  const std::string &_topic,
372  bool(*_callback)(const RequestT &_request, ReplyT &_reply),
374 
386  public: template<typename ReplyT>
387  bool Advertise(
388  const std::string &_topic,
389  bool(*_callback)(ReplyT &_reply),
391 
402  public: template<typename RequestT>
403  bool Advertise(
404  const std::string &_topic,
405  void(*_callback)(const RequestT &_request),
407 
420  public: template<typename RequestT, typename ReplyT>
421  bool Advertise(
422  const std::string &_topic,
423  std::function<bool(const RequestT &_request,
424  ReplyT &_reply)> _callback,
426 
438  public: template<typename ReplyT>
439  bool Advertise(
440  const std::string &_topic,
441  std::function<bool(ReplyT &_reply)> &_callback,
443 
454  public: template<typename RequestT>
455  bool Advertise(
456  const std::string &_topic,
457  std::function<void(const RequestT &_request)> &_callback,
459 
473  public: template<typename ClassT, typename RequestT, typename ReplyT>
474  bool Advertise(
475  const std::string &_topic,
476  bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
477  ClassT *_obj,
479 
492  public: template<typename ClassT, typename ReplyT>
493  bool Advertise(
494  const std::string &_topic,
495  bool(ClassT::*_callback)(ReplyT &_reply),
496  ClassT *_obj,
498 
510  public: template<typename ClassT, typename RequestT>
511  bool Advertise(
512  const std::string &_topic,
513  void(ClassT::*_callback)(const RequestT &_request),
514  ClassT *_obj,
516 
519  public: std::vector<std::string> AdvertisedServices() const;
520 
532  public: template<typename RequestT, typename ReplyT>
533  bool Request(
534  const std::string &_topic,
535  const RequestT &_request,
536  void(*_callback)(const ReplyT &_reply, const bool _result));
537 
548  public: template<typename ReplyT>
549  bool Request(
550  const std::string &_topic,
551  void(*_callback)(const ReplyT &_reply, const bool _result));
552 
564  public: template<typename RequestT, typename ReplyT>
565  bool Request(
566  const std::string &_topic,
567  const RequestT &_request,
568  std::function<void(const ReplyT &_reply,
569  const bool _result)> &_callback);
570 
581  public: template<typename ReplyT>
582  bool Request(
583  const std::string &_topic,
584  std::function<void(const ReplyT &_reply,
585  const bool _result)> &_callback);
586 
599  public: template<typename ClassT, typename RequestT, typename ReplyT>
600  bool Request(
601  const std::string &_topic,
602  const RequestT &_request,
603  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
604  ClassT *_obj);
605 
617  public: template<typename ClassT, typename ReplyT>
618  bool Request(
619  const std::string &_topic,
620  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
621  ClassT *_obj);
622 
632  public: template<typename RequestT, typename ReplyT>
633  bool Request(
634  const std::string &_topic,
635  const RequestT &_request,
636  const unsigned int &_timeout,
637  ReplyT &_reply,
638  bool &_result);
639 
648  public: template<typename ReplyT>
649  bool Request(
650  const std::string &_topic,
651  const unsigned int &_timeout,
652  ReplyT &_reply,
653  bool &_result);
654 
660  public: template<typename RequestT>
661  bool Request(const std::string &_topic, const RequestT &_request);
662 
666  public: bool UnadvertiseSrv(const std::string &_topic);
667 
674  public: void TopicList(std::vector<std::string> &_topics) const;
675 
680  public: bool TopicInfo(const std::string &_topic,
681  std::vector<MessagePublisher> &_publishers) const;
682 
689  public: void ServiceList(std::vector<std::string> &_services) const;
690 
695  public: bool ServiceInfo(
696  const std::string &_service,
697  std::vector<ServicePublisher> &_publishers) const;
698 
712  public: bool SubscribeRaw(
713  const std::string &_topic,
714  const RawCallback &_callback,
715  const std::string &_msgType = kGenericMessageType,
716  const SubscribeOptions &_opts = SubscribeOptions());
717 
720  public: const NodeOptions &Options() const;
721 
725  private: NodeShared *Shared() const;
726 
729  private: const std::string &NodeUuid() const;
730 
733  private: std::unordered_set<std::string> &TopicsSubscribed() const;
734 
737  private: std::unordered_set<std::string> &SrvsAdvertised() const;
738 
742  private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
743 
744 #ifdef _WIN32
745 // Disable warning C4251 which is triggered by
746 // std::unique_ptr
747 #pragma warning(push)
748 #pragma warning(disable: 4251)
749 #endif
753 #ifdef _WIN32
754 #pragma warning(pop)
755 #endif
756  };
757  }
758  }
759 }
760 
761 #include "ignition/transport/detail/Node.hh"
762 
763 #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:113
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:64
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:93
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