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 "rmw/rmw.h"
25 
29 #include "rclcpp/macros.hpp"
30 #include "rclcpp/qos.hpp"
31 #include "rclcpp/qos_event.hpp"
34 
35 namespace rclcpp
36 {
37 
38 namespace node_interfaces
39 {
40 class NodeBaseInterface;
41 } // namespace node_interfaces
42 
43 namespace experimental
44 {
49 class IntraProcessManager;
50 } // namespace experimental
51 
54 class SubscriptionBase : public std::enable_shared_from_this<SubscriptionBase>
55 {
56 public:
58 
59 
60 
70  const rosidl_message_type_support_t & type_support_handle,
71  const std::string & topic_name,
72  const rcl_subscription_options_t & subscription_options,
73  bool is_serialized = false);
74 
77  virtual ~SubscriptionBase();
78 
81  const char *
82  get_topic_name() const;
83 
86  get_subscription_handle();
87 
90  get_subscription_handle() const;
91 
93 
96  get_event_handlers() const;
97 
99 
111  get_actual_qos() const;
112 
114 
116  virtual
118  create_message() = 0;
119 
121 
123  virtual
125  create_serialized_message() = 0;
126 
128 
133  virtual
134  void
135  handle_message(std::shared_ptr<void> & message, const rmw_message_info_t & message_info) = 0;
136 
138  virtual
139  void
140  handle_loaned_message(void * loaned_message, const rmw_message_info_t & message_info) = 0;
141 
143 
145  virtual
146  void
147  return_message(std::shared_ptr<void> & message) = 0;
148 
150 
152  virtual
153  void
154  return_serialized_message(std::shared_ptr<rcl_serialized_message_t> & message) = 0;
155 
157  const rosidl_message_type_support_t &
158  get_message_type_support_handle() const;
159 
161  bool
162  is_serialized() const;
163 
165 
167  size_t
168  get_publisher_count() const;
169 
171 
178  bool
179  can_loan_messages() const;
180 
183 
186  void
187  setup_intra_process(
188  uint64_t intra_process_subscription_id,
189  IntraProcessManagerWeakPtr weak_ipm);
190 
194  get_intra_process_waitable() const;
195 
196 protected:
197  template<typename EventCallbackT>
198  void
200  const EventCallbackT & callback,
201  const rcl_subscription_event_type_t event_type)
202  {
203  auto handler = std::make_shared<QOSEventHandler<EventCallbackT>>(
204  callback,
206  get_subscription_handle().get(),
207  event_type);
208  event_handlers_.emplace_back(handler);
209  }
210 
212  bool
213  matches_any_intra_process_publishers(const rmw_gid_t * sender_gid) const;
214 
216 
220 
222 
226 
227 private:
228  RCLCPP_DISABLE_COPY(SubscriptionBase)
229 
230  rosidl_message_type_support_t type_support_;
231  bool is_serialized_;
232 };
233 
234 } // namespace rclcpp
235 
236 #endif // RCLCPP__SUBSCRIPTION_BASE_HPP_
std::vector< std::shared_ptr< rclcpp::QOSEventHandlerBase > > event_handlers_
Definition: subscription_base.hpp:221
IntraProcessManagerWeakPtr weak_ipm_
Definition: subscription_base.hpp:224
std::shared_ptr< rcl_subscription_t > subscription_handle_
Definition: subscription_base.hpp:218
rclcpp::node_interfaces::NodeBaseInterface *const node_base_
Definition: subscription_base.hpp:215
#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)
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
This header provides the get_node_base_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:199
std::shared_ptr< rcl_subscription_t > intra_process_subscription_handle_
Definition: subscription_base.hpp:219
uint64_t intra_process_subscription_id_
Definition: subscription_base.hpp:225
bool use_intra_process_
Definition: subscription_base.hpp:223
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
Definition: macros.hpp:51
std::shared_ptr< rcl_node_t > node_handle_
Definition: subscription_base.hpp:217
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Set the data type used in the intra-process buffer as std::shared_ptr<MessageT>
Definition: subscription_base.hpp:54
rcl_subscription_event_type_t