Gazebo Transport

API Reference

15.0.0~pre1
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
284 public: Node();
285
288 public: explicit Node(const NodeOptions &_options);
289
291 public: virtual ~Node();
292
301 public: template<typename MessageT>
303 const std::string &_topic,
305
318 const std::string &_topic,
319 const std::string &_msgTypeName,
321
325
340 public: template <typename ...Args>
341 bool Subscribe(Args && ...args);
342
362 public: template <typename ...Args>
364 Args && ...args);
365
372
376 public: bool Unsubscribe(const std::string &_topic);
377
390 public: template<typename RequestT, typename ReplyT>
392 const std::string &_topic,
393 bool(*_callback)(const RequestT &_request, ReplyT &_reply),
395
407 public: template<typename ReplyT>
409 const std::string &_topic,
410 bool(*_callback)(ReplyT &_reply),
412
423 public: template<typename RequestT>
425 const std::string &_topic,
426 void(*_callback)(const RequestT &_request),
428
441 public: template<typename RequestT, typename ReplyT>
443 const std::string &_topic,
444 std::function<bool(const RequestT &_request,
445 ReplyT &_reply)> _callback,
447
459 public: template<typename ReplyT>
461 const std::string &_topic,
462 std::function<bool(ReplyT &_reply)> &_callback,
464
475 public: template<typename RequestT>
477 const std::string &_topic,
478 std::function<void(const RequestT &_request)> &_callback,
480
494 public: template<typename ClassT, typename RequestT, typename ReplyT>
496 const std::string &_topic,
497 bool(ClassT::*_callback)(const RequestT &_request, ReplyT &_reply),
498 ClassT *_obj,
500
513 public: template<typename ClassT, typename ReplyT>
515 const std::string &_topic,
516 bool(ClassT::*_callback)(ReplyT &_reply),
517 ClassT *_obj,
519
531 public: template<typename ClassT, typename RequestT>
533 const std::string &_topic,
534 void(ClassT::*_callback)(const RequestT &_request),
535 ClassT *_obj,
537
541
553 public: template<typename RequestT, typename ReplyT>
555 const std::string &_topic,
556 const RequestT &_request,
557 void(*_callback)(const ReplyT &_reply, const bool _result));
558
569 public: template<typename ReplyT>
571 const std::string &_topic,
572 void(*_callback)(const ReplyT &_reply, const bool _result));
573
585 public: template<typename RequestT, typename ReplyT>
587 const std::string &_topic,
588 const RequestT &_request,
589 std::function<void(const ReplyT &_reply,
590 const bool _result)> &_callback);
591
602 public: template<typename ReplyT>
604 const std::string &_topic,
605 std::function<void(const ReplyT &_reply,
606 const bool _result)> &_callback);
607
620 public: template<typename ClassT, typename RequestT, typename ReplyT>
622 const std::string &_topic,
623 const RequestT &_request,
624 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
625 ClassT *_obj);
626
638 public: template<typename ClassT, typename ReplyT>
640 const std::string &_topic,
641 void(ClassT::*_callback)(const ReplyT &_reply, const bool _result),
642 ClassT *_obj);
643
653 public: template<typename RequestT, typename ReplyT>
655 const std::string &_topic,
656 const RequestT &_request,
657 const unsigned int &_timeout,
658 ReplyT &_reply,
659 bool &_result);
660
669 public: template<typename ReplyT>
671 const std::string &_topic,
672 const unsigned int &_timeout,
673 ReplyT &_reply,
674 bool &_result);
675
681 public: template<typename RequestT>
682 bool Request(const std::string &_topic, const RequestT &_request);
683
698 public: bool RequestRaw(const std::string &_topic,
699 const std::string &_request, const std::string &_requestType,
700 const std::string &_responseType, unsigned int _timeout,
701 std::string &_response,
702 bool &_result);
703
707 public: bool UnadvertiseSrv(const std::string &_topic);
708
715 public: void TopicList(std::vector<std::string> &_topics) const;
716
722 public: bool TopicInfo(const std::string &_topic,
724 std::vector<MessagePublisher> &_subscribers) const;
725
732 public: void ServiceList(std::vector<std::string> &_services) const;
733
738 public: bool ServiceInfo(
739 const std::string &_service,
740 std::vector<ServicePublisher> &_publishers) const;
741
755 public: bool SubscribeRaw(
756 const std::string &_topic,
757 const RawCallback &_callback,
758 const std::string &_msgType = kGenericMessageType,
759 const SubscribeOptions &_opts = SubscribeOptions());
760
763 public: const NodeOptions &Options() const;
764
771 public: bool EnableStats(const std::string &_topic, bool _enable,
772 const std::string &_publicationTopic = "/statistics",
773 uint64_t _publicationRate = 1);
774
781 public: std::optional<TopicStatistics> TopicStats(
782 const std::string &_topic) const;
783
790 public: void AddGlobalRelay(const std::string& _relayAddress);
791
796
800 private: NodeShared *Shared() const;
801
804 private: const std::string &NodeUuid() const;
805
808 private: std::unordered_set<std::string> &TopicsSubscribed() const;
809
812 private: std::unordered_set<std::string> &SrvsAdvertised() const;
813
817 private: bool SubscribeHelper(const std::string &_fullyQualifiedTopic);
818
828 private: template<typename MessageT>
830 const std::string &_topic,
831 void(*_callback)(const MessageT &_msg),
832 const SubscribeOptions &_opts = SubscribeOptions());
833
842 private: template<typename MessageT>
844 const std::string &_topic,
845 std::function<void(const MessageT &_msg)> _callback,
846 const SubscribeOptions &_opts = SubscribeOptions());
847
858 private: template<typename ClassT, typename MessageT>
860 const std::string &_topic,
861 void(ClassT::*_callback)(const MessageT &_msg),
862 ClassT *_obj,
863 const SubscribeOptions &_opts = SubscribeOptions());
864
875 private: template<typename MessageT>
877 const std::string &_topic,
878 void(*_callback)(const MessageT &_msg, const MessageInfo &_info),
879 const SubscribeOptions &_opts = SubscribeOptions());
880
890 private: template<typename MessageT>
892 const std::string &_topic,
893 std::function<void(const MessageT &_msg,
894 const MessageInfo &_info)> _callback,
895 const SubscribeOptions &_opts = SubscribeOptions());
896
908 private: template<typename ClassT, typename MessageT>
910 const std::string &_topic,
911 void(ClassT::*_callback)(const MessageT &_msg,
912 const MessageInfo &_info),
913 ClassT *_obj,
914 const SubscribeOptions &_opts = SubscribeOptions());
915
916#ifdef _WIN32
917// Disable warning C4251 which is triggered by
918// std::unique_ptr
919#pragma warning(push)
920#pragma warning(disable: 4251)
921#endif
925#ifdef _WIN32
926#pragma warning(pop)
927#endif
928 };
929 }
930}
931
932#include "gz/transport/detail/Node.hh"
933
934#endif