rclcpp  master
C++ ROS Client Library API
subscription_base.hpp
Go to the documentation of this file.
1 // Copyright 2019 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__SUBSCRIPTION_BASE_HPP_
16 #define RCLCPP__SUBSCRIPTION_BASE_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "rcl/subscription.h"
23 
24 #include "rcl_interfaces/msg/intra_process_message.hpp"
25 
26 #include "rmw/rmw.h"
27 
29 #include "rclcpp/macros.hpp"
30 #include "rclcpp/qos_event.hpp"
33 
34 namespace rclcpp
35 {
36 
37 namespace node_interfaces
38 {
39 class NodeTopicsInterface;
40 } // namespace node_interfaces
41 
42 namespace intra_process_manager
43 {
48 class IntraProcessManager;
49 }
50 
54 {
55 public:
57 
58 
59 
68  std::shared_ptr<rcl_node_t> node_handle,
69  const rosidl_message_type_support_t & type_support_handle,
70  const std::string & topic_name,
71  const rcl_subscription_options_t & subscription_options,
72  bool is_serialized = false);
73 
76  virtual ~SubscriptionBase();
77 
80  const char *
81  get_topic_name() const;
82 
85  get_subscription_handle();
86 
89  get_subscription_handle() const;
90 
93  get_intra_process_subscription_handle() const;
94 
96 
99  get_event_handlers() const;
100 
102 
103  virtual std::shared_ptr<void>
104  create_message() = 0;
105 
107 
109  create_serialized_message() = 0;
110 
112 
116  virtual void
117  handle_message(std::shared_ptr<void> & message, const rmw_message_info_t & message_info) = 0;
118 
120 
121  virtual void
122  return_message(std::shared_ptr<void> & message) = 0;
123 
125 
126  virtual void
127  return_serialized_message(std::shared_ptr<rcl_serialized_message_t> & message) = 0;
128 
129  virtual void
130  handle_intra_process_message(
131  rcl_interfaces::msg::IntraProcessMessage & ipm,
132  const rmw_message_info_t & message_info) = 0;
133 
134  const rosidl_message_type_support_t &
135  get_message_type_support_handle() const;
136 
137  bool
138  is_serialized() const;
139 
141 
143  size_t
144  get_publisher_count() const;
145 
148 
150  void setup_intra_process(
151  uint64_t intra_process_subscription_id,
153  const rcl_subscription_options_t & intra_process_options);
154 
155 protected:
156  template<typename EventCallbackT>
157  void
159  const EventCallbackT & callback,
160  const rcl_subscription_event_type_t event_type)
161  {
162  auto handler = std::make_shared<QOSEventHandler<EventCallbackT>>(
163  callback,
165  get_subscription_handle().get(),
166  event_type);
167  event_handlers_.emplace_back(handler);
168  }
169 
173 
175 
179 
180 private:
181  RCLCPP_DISABLE_COPY(SubscriptionBase)
182 
183  rosidl_message_type_support_t type_support_;
184  bool is_serialized_;
185 };
186 
187 } // namespace rclcpp
188 
189 #endif // RCLCPP__SUBSCRIPTION_BASE_HPP_
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
Definition: subscription_base.hpp:174
IntraProcessManagerWeakPtr weak_ipm_
Definition: subscription_base.hpp:177
std::shared_ptr< rcl_subscription_t > subscription_handle_
Definition: subscription_base.hpp:171
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
rcl_ret_t rcl_subscription_event_init(rcl_event_t *event, const rcl_subscription_t *subscription, const rcl_subscription_event_type_t event_type)
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
void add_event_handler(const EventCallbackT &callback, const rcl_subscription_event_type_t event_type)
Definition: subscription_base.hpp:158
std::shared_ptr< rcl_subscription_t > intra_process_subscription_handle_
Definition: subscription_base.hpp:172
uint64_t intra_process_subscription_id_
Definition: subscription_base.hpp:178
bool use_intra_process_
Definition: subscription_base.hpp:176
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
std::shared_ptr< rcl_node_t > node_handle_
Definition: subscription_base.hpp:170
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Definition: subscription_base.hpp:53
rcl_subscription_event_type_t