Ignition Transport

API Reference

7.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 <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 
63  void IGNITION_TRANSPORT_VISIBLE waitForShutdown();
64 
69  class IGNITION_TRANSPORT_VISIBLE Node
70  {
71  class PublisherPrivate;
72 
89  public: class IGNITION_TRANSPORT_VISIBLE Publisher
90  {
92  public: Publisher();
93 
96  public: explicit Publisher(const MessagePublisher &_publisher);
97 
99  public: virtual ~Publisher();
100 
104  public: operator bool();
105 
109  public: operator bool() const;
110 
114  public: bool Valid() const;
115 
121  public: bool Publish(const ProtoMsg &_msg);
122 
144  public: bool PublishRaw(
145  const std::string &_msgData,
146  const std::string &_msgType);
147 
156  public: bool ThrottledUpdateReady() const;
157 
161  private: bool UpdateThrottling();
162 
165  public: bool HasConnections() const;
166 
172 #ifdef _WIN32
173 // Disable warning C4251 which is triggered by
174 // std::shared_ptr
175 #pragma warning(push)
176 #pragma warning(disable: 4251)
177 #endif
178  private: std::shared_ptr<PublisherPrivate> dataPtr;
179 #ifdef _WIN32
180 #pragma warning(pop)
181 #endif
182  };
183 
186  public: explicit Node(const NodeOptions &_options = NodeOptions());
187 
189  public: virtual ~Node();
190 
199  public: template<typename MessageT>
200  Node::Publisher Advertise(
201  const std::string &_topic,
203 
215  public: Node::Publisher Advertise(
216  const std::string &_topic,
217  const std::string &_msgTypeName,
219 
222  public: std::vector<std::string> AdvertisedTopics() const;
223 
233  public: template<typename MessageT>
234  bool Subscribe(
235  const std::string &_topic,
236  void(*_callback)(const MessageT &_msg),
237  const SubscribeOptions &_opts = SubscribeOptions());
238 
247  public: template<typename MessageT>
248  bool Subscribe(
249  const std::string &_topic,
250  std::function<void(const MessageT &_msg)> &_callback,
251  const SubscribeOptions &_opts = SubscribeOptions());
252 
263  public: template<typename ClassT, typename MessageT>
264  bool Subscribe(
265  const std::string &_topic,
266  void(ClassT::*_callback)(const MessageT &_msg),
267  ClassT *_obj,
268  const SubscribeOptions &_opts = SubscribeOptions());
269 
280  public: template<typename MessageT>
281  bool Subscribe(
282  const std::string &_topic,
283  void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
284  const SubscribeOptions &_opts = SubscribeOptions());
285 
295  public: template<typename MessageT>
296  bool Subscribe(
297  const std::string &_topic,
298  std::function<void(const MessageT &_msg,
299  const MessageInfo &_info)> &_callback,
300  const SubscribeOptions &_opts = SubscribeOptions());
301 
313  public: template<typename ClassT, typename MessageT>
314  bool Subscribe(
315  const std::string &_topic,
316  void(ClassT::*_callback)(const MessageT &_msg,
317  const MessageInfo &_info),
318  ClassT *_obj,
319  const SubscribeOptions &_opts = SubscribeOptions());
320 
326  public: std::vector<std::string> SubscribedTopics() const;
327 
331  public: bool Unsubscribe(const std::string &_topic);
332 
345  public: template<typename RequestT, typename ReplyT>
346  bool Advertise(
347  const std::string &_topic,
348  bool(*_callback)(const RequestT &_request, ReplyT &_reply),
350 
362  public: template<typename ReplyT>
363  bool Advertise(
364  const std::string &_topic,
365  bool(*_callback)(ReplyT &_reply),
367 
378  public: template<typename RequestT>
379  bool Advertise(
380  const std::string &_topic,
381  void(*_callback)(const RequestT &_request),
383 
396  public: template<typename RequestT, typename ReplyT>
397  bool Advertise(
398  const std::string &_topic,
399  std::function<bool(const RequestT &_request,
400  ReplyT &_reply)> _callback,
402 
414  public: template<typename ReplyT>
415  bool Advertise(
416  const std::string &_topic,
417  std::function<bool(ReplyT &_reply)> &_callback,
419 
430  public: template<typename RequestT>
431  bool Advertise(
432  const std::string &_topic,
433  std::function<void(const RequestT &_request)> &_callback,
435 
449  public: template<typename ClassT, typename RequestT, typename ReplyT>
450  bool Advertise(
451  const std::string &_topic,
452  bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
453  ClassT *_obj,
455 
468  public: template<typename ClassT, typename ReplyT>
469  bool Advertise(
470  const std::string &_topic,
471  bool(ClassT::*_callback)(ReplyT &_reply),
472  ClassT *_obj,
474 
486  public: template<typename ClassT, typename RequestT>
487  bool Advertise(
488  const std::string &_topic,
489  void(ClassT::*_callback)(const RequestT &_request),
490  ClassT *_obj,
492 
495  public: std::vector<std::string> AdvertisedServices() const;
496 
508  public: template<typename RequestT, typename ReplyT>
509  bool Request(
510  const std::string &_topic,
511  const RequestT &_request,
512  void(*_callback)(const ReplyT &_reply, const bool _result));
513 
524  public: template<typename ReplyT>
525  bool Request(
526  const std::string &_topic,
527  void(*_callback)(const ReplyT &_reply, const bool _result));
528 
540  public: template<typename RequestT, typename ReplyT>
541  bool Request(
542  const std::string &_topic,
543  const RequestT &_request,
544  std::function<void(const ReplyT &_reply,
545  const bool _result)> &_callback);
546 
557  public: template<typename ReplyT>
558  bool Request(
559  const std::string &_topic,
560  std::function<void(const ReplyT &_reply,
561  const bool _result)> &_callback);
562 
575  public: template<typename ClassT, typename RequestT, typename ReplyT>
576  bool Request(
577  const std::string &_topic,
578  const RequestT &_request,
579  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
580  ClassT *_obj);
581 
593  public: template<typename ClassT, typename ReplyT>
594  bool Request(
595  const std::string &_topic,
596  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
597  ClassT *_obj);
598 
608  public: template<typename RequestT, typename ReplyT>
609  bool Request(
610  const std::string &_topic,
611  const RequestT &_request,
612  const unsigned int &_timeout,
613  ReplyT &_reply,
614  bool &_result);
615 
624  public: template<typename ReplyT>
625  bool Request(
626  const std::string &_topic,
627  const unsigned int &_timeout,
628  ReplyT &_reply,
629  bool &_result);
630 
636  public: template<typename RequestT>
637  bool Request(const std::string &_topic, const RequestT &_request);
638 
642  public: bool UnadvertiseSrv(const std::string &_topic);
643 
650  public: void TopicList(std::vector<std::string> &_topics) const;
651 
656  public: bool TopicInfo(const std::string &_topic,
657  std::vector<MessagePublisher> &_publishers) const;
658 
665  public: void ServiceList(std::vector<std::string> &_services) const;
666 
671  public: bool ServiceInfo(
672  const std::string &_service,
673  std::vector<ServicePublisher> &_publishers) const;
674 
688  public: bool SubscribeRaw(
689  const std::string &_topic,
690  const RawCallback &_callback,
691  const std::string &_msgType = kGenericMessageType,
692  const SubscribeOptions &_opts = SubscribeOptions());
693 
696  public: const NodeOptions &Options() const;
697 
701  private: NodeShared *Shared() const;
702 
705  private: const std::string &NodeUuid() const;
706 
709  private: std::unordered_set<std::string> &TopicsSubscribed() const;
710 
713  private: std::unordered_set<std::string> &SrvsAdvertised() const;
714 
718  private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
719 
720 #ifdef _WIN32
721 // Disable warning C4251 which is triggered by
722 // std::unique_ptr
723 #pragma warning(push)
724 #pragma warning(disable: 4251)
725 #endif
729 #ifdef _WIN32
730 #pragma warning(pop)
731 #endif
732  };
733  }
734  }
735 }
736 
737 #include "ignition/transport/detail/Node.hh"
738 
739 #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:89
A class to provide different options for a subscription.
Definition: SubscribeOptions.hh:39
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:69
This class stores all the information about a message publisher.
Definition: Publisher.hh:212
google::protobuf::Message ProtoMsg
Definition: TransportTypes.hh:70
Definition: AdvertiseOptions.hh:28