Gazebo Transport

API Reference

15.0.2
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"
35
36namespace zenoh
37{
38 // Forward declaration.
39 class LivelinessToken;
40 class Publisher;
41}
42
43namespace gz::transport
44{
45 // Inline bracket to help doxygen filtering.
46 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
47 //
48 // Forward declarations.
49 class NodePrivate;
50
61 int GZ_TRANSPORT_VISIBLE rcvHwm();
62
73 int GZ_TRANSPORT_VISIBLE sndHwm();
74
78 void GZ_TRANSPORT_VISIBLE waitForShutdown();
79
84 class GZ_TRANSPORT_VISIBLE Node
85 {
86 class PublisherPrivate;
87 class SubscriberPrivate;
88
105 public: class GZ_TRANSPORT_VISIBLE Publisher
106 {
108 public: Publisher();
109
112 public: explicit Publisher(const MessagePublisher &_publisher);
113
114#ifdef HAVE_ZENOH
119 public: explicit Publisher(const MessagePublisher &_publisher,
120 zenoh::Publisher &&_zPublisher,
121 zenoh::LivelinessToken &&_zToken);
122#endif
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
223 public: class GZ_TRANSPORT_VISIBLE Subscriber
224 {
226 public: Subscriber();
227
233 public: Subscriber(const std::string &_topic,
234 const std::string &_nUuid,
235 const NodeOptions &_nOpts,
236 const std::string &_hUuid);
237
240 public: virtual ~Subscriber();
241
244 public: bool Unsubscribe();
245
249 public: operator bool();
250
254 public: operator bool() const;
255
258 public: Subscriber(Subscriber &&_other);
259
264
268 public: bool Valid() const;
269
272#ifdef _WIN32
273// Disable warning C4251 which is triggered by
274// std::shared_ptr
275#pragma warning(push)
276#pragma warning(disable: 4251)
277#endif
278 private: std::shared_ptr<SubscriberPrivate> dataPtr;
279#ifdef _WIN32
280#pragma warning(pop)
281#endif
282 };
283
287 public: Node();
288
293 public: explicit Node(const NodeOptions &_options);
294
296 public: virtual ~Node();
297
306 public: template<typename MessageT>
308 const std::string &_topic,
310
323 const std::string &_topic,
324 const std::string &_msgTypeName,
326
330
345 public: template <typename ...Args>
346 bool Subscribe(Args && ...args);
347
367 public: template <typename ...Args>
369 Args && ...args);
370
377
381 public: bool Unsubscribe(const std::string &_topic);
382
401 public: template<typename RequestT, typename ReplyT>
403 const std::string &_topic,
404 bool(*_callback)(const RequestT &_request, ReplyT &_reply),
406
424 public: template<typename ReplyT>
426 const std::string &_topic,
427 bool(*_callback)(ReplyT &_reply),
429
446 public: template<typename RequestT>
448 const std::string &_topic,
449 void(*_callback)(const RequestT &_request),
451
470 public: template<typename RequestT, typename ReplyT>
472 const std::string &_topic,
473 std::function<bool(const RequestT &_request,
474 ReplyT &_reply)> _callback,
476
494 public: template<typename ReplyT>
496 const std::string &_topic,
497 std::function<bool(ReplyT &_reply)> &_callback,
499
516 public: template<typename RequestT>
518 const std::string &_topic,
519 std::function<void(const RequestT &_request)> &_callback,
521
541 public: template<typename ClassT, typename RequestT, typename ReplyT>
543 const std::string &_topic,
544 bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
545 ClassT *_obj,
547
566 public: template<typename ClassT, typename ReplyT>
568 const std::string &_topic,
569 bool(ClassT::*_callback)(ReplyT &_reply),
570 ClassT *_obj,
572
590 public: template<typename ClassT, typename RequestT>
592 const std::string &_topic,
593 void(ClassT::*_callback)(const RequestT &_request),
594 ClassT *_obj,
596
600
612 public: template<typename RequestT, typename ReplyT>
614 const std::string &_topic,
615 const RequestT &_request,
616 void(*_callback)(const ReplyT &_reply, const bool _result));
617
628 public: template<typename ReplyT>
630 const std::string &_topic,
631 void(*_callback)(const ReplyT &_reply, const bool _result));
632
644 public: template<typename RequestT, typename ReplyT>
646 const std::string &_topic,
647 const RequestT &_request,
648 std::function<void(const ReplyT &_reply,
649 const bool _result)> &_callback);
650
661 public: template<typename ReplyT>
663 const std::string &_topic,
664 std::function<void(const ReplyT &_reply,
665 const bool _result)> &_callback);
666
679 public: template<typename ClassT, typename RequestT, typename ReplyT>
681 const std::string &_topic,
682 const RequestT &_request,
683 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
684 ClassT *_obj);
685
697 public: template<typename ClassT, typename ReplyT>
699 const std::string &_topic,
700 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
701 ClassT *_obj);
702
712 public: template<typename RequestT, typename ReplyT>
714 const std::string &_topic,
715 const RequestT &_request,
716 const unsigned int &_timeout,
717 ReplyT &_reply,
718 bool &_result);
719
728 public: template<typename ReplyT>
730 const std::string &_topic,
731 const unsigned int &_timeout,
732 ReplyT &_reply,
733 bool &_result);
734
740 public: template<typename RequestT>
741 bool Request(const std::string &_topic, const RequestT &_request);
742
757 public: bool RequestRaw(const std::string &_topic,
758 const std::string &_request, const std::string &_requestType,
759 const std::string &_responseType, unsigned int _timeout,
760 std::string &_response,
761 bool &_result);
762
766 public: bool UnadvertiseSrv(const std::string &_topic);
767
774 public: void TopicList(std::vector<std::string> &_topics) const;
775
781 public: bool TopicInfo(const std::string &_topic,
783 std::vector<MessagePublisher> &_subscribers) const;
784
791 public: void ServiceList(std::vector<std::string> &_services) const;
792
797 public: bool ServiceInfo(
798 const std::string &_service,
799 std::vector<ServicePublisher> &_publishers) const;
800
814 public: bool SubscribeRaw(
815 const std::string &_topic,
816 const RawCallback &_callback,
817 const std::string &_msgType = kGenericMessageType,
818 const SubscribeOptions &_opts = SubscribeOptions());
819
822 public: const NodeOptions &Options() const;
823
830 public: bool EnableStats(const std::string &_topic, bool _enable,
831 const std::string &_publicationTopic = "/statistics",
832 uint64_t _publicationRate = 1);
833
840 public: std::optional<TopicStatistics> TopicStats(
841 const std::string &_topic) const;
842
849 public: void AddGlobalRelay(const std::string& _relayAddress);
850
855
859 private: NodeShared *Shared() const;
860
863 private: const std::string &NodeUuid() const;
864
867 private: std::unordered_set<std::string> &TopicsSubscribed() const;
868
871 private: std::unordered_set<std::string> &SrvsAdvertised() const;
872
876 private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
877
887 private: template<typename MessageT>
889 const std::string &_topic,
890 void(*_callback)(const MessageT &_msg),
891 const SubscribeOptions &_opts = SubscribeOptions());
892
901 private: template<typename MessageT>
903 const std::string &_topic,
904 std::function<void(const MessageT &_msg)> _callback,
905 const SubscribeOptions &_opts = SubscribeOptions());
906
917 private: template<typename ClassT, typename MessageT>
919 const std::string &_topic,
920 void(ClassT::*_callback)(const MessageT &_msg),
921 ClassT *_obj,
922 const SubscribeOptions &_opts = SubscribeOptions());
923
934 private: template<typename MessageT>
936 const std::string &_topic,
937 void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
938 const SubscribeOptions &_opts = SubscribeOptions());
939
949 private: template<typename MessageT>
951 const std::string &_topic,
952 std::function<void(const MessageT &_msg,
953 const MessageInfo &_info)> _callback,
954 const SubscribeOptions &_opts = SubscribeOptions());
955
967 private: template<typename ClassT, typename MessageT>
969 const std::string &_topic,
970 void(ClassT::*_callback)(const MessageT &_msg,
971 const MessageInfo &_info),
972 ClassT *_obj,
973 const SubscribeOptions &_opts = SubscribeOptions());
974
975#ifdef _WIN32
976// Disable warning C4251 which is triggered by
977// std::unique_ptr
978#pragma warning(push)
979#pragma warning(disable: 4251)
980#endif
984#ifdef _WIN32
985#pragma warning(pop)
986#endif
987 };
988 }
989}
990
991#include "gz/transport/detail/Node.hh"
992
993#endif