Ignition Transport

API Reference

6.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 
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 
151  private: bool UpdateThrottling();
152 
155  public: bool HasConnections() const;
156 
162 #ifdef _WIN32
163 // Disable warning C4251 which is triggered by
164 // std::shared_ptr
165 #pragma warning(push)
166 #pragma warning(disable: 4251)
167 #endif
168  private: std::shared_ptr<PublisherPrivate> dataPtr;
169 #ifdef _WIN32
170 #pragma warning(pop)
171 #endif
172  };
173 
176  public: explicit Node(const NodeOptions &_options = NodeOptions());
177 
179  public: virtual ~Node();
180 
189  public: template<typename MessageT>
190  Node::Publisher Advertise(
191  const std::string &_topic,
193 
205  public: Node::Publisher Advertise(
206  const std::string &_topic,
207  const std::string &_msgTypeName,
209 
212  public: std::vector<std::string> AdvertisedTopics() const;
213 
223  public: template<typename MessageT>
224  bool Subscribe(
225  const std::string &_topic,
226  void(*_callback)(const MessageT &_msg),
227  const SubscribeOptions &_opts = SubscribeOptions());
228 
237  public: template<typename MessageT>
238  bool Subscribe(
239  const std::string &_topic,
240  std::function<void(const MessageT &_msg)> &_callback,
241  const SubscribeOptions &_opts = SubscribeOptions());
242 
253  public: template<typename ClassT, typename MessageT>
254  bool Subscribe(
255  const std::string &_topic,
256  void(ClassT::*_callback)(const MessageT &_msg),
257  ClassT *_obj,
258  const SubscribeOptions &_opts = SubscribeOptions());
259 
270  public: template<typename MessageT>
271  bool Subscribe(
272  const std::string &_topic,
273  void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
274  const SubscribeOptions &_opts = SubscribeOptions());
275 
285  public: template<typename MessageT>
286  bool Subscribe(
287  const std::string &_topic,
288  std::function<void(const MessageT &_msg,
289  const MessageInfo &_info)> &_callback,
290  const SubscribeOptions &_opts = SubscribeOptions());
291 
303  public: template<typename ClassT, typename MessageT>
304  bool Subscribe(
305  const std::string &_topic,
306  void(ClassT::*_callback)(const MessageT &_msg,
307  const MessageInfo &_info),
308  ClassT *_obj,
309  const SubscribeOptions &_opts = SubscribeOptions());
310 
316  public: std::vector<std::string> SubscribedTopics() const;
317 
321  public: bool Unsubscribe(const std::string &_topic);
322 
335  public: template<typename RequestT, typename ReplyT>
336  bool Advertise(
337  const std::string &_topic,
338  bool(*_callback)(const RequestT &_request, ReplyT &_reply),
340 
352  public: template<typename ReplyT>
353  bool Advertise(
354  const std::string &_topic,
355  bool(*_callback)(ReplyT &_reply),
357 
368  public: template<typename RequestT>
369  bool Advertise(
370  const std::string &_topic,
371  void(*_callback)(const RequestT &_request),
373 
386  public: template<typename RequestT, typename ReplyT>
387  bool Advertise(
388  const std::string &_topic,
389  std::function<bool(const RequestT &_request,
390  ReplyT &_reply)> _callback,
392 
404  public: template<typename ReplyT>
405  bool Advertise(
406  const std::string &_topic,
407  std::function<bool(ReplyT &_reply)> &_callback,
409 
420  public: template<typename RequestT>
421  bool Advertise(
422  const std::string &_topic,
423  std::function<void(const RequestT &_request)> &_callback,
425 
439  public: template<typename ClassT, typename RequestT, typename ReplyT>
440  bool Advertise(
441  const std::string &_topic,
442  bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
443  ClassT *_obj,
445 
458  public: template<typename ClassT, typename ReplyT>
459  bool Advertise(
460  const std::string &_topic,
461  bool(ClassT::*_callback)(ReplyT &_reply),
462  ClassT *_obj,
464 
476  public: template<typename ClassT, typename RequestT>
477  bool Advertise(
478  const std::string &_topic,
479  void(ClassT::*_callback)(const RequestT &_request),
480  ClassT *_obj,
482 
485  public: std::vector<std::string> AdvertisedServices() const;
486 
498  public: template<typename RequestT, typename ReplyT>
499  bool Request(
500  const std::string &_topic,
501  const RequestT &_request,
502  void(*_callback)(const ReplyT &_reply, const bool _result));
503 
514  public: template<typename ReplyT>
515  bool Request(
516  const std::string &_topic,
517  void(*_callback)(const ReplyT &_reply, const bool _result));
518 
530  public: template<typename RequestT, typename ReplyT>
531  bool Request(
532  const std::string &_topic,
533  const RequestT &_request,
534  std::function<void(const ReplyT &_reply,
535  const bool _result)> &_callback);
536 
547  public: template<typename ReplyT>
548  bool Request(
549  const std::string &_topic,
550  std::function<void(const ReplyT &_reply,
551  const bool _result)> &_callback);
552 
565  public: template<typename ClassT, typename RequestT, typename ReplyT>
566  bool Request(
567  const std::string &_topic,
568  const RequestT &_request,
569  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
570  ClassT *_obj);
571 
583  public: template<typename ClassT, typename ReplyT>
584  bool Request(
585  const std::string &_topic,
586  void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
587  ClassT *_obj);
588 
598  public: template<typename RequestT, typename ReplyT>
599  bool Request(
600  const std::string &_topic,
601  const RequestT &_request,
602  const unsigned int &_timeout,
603  ReplyT &_reply,
604  bool &_result);
605 
614  public: template<typename ReplyT>
615  bool Request(
616  const std::string &_topic,
617  const unsigned int &_timeout,
618  ReplyT &_reply,
619  bool &_result);
620 
626  public: template<typename RequestT>
627  bool Request(const std::string &_topic, const RequestT &_request);
628 
632  public: bool UnadvertiseSrv(const std::string &_topic);
633 
640  public: void TopicList(std::vector<std::string> &_topics) const;
641 
646  public: bool TopicInfo(const std::string &_topic,
647  std::vector<MessagePublisher> &_publishers) const;
648 
655  public: void ServiceList(std::vector<std::string> &_services) const;
656 
661  public: bool ServiceInfo(
662  const std::string &_service,
663  std::vector<ServicePublisher> &_publishers) const;
664 
678  public: bool SubscribeRaw(
679  const std::string &_topic,
680  const RawCallback &_callback,
681  const std::string &_msgType = kGenericMessageType,
682  const SubscribeOptions &_opts = SubscribeOptions());
683 
686  public: const NodeOptions &Options() const;
687 
691  private: NodeShared *Shared() const;
692 
695  private: const std::string &NodeUuid() const;
696 
699  private: std::unordered_set<std::string> &TopicsSubscribed() const;
700 
703  private: std::unordered_set<std::string> &SrvsAdvertised() const;
704 
708  private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
709 
710 #ifdef _WIN32
711 // Disable warning C4251 which is triggered by
712 // std::unique_ptr
713 #pragma warning(push)
714 #pragma warning(disable: 4251)
715 #endif
719 #ifdef _WIN32
720 #pragma warning(pop)
721 #endif
722  };
723  }
724  }
725 }
726 
727 #include "ignition/transport/detail/Node.hh"
728 
729 #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