ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
resolve_intra_process_buffer_type.hpp
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__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_
16 #define RCLCPP__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_
17 
18 #include <stdexcept>
19 
20 #include "rclcpp/any_subscription_callback.hpp"
21 #include "rclcpp/intra_process_buffer_type.hpp"
22 
23 namespace rclcpp
24 {
25 
26 namespace detail
27 {
28 
30 template<typename CallbackMessageT, typename AllocatorT>
32 resolve_intra_process_buffer_type(
33  const rclcpp::IntraProcessBufferType buffer_type,
34  const rclcpp::AnySubscriptionCallback<CallbackMessageT, AllocatorT> & any_subscription_callback)
35 {
36  rclcpp::IntraProcessBufferType resolved_buffer_type = buffer_type;
37 
38  // If the user has not specified a type for the intra-process buffer, use the callback's type.
39  if (resolved_buffer_type == IntraProcessBufferType::CallbackDefault) {
40  if (any_subscription_callback.use_take_shared_method()) {
41  resolved_buffer_type = IntraProcessBufferType::SharedPtr;
42  } else {
43  resolved_buffer_type = IntraProcessBufferType::UniquePtr;
44  }
45  }
46 
47  return resolved_buffer_type;
48 }
49 
50 } // namespace detail
51 
52 } // namespace rclcpp
53 
54 #endif // RCLCPP__DETAIL__RESOLVE_INTRA_PROCESS_BUFFER_TYPE_HPP_
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
@ SharedPtr
Set the data type used in the intra-process buffer as std::shared_ptr<MessageT>
@ CallbackDefault
Set the data type used in the intra-process buffer as the same used in the callback.
@ UniquePtr
Set the data type used in the intra-process buffer as std::unique_ptr<MessageT>