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"
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 class GZ_TRANSPORT_VISIBLE Node
81 {
82 class PublisherPrivate;
83 class SubscriberPrivate;
84
101 public: class GZ_TRANSPORT_VISIBLE Publisher
102 {
104 public: Publisher();
105
108 public: explicit Publisher(const MessagePublisher &_publisher);
109
110#ifdef HAVE_ZENOH
115 public: explicit Publisher(const MessagePublisher &_publisher,
116 zenoh::Publisher &&_zPublisher,
117 zenoh::LivelinessToken &&_zToken);
118#endif
119
121 public: virtual ~Publisher();
122
126 public: operator bool();
127
131 public: operator bool() const;
132
136 public: bool Valid() const;
137
143 public: bool Publish(const ProtoMsg &_msg);
144
166 public: bool PublishRaw(
167 const std::string &_msgData,
168 const std::string &_msgType);
169
178 public: bool ThrottledUpdateReady() const;
179
183 private: bool UpdateThrottling();
184
187 public: bool HasConnections() const;
188
194#ifdef _WIN32
195// Disable warning C4251 which is triggered by
196// std::shared_ptr
197#pragma warning(push)
198#pragma warning(disable: 4251)
199#endif
200 private: std::shared_ptr<PublisherPrivate> dataPtr;
201#ifdef _WIN32
202#pragma warning(pop)
203#endif
204 };
205
219 public: class GZ_TRANSPORT_VISIBLE Subscriber
220 {
222 public: Subscriber();
223
229 public: Subscriber(const std::string &_topic,
230 const std::string &_nUuid,
231 const NodeOptions &_nOpts,
232 const std::string &_hUuid);
233
236 public: virtual ~Subscriber();
237
240 public: bool Unsubscribe();
241
245 public: operator bool();
246
250 public: operator bool() const;
251
254 public: Subscriber(Subscriber &&_other);
255
260
264 public: bool Valid() const;
265
268#ifdef _WIN32
269// Disable warning C4251 which is triggered by
270// std::shared_ptr
271#pragma warning(push)
272#pragma warning(disable: 4251)
273#endif
274 private: std::shared_ptr<SubscriberPrivate> dataPtr;
275#ifdef _WIN32
276#pragma warning(pop)
277#endif
278 };
279
283 public: Node();
284
289 public: explicit Node(const NodeOptions &_options);
290
292 public: virtual ~Node();
293
302 public: template<typename MessageT>
304 const std::string &_topic,
306
319 const std::string &_topic,
320 const std::string &_msgTypeName,
322
326
341 public: template <typename ...Args>
342 bool Subscribe(Args && ...args);
343
363 public: template <typename ...Args>
365 Args && ...args);
366
373
377 public: bool Unsubscribe(const std::string &_topic);
378
397 public: template<typename RequestT, typename ReplyT>
399 const std::string &_topic,
400 bool(*_callback)(const RequestT &_request, ReplyT &_reply),
402
420 public: template<typename ReplyT>
422 const std::string &_topic,
423 bool(*_callback)(ReplyT &_reply),
425
442 public: template<typename RequestT>
444 const std::string &_topic,
445 void(*_callback)(const RequestT &_request),
447
466 public: template<typename RequestT, typename ReplyT>
468 const std::string &_topic,
469 std::function<bool(const RequestT &_request,
470 ReplyT &_reply)> _callback,
472
490 public: template<typename ReplyT>
492 const std::string &_topic,
493 std::function<bool(ReplyT &_reply)> &_callback,
495
512 public: template<typename RequestT>
514 const std::string &_topic,
515 std::function<void(const RequestT &_request)> &_callback,
517
537 public: template<typename ClassT, typename RequestT, typename ReplyT>
539 const std::string &_topic,
540 bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
541 ClassT *_obj,
543
562 public: template<typename ClassT, typename ReplyT>
564 const std::string &_topic,
565 bool(ClassT::*_callback)(ReplyT &_reply),
566 ClassT *_obj,
568
586 public: template<typename ClassT, typename RequestT>
588 const std::string &_topic,
589 void(ClassT::*_callback)(const RequestT &_request),
590 ClassT *_obj,
592
596
608 public: template<typename RequestT, typename ReplyT>
610 const std::string &_topic,
611 const RequestT &_request,
612 void(*_callback)(const ReplyT &_reply, const bool _result));
613
624 public: template<typename ReplyT>
626 const std::string &_topic,
627 void(*_callback)(const ReplyT &_reply, const bool _result));
628
640 public: template<typename RequestT, typename ReplyT>
642 const std::string &_topic,
643 const RequestT &_request,
644 std::function<void(const ReplyT &_reply,
645 const bool _result)> &_callback);
646
657 public: template<typename ReplyT>
659 const std::string &_topic,
660 std::function<void(const ReplyT &_reply,
661 const bool _result)> &_callback);
662
675 public: template<typename ClassT, typename RequestT, typename ReplyT>
677 const std::string &_topic,
678 const RequestT &_request,
679 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
680 ClassT *_obj);
681
693 public: template<typename ClassT, typename ReplyT>
695 const std::string &_topic,
696 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
697 ClassT *_obj);
698
708 public: template<typename RequestT, typename ReplyT>
710 const std::string &_topic,
711 const RequestT &_request,
712 const unsigned int &_timeout,
713 ReplyT &_reply,
714 bool &_result);
715
724 public: template<typename ReplyT>
726 const std::string &_topic,
727 const unsigned int &_timeout,
728 ReplyT &_reply,
729 bool &_result);
730
736 public: template<typename RequestT>
737 bool Request(const std::string &_topic, const RequestT &_request);
738
753 public: bool RequestRaw(const std::string &_topic,
754 const std::string &_request, const std::string &_requestType,
755 const std::string &_responseType, unsigned int _timeout,
756 std::string &_response,
757 bool &_result);
758
762 public: bool UnadvertiseSrv(const std::string &_topic);
763
770 public: void TopicList(std::vector<std::string> &_topics) const;
771
777 public: bool TopicInfo(const std::string &_topic,
779 std::vector<MessagePublisher> &_subscribers) const;
780
787 public: void ServiceList(std::vector<std::string> &_services) const;
788
793 public: bool ServiceInfo(
794 const std::string &_service,
795 std::vector<ServicePublisher> &_publishers) const;
796
810 public: bool SubscribeRaw(
811 const std::string &_topic,
812 const RawCallback &_callback,
813 const std::string &_msgType = kGenericMessageType,
814 const SubscribeOptions &_opts = SubscribeOptions());
815
818 public: const NodeOptions &Options() const;
819
826 public: bool EnableStats(const std::string &_topic, bool _enable,
827 const std::string &_publicationTopic = "/statistics",
828 uint64_t _publicationRate = 1);
829
836 public: std::optional<TopicStatistics> TopicStats(
837 const std::string &_topic) const;
838
845 public: void AddGlobalRelay(const std::string& _relayAddress);
846
851
855 private: NodeShared *Shared() const;
856
859 private: const std::string &NodeUuid() const;
860
863 private: std::unordered_set<std::string> &TopicsSubscribed() const;
864
867 private: std::unordered_set<std::string> &SrvsAdvertised() const;
868
872 private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
873
883 private: template<typename MessageT>
885 const std::string &_topic,
886 void(*_callback)(const MessageT &_msg),
887 const SubscribeOptions &_opts = SubscribeOptions());
888
897 private: template<typename MessageT>
899 const std::string &_topic,
900 std::function<void(const MessageT &_msg)> _callback,
901 const SubscribeOptions &_opts = SubscribeOptions());
902
913 private: template<typename ClassT, typename MessageT>
915 const std::string &_topic,
916 void(ClassT::*_callback)(const MessageT &_msg),
917 ClassT *_obj,
918 const SubscribeOptions &_opts = SubscribeOptions());
919
930 private: template<typename MessageT>
932 const std::string &_topic,
933 void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
934 const SubscribeOptions &_opts = SubscribeOptions());
935
945 private: template<typename MessageT>
947 const std::string &_topic,
948 std::function<void(const MessageT &_msg,
949 const MessageInfo &_info)> _callback,
950 const SubscribeOptions &_opts = SubscribeOptions());
951
963 private: template<typename ClassT, typename MessageT>
965 const std::string &_topic,
966 void(ClassT::*_callback)(const MessageT &_msg,
967 const MessageInfo &_info),
968 ClassT *_obj,
969 const SubscribeOptions &_opts = SubscribeOptions());
970
971#ifdef _WIN32
972// Disable warning C4251 which is triggered by
973// std::unique_ptr
974#pragma warning(push)
975#pragma warning(disable: 4251)
976#endif
980#ifdef _WIN32
981#pragma warning(pop)
982#endif
983 };
984 }
985}
986
987#include "gz/transport/detail/Node.hh"
988
989#endif