rclcpp  master
C++ ROS Client Library API
publisher_base.hpp
Go to the documentation of this file.
1 // Copyright 2014 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__PUBLISHER_BASE_HPP_
16 #define RCLCPP__PUBLISHER_BASE_HPP_
17 
18 #include <rmw/error_handling.h>
19 #include <rmw/rmw.h>
20 
21 #include <functional>
22 #include <iostream>
23 #include <memory>
24 #include <sstream>
25 #include <string>
26 #include <vector>
27 
28 #include "rcl/publisher.h"
29 
30 #include "rclcpp/macros.hpp"
31 #include "rclcpp/qos.hpp"
32 #include "rclcpp/qos_event.hpp"
35 
36 namespace rclcpp
37 {
38 
39 // Forward declaration is used for friend statement.
40 namespace node_interfaces
41 {
42 class NodeBaseInterface;
43 class NodeTopicsInterface;
44 } // namespace node_interfaces
45 
46 namespace experimental
47 {
52 class IntraProcessManager;
53 } // namespace experimental
54 
55 class PublisherBase : public std::enable_shared_from_this<PublisherBase>
56 {
57  friend ::rclcpp::node_interfaces::NodeTopicsInterface;
58 
59 public:
61 
62 
63 
74  const std::string & topic,
75  const rosidl_message_type_support_t & type_support,
76  const rcl_publisher_options_t & publisher_options);
77 
79  virtual ~PublisherBase();
80 
82 
84  const char *
85  get_topic_name() const;
86 
88 
90  size_t
91  get_queue_size() const;
92 
94 
96  const rmw_gid_t &
97  get_gid() const;
98 
100 
104 
106 
109  get_publisher_handle() const;
110 
112 
115  get_event_handlers() const;
116 
118 
120  size_t
121  get_subscription_count() const;
122 
124 
126  size_t
128 
130 
139  bool
140  assert_liveliness() const;
141 
143 
155  get_actual_qos() const;
156 
158 
163  bool
164  can_loan_messages() const;
165 
167 
173  bool
174  operator==(const rmw_gid_t & gid) const;
175 
177 
183  bool
184  operator==(const rmw_gid_t * gid) const;
185 
188 
191  void
193  uint64_t intra_process_publisher_id,
195 
196 protected:
197  template<typename EventCallbackT>
198  void
200  const EventCallbackT & callback,
201  const rcl_publisher_event_type_t event_type)
202  {
203  auto handler = std::make_shared<QOSEventHandler<EventCallbackT,
205  callback,
206  rcl_publisher_event_init,
208  event_type);
209  event_handlers_.emplace_back(handler);
210  }
211 
214 
216 
218 
220 
226 
228 };
229 
230 } // namespace rclcpp
231 
232 #endif // RCLCPP__PUBLISHER_BASE_HPP_
rclcpp::PublisherBase::weak_ipm_
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:224
rclcpp::PublisherBase::get_topic_name
const char * get_topic_name() const
Get the topic that this publisher publishes on.
std::string
std::shared_ptr< rcl_publisher_t >
rmw.h
rclcpp::PublisherBase::default_incompatible_qos_callback
void default_incompatible_qos_callback(QOSOfferedIncompatibleQoSInfo &info) const
std::make_shared
T make_shared(T... args)
std::vector
error_handling.h
rclcpp::PublisherBase::get_publisher_handle
std::shared_ptr< rcl_publisher_t > get_publisher_handle()
Get the rcl publisher handle.
rclcpp::PublisherBase::event_handlers_
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
Definition: publisher_base.hpp:219
rclcpp::PublisherBase::get_queue_size
size_t get_queue_size() const
Get the queue size for this publisher.
rclcpp::PublisherBase::publisher_handle_
std::shared_ptr< rcl_publisher_t > publisher_handle_
Definition: publisher_base.hpp:217
rclcpp::PublisherBase::operator==
bool operator==(const rmw_gid_t &gid) const
Compare this publisher to a gid.
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
qos.hpp
rclcpp::PublisherBase::PublisherBase
PublisherBase(rclcpp::node_interfaces::NodeBaseInterface *node_base, const std::string &topic, const rosidl_message_type_support_t &type_support, const rcl_publisher_options_t &publisher_options)
Default constructor.
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::node_interfaces::NodeBaseInterface
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
rclcpp::QoS
Encapsulation of Quality of Service settings.
Definition: qos.hpp:59
RCLCPP_SMART_PTR_DEFINITIONS
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
rclcpp::PublisherBase::setup_intra_process
void setup_intra_process(uint64_t intra_process_publisher_id, IntraProcessManagerSharedPtr ipm)
Implementation utility function used to setup intra process publishing after creation.
macros.hpp
rclcpp::PublisherBase::~PublisherBase
virtual ~PublisherBase()
rclcpp::PublisherBase::rcl_node_handle_
std::shared_ptr< rcl_node_t > rcl_node_handle_
Definition: publisher_base.hpp:215
rclcpp::PublisherBase
Definition: publisher_base.hpp:55
std::enable_shared_from_this
rclcpp::PublisherBase::add_event_handler
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:199
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
rclcpp::PublisherBase::intra_process_is_enabled_
bool intra_process_is_enabled_
Definition: publisher_base.hpp:223
std::weak_ptr< rclcpp::experimental::IntraProcessManager >
std::vector::emplace_back
T emplace_back(T... args)
rmw_gid_t
type_support_decl.hpp
visibility_control.hpp
rclcpp::PublisherBase::can_loan_messages
bool can_loan_messages() const
Check if publisher instance can loan messages.
rclcpp::PublisherBase::rmw_gid_
rmw_gid_t rmw_gid_
Definition: publisher_base.hpp:227
rclcpp::PublisherBase::intra_process_publisher_id_
uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:225
rmw_qos_incompatible_event_status_t
rclcpp::PublisherBase::get_subscription_count
size_t get_subscription_count() const
Get subscription count.
rclcpp::PublisherBase::get_event_handlers
const std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > & get_event_handlers() const
Get all the QoS event handlers associated with this publisher.
rclcpp::PublisherBase::assert_liveliness
RCUTILS_WARN_UNUSED bool assert_liveliness() const
Manually assert that this Publisher is alive (for RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC).
rcl_publisher_options_t
rclcpp::QOSEventHandler
Definition: qos_event.hpp:106
qos_event.hpp
rclcpp::PublisherBase::get_intra_process_subscription_count
size_t get_intra_process_subscription_count() const
Get intraprocess subscription count.
rclcpp::PublisherBase::get_gid
const rmw_gid_t & get_gid() const
Get the global identifier for this publisher (used in rmw and by DDS).
rclcpp::PublisherBase::get_actual_qos
rclcpp::QoS get_actual_qos() const
Get the actual QoS settings, after the defaults have been determined.