Gazebo Transport

API Reference

15.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 GZ_TRANSPORT_NODE_HH_
18#define GZ_TRANSPORT_NODE_HH_
19
20#include <memory>
21#include <optional>
22#include <string>
23#include <unordered_set>
24#include <vector>
26#include "gz/transport/config.hh"
27#include "gz/transport/Export.hh"
36
37namespace zenoh
38{
39 // Forward declaration.
40 class LivelinessToken;
41 class Publisher;
42}
43
44namespace gz::transport
45{
46 // Inline bracket to help doxygen filtering.
47 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
48 //
49 // Forward declarations.
50 class NodePrivate;
51
62 int GZ_TRANSPORT_VISIBLE rcvHwm();
63
74 int GZ_TRANSPORT_VISIBLE sndHwm();
75
80
83 struct GZ_TRANSPORT_VISIBLE TopicInfo
84 {
87
90
93 };
94
95 class GZ_TRANSPORT_VISIBLE Node
96 {
97 class PublisherPrivate;
98 class SubscriberPrivate;
99
116 public: class GZ_TRANSPORT_VISIBLE Publisher
117 {
119 public: Publisher();
120
123 public: explicit Publisher(const MessagePublisher &_publisher);
124
125#ifdef HAVE_ZENOH
130 public: explicit Publisher(const MessagePublisher &_publisher,
131 zenoh::Publisher &&_zPublisher,
132 zenoh::LivelinessToken &&_zToken);
133#endif
134
136 public: virtual ~Publisher();
137
141 public: operator bool();
142
146 public: operator bool() const;
147
151 public: bool Valid() const;
152
158 public: bool Publish(const ProtoMsg &_msg);
159
181 public: bool PublishRaw(
182 const std::string &_msgData,
183 const std::string &_msgType);
184
193 public: bool ThrottledUpdateReady() const;
194
198 private: bool UpdateThrottling();
199
202 public: bool HasConnections() const;
203
209#ifdef _WIN32
210// Disable warning C4251 which is triggered by
211// std::shared_ptr
212#pragma warning(push)
213#pragma warning(disable: 4251)
214#endif
215 private: std::shared_ptr<PublisherPrivate> dataPtr;
216#ifdef _WIN32
217#pragma warning(pop)
218#endif
219 };
220
234 public: class GZ_TRANSPORT_VISIBLE Subscriber
235 {
237 public: Subscriber();
238
244 public: Subscriber(const std::string &_topic,
245 const std::string &_nUuid,
246 const NodeOptions &_nOpts,
247 const std::string &_hUuid);
248
251 public: virtual ~Subscriber();
252
255 public: bool Unsubscribe();
256
260 public: operator bool();
261
265 public: operator bool() const;
266
269 public: Subscriber(Subscriber &&_other);
270
275
279 public: bool Valid() const;
280
283#ifdef _WIN32
284// Disable warning C4251 which is triggered by
285// std::shared_ptr
286#pragma warning(push)
287#pragma warning(disable: 4251)
288#endif
289 private: std::shared_ptr<SubscriberPrivate> dataPtr;
290#ifdef _WIN32
291#pragma warning(pop)
292#endif
293 };
294
298 public: Node();
299
304 public: explicit Node(const NodeOptions &_options);
305
307 public: virtual ~Node();
308
317 public: template<typename MessageT>
319 const std::string &_topic,
321
334 const std::string &_topic,
335 const std::string &_msgTypeName,
337
341
356 public: template <typename ...Args>
357 bool Subscribe(Args && ...args);
358
378 public: template <typename ...Args>
380 Args && ...args);
381
388
392 public: bool Unsubscribe(const std::string &_topic);
393
412 public: template<typename RequestT, typename ReplyT>
414 const std::string &_topic,
415 bool(*_callback)(const RequestT &_request, ReplyT &_reply),
417
435 public: template<typename ReplyT>
437 const std::string &_topic,
438 bool(*_callback)(ReplyT &_reply),
440
457 public: template<typename RequestT>
459 const std::string &_topic,
460 void(*_callback)(const RequestT &_request),
462
481 public: template<typename RequestT, typename ReplyT>
483 const std::string &_topic,
484 std::function<bool(const RequestT &_request,
485 ReplyT &_reply)> _callback,
487
505 public: template<typename ReplyT>
507 const std::string &_topic,
508 std::function<bool(ReplyT &_reply)> &_callback,
510
527 public: template<typename RequestT>
529 const std::string &_topic,
530 std::function<void(const RequestT &_request)> &_callback,
532
552 public: template<typename ClassT, typename RequestT, typename ReplyT>
554 const std::string &_topic,
555 bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
556 ClassT *_obj,
558
577 public: template<typename ClassT, typename ReplyT>
579 const std::string &_topic,
580 bool(ClassT::*_callback)(ReplyT &_reply),
581 ClassT *_obj,
583
601 public: template<typename ClassT, typename RequestT>
603 const std::string &_topic,
604 void(ClassT::*_callback)(const RequestT &_request),
605 ClassT *_obj,
607
611
623 public: template<typename RequestT, typename ReplyT>
625 const std::string &_topic,
626 const RequestT &_request,
627 void(*_callback)(const ReplyT &_reply, const bool _result));
628
639 public: template<typename ReplyT>
641 const std::string &_topic,
642 void(*_callback)(const ReplyT &_reply, const bool _result));
643
655 public: template<typename RequestT, typename ReplyT>
657 const std::string &_topic,
658 const RequestT &_request,
659 std::function<void(const ReplyT &_reply,
660 const bool _result)> &_callback);
661
672 public: template<typename ReplyT>
674 const std::string &_topic,
675 std::function<void(const ReplyT &_reply,
676 const bool _result)> &_callback);
677
690 public: template<typename ClassT, typename RequestT, typename ReplyT>
692 const std::string &_topic,
693 const RequestT &_request,
694 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
695 ClassT *_obj);
696
708 public: template<typename ClassT, typename ReplyT>
710 const std::string &_topic,
711 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
712 ClassT *_obj);
713
723 public: template<typename RequestT, typename ReplyT>
725 const std::string &_topic,
726 const RequestT &_request,
727 const unsigned int &_timeout,
728 ReplyT &_reply,
729 bool &_result);
730
739 public: template<typename ReplyT>
741 const std::string &_topic,
742 const unsigned int &_timeout,
743 ReplyT &_reply,
744 bool &_result);
745
751 public: template<typename RequestT>
752 bool Request(const std::string &_topic, const RequestT &_request);
753
768 public: bool RequestRaw(const std::string &_topic,
769 const std::string &_request, const std::string &_requestType,
770 const std::string &_responseType, unsigned int _timeout,
771 std::string &_response,
772 bool &_result);
773
777 public: bool UnadvertiseSrv(const std::string &_topic);
778
785 public: void TopicList(std::vector<std::string> &_topics) const;
786
792 public: bool TopicInfo(const std::string &_topic,
794 std::vector<MessagePublisher> &_subscribers) const;
795
799 public: bool AllTopicInfo(
801
808 public: void ServiceList(std::vector<std::string> &_services) const;
809
814 public: bool ServiceInfo(
815 const std::string &_service,
816 std::vector<ServicePublisher> &_publishers) const;
817
819 public: enum class ServiceTypeResolution
820 {
822 kResolved = 0,
823
825 kInvalidService,
826
829 kNoProviders,
830
833 kAmbiguousTypes,
834
837 kIncompatibleTypes,
838 };
839
863 const std::string &_service,
864 std::string &_reqType,
865 std::string &_repType,
866 unsigned int _timeoutMs = 0) const;
867
881 public: bool SubscribeRaw(
882 const std::string &_topic,
883 const RawCallback &_callback,
884 const std::string &_msgType = kGenericMessageType,
885 const SubscribeOptions &_opts = SubscribeOptions());
886
889 public: const NodeOptions &Options() const;
890
897 public: bool EnableStats(const std::string &_topic, bool _enable,
898 const std::string &_publicationTopic = "/statistics",
899 uint64_t _publicationRate = 1);
900
907 public: std::optional<TopicStatistics> TopicStats(
908 const std::string &_topic) const;
909
916 public: void AddGlobalRelay(const std::string& _relayAddress);
917
922
926 private: NodeShared *Shared() const;
927
930 private: const std::string &NodeUuid() const;
931
934 private: std::unordered_set<std::string> &TopicsSubscribed() const;
935
938 private: std::unordered_set<std::string> &SrvsAdvertised() const;
939
943 private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
944
950 private: bool TopicInfoHelper(const std::string &_topic,
952 std::vector<MessagePublisher> &_subscribers) const;
953
963 private: template<typename MessageT>
965 const std::string &_topic,
966 void(*_callback)(const MessageT &_msg),
967 const SubscribeOptions &_opts = SubscribeOptions());
968
977 private: template<typename MessageT>
979 const std::string &_topic,
980 std::function<void(const MessageT &_msg)> _callback,
981 const SubscribeOptions &_opts = SubscribeOptions());
982
993 private: template<typename ClassT, typename MessageT>
995 const std::string &_topic,
996 void(ClassT::*_callback)(const MessageT &_msg),
997 ClassT *_obj,
998 const SubscribeOptions &_opts = SubscribeOptions());
999
1010 private: template<typename MessageT>
1012 const std::string &_topic,
1013 void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
1014 const SubscribeOptions &_opts = SubscribeOptions());
1015
1025 private: template<typename MessageT>
1027 const std::string &_topic,
1028 std::function<void(const MessageT &_msg,
1029 const MessageInfo &_info)> _callback,
1030 const SubscribeOptions &_opts = SubscribeOptions());
1031
1043 private: template<typename ClassT, typename MessageT>
1045 const std::string &_topic,
1046 void(ClassT::*_callback)(const MessageT &_msg,
1047 const MessageInfo &_info),
1048 ClassT *_obj,
1049 const SubscribeOptions &_opts = SubscribeOptions());
1050
1051#ifdef _WIN32
1052// Disable warning C4251 which is triggered by
1053// std::unique_ptr
1054#pragma warning(push)
1055#pragma warning(disable: 4251)
1056#endif
1060#ifdef _WIN32
1061#pragma warning(pop)
1062#endif
1063 };
1064 }
1065}
1066
1067#include "gz/transport/detail/Node.hh"
1068
1069#endif