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"
32 #include "rclcpp/qos.hpp"
33 #include "rclcpp/qos_event.hpp"
36 
37 namespace rclcpp
38 {
39 
40 // Forward declaration is used for friend statement.
41 namespace node_interfaces
42 {
43 class NodeBaseInterface;
44 class NodeTopicsInterface;
45 } // namespace node_interfaces
46 
47 namespace experimental
48 {
53 class IntraProcessManager;
54 } // namespace experimental
55 
56 class PublisherBase : public std::enable_shared_from_this<PublisherBase>
57 {
58  friend ::rclcpp::node_interfaces::NodeTopicsInterface;
59 
60 public:
62 
63 
64 
75  const std::string & topic,
76  const rosidl_message_type_support_t & type_support,
77  const rcl_publisher_options_t & publisher_options);
78 
80  virtual ~PublisherBase();
81 
83 
85  const char *
86  get_topic_name() const;
87 
89 
91  size_t
92  get_queue_size() const;
93 
95 
97  const rmw_gid_t &
98  get_gid() const;
99 
101 
105 
107 
110  get_publisher_handle() const;
111 
113 
116  get_event_handlers() const;
117 
119 
121  size_t
122  get_subscription_count() const;
123 
125 
127  size_t
129 
131 
140  bool
141  assert_liveliness() const;
142 
144 
156  get_actual_qos() const;
157 
159 
164  bool
165  can_loan_messages() const;
166 
168 
174  bool
175  operator==(const rmw_gid_t & gid) const;
176 
178 
184  bool
185  operator==(const rmw_gid_t * gid) const;
186 
189 
192  void
194  uint64_t intra_process_publisher_id,
196 
198 
205 
206 protected:
207  template<typename EventCallbackT>
208  void
210  const EventCallbackT & callback,
211  const rcl_publisher_event_type_t event_type)
212  {
213  auto handler = std::make_shared<QOSEventHandler<EventCallbackT,
215  callback,
218  event_type);
219  event_handlers_.emplace_back(handler);
220  }
221 
224 
226 
228 
230 
236 
238 };
239 
240 } // namespace rclcpp
241 
242 #endif // RCLCPP__PUBLISHER_BASE_HPP_
rclcpp::PublisherBase::weak_ipm_
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:234
rcl_publisher_event_type_t
rcl_publisher_event_type_t
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 >
network_flow_endpoint.hpp
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:229
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:227
rclcpp::PublisherBase::operator==
bool operator==(const rmw_gid_t &gid) const
Compare this publisher to a gid.
publisher.h
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:110
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:225
rclcpp::PublisherBase
Definition: publisher_base.hpp:56
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:209
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
rclcpp::PublisherBase::intra_process_is_enabled_
bool intra_process_is_enabled_
Definition: publisher_base.hpp:233
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:237
rclcpp::PublisherBase::intra_process_publisher_id_
uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:235
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_event_init
rcl_ret_t rcl_publisher_event_init(rcl_event_t *event, const rcl_publisher_t *publisher, const rcl_publisher_event_type_t event_type)
rcl_publisher_options_t
rclcpp::QOSEventHandler
Definition: qos_event.hpp:111
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.
rclcpp::PublisherBase::get_network_flow_endpoints
std::vector< rclcpp::NetworkFlowEndpoint > get_network_flow_endpoints() const
Get network flow endpoints.