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 
103  get_publisher_handle();
104 
106 
108  const rcl_publisher_t *
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
127  get_intra_process_subscription_count() const;
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
192  setup_intra_process(
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>>(
204  callback,
206  &publisher_handle_,
207  event_type);
208  event_handlers_.emplace_back(handler);
209  }
210 
212 
214 
216 
222 
224 };
225 
226 } // namespace rclcpp
227 
228 #endif // RCLCPP__PUBLISHER_BASE_HPP_
uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:221
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
Definition: publisher_base.hpp:55
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
bool intra_process_is_enabled_
Definition: publisher_base.hpp:219
rcl_publisher_t rcl_get_zero_initialized_publisher(void)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
rmw_gid_t rmw_gid_
Definition: publisher_base.hpp:223
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
rcl_publisher_event_type_t
std::shared_ptr< rcl_node_t > rcl_node_handle_
Definition: publisher_base.hpp:211
rcl_ret_t rcl_publisher_event_init(rcl_event_t *event, const rcl_publisher_t *publisher, const rcl_publisher_event_type_t event_type)
IntraProcessManagerWeakPtr weak_ipm_
Definition: publisher_base.hpp:220
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
#define RCUTILS_WARN_UNUSED
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
Definition: publisher_base.hpp:215
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:199