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_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 }
45 
46 namespace intra_process_manager
47 {
52 class IntraProcessManager;
53 }
54 
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 
102  const rmw_gid_t &
103  get_intra_process_gid() const;
104 
106 
109  get_publisher_handle();
110 
112 
114  const rcl_publisher_t *
115  get_publisher_handle() const;
116 
118 
121  get_event_handlers() const;
122 
124 
126  size_t
127  get_subscription_count() const;
128 
130 
132  size_t
133  get_intra_process_subscription_count() const;
134 
136 
145  bool
146  assert_liveliness() const;
147 
149 
160  get_actual_qos() const;
161 
163 
169  bool
170  operator==(const rmw_gid_t & gid) const;
171 
173 
179  bool
180  operator==(const rmw_gid_t * gid) const;
181 
184 
187  mapped_ring_buffer::MappedRingBufferBase::SharedPtr
188  virtual make_mapped_ring_buffer(size_t size) const;
189 
192  void
193  setup_intra_process(
194  uint64_t intra_process_publisher_id,
196  const rcl_publisher_options_t & intra_process_options);
197 
198 protected:
199  template<typename EventCallbackT>
200  void
202  const EventCallbackT & callback,
203  const rcl_publisher_event_type_t event_type)
204  {
205  auto handler = std::make_shared<QOSEventHandler<EventCallbackT>>(
206  callback,
208  &publisher_handle_,
209  event_type);
210  event_handlers_.emplace_back(handler);
211  }
212 
214 
216  rcl_publisher_t intra_process_publisher_handle_ = rcl_get_zero_initialized_publisher();
217 
219 
225 
228 };
229 
230 } // namespace rclcpp
231 
232 #endif // RCLCPP__PUBLISHER_BASE_HPP_
uint64_t intra_process_publisher_id_
Definition: publisher_base.hpp:224
Definition: publisher_base.hpp:55
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
bool intra_process_is_enabled_
Definition: publisher_base.hpp:222
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:226
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:213
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:223
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
#define RCUTILS_WARN_UNUSED
rmw_gid_t intra_process_rmw_gid_
Definition: publisher_base.hpp:227
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
Definition: publisher_base.hpp:218
void add_event_handler(const EventCallbackT &callback, const rcl_publisher_event_type_t event_type)
Definition: publisher_base.hpp:201