rclcpp  master
C++ ROS Client Library API
create_intra_process_buffer.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__EXPERIMENTAL__CREATE_INTRA_PROCESS_BUFFER_HPP_
16 #define RCLCPP__EXPERIMENTAL__CREATE_INTRA_PROCESS_BUFFER_HPP_
17 
18 #include <memory>
19 #include <type_traits>
20 #include <utility>
21 
22 #include "rcl/subscription.h"
23 
27 
28 namespace rclcpp
29 {
30 namespace experimental
31 {
32 
33 template<
34  typename MessageT,
35  typename Alloc = std::allocator<void>,
39  IntraProcessBufferType buffer_type,
41  std::shared_ptr<Alloc> allocator)
42 {
43  using MessageSharedPtr = std::shared_ptr<const MessageT>;
44  using MessageUniquePtr = std::unique_ptr<MessageT, Deleter>;
45 
46  size_t buffer_size = qos.depth;
47 
49  typename IntraProcessBuffer<MessageT, Alloc, Deleter>::UniquePtr buffer;
50 
51  switch (buffer_type) {
53  {
54  using BufferT = MessageSharedPtr;
55 
56  auto buffer_implementation =
57  std::make_unique<rclcpp::experimental::buffers::RingBufferImplementation<BufferT>>(
58  buffer_size);
59 
60  // Construct the intra_process_buffer
61  buffer =
62  std::make_unique<rclcpp::experimental::buffers::TypedIntraProcessBuffer<MessageT, Alloc,
63  Deleter, BufferT>>(
64  std::move(buffer_implementation),
65  allocator);
66 
67  break;
68  }
70  {
71  using BufferT = MessageUniquePtr;
72 
73  auto buffer_implementation =
74  std::make_unique<rclcpp::experimental::buffers::RingBufferImplementation<BufferT>>(
75  buffer_size);
76 
77  // Construct the intra_process_buffer
78  buffer =
79  std::make_unique<rclcpp::experimental::buffers::TypedIntraProcessBuffer<MessageT, Alloc,
80  Deleter, BufferT>>(
81  std::move(buffer_implementation),
82  allocator);
83 
84  break;
85  }
86  default:
87  {
88  throw std::runtime_error("Unrecognized IntraProcessBufferType value");
89  break;
90  }
91  }
92 
93  return buffer;
94 }
95 
96 } // namespace experimental
97 } // namespace rclcpp
98 
99 #endif // RCLCPP__EXPERIMENTAL__CREATE_INTRA_PROCESS_BUFFER_HPP_
rclcpp::IntraProcessBufferType::UniquePtr
@ UniquePtr
Set the data type used in the intra-process buffer as std::unique_ptr<MessageT>
std::shared_ptr
std::move
T move(T... args)
rclcpp::experimental::create_intra_process_buffer
rclcpp::experimental::buffers::IntraProcessBuffer< MessageT, Alloc, Deleter >::UniquePtr create_intra_process_buffer(IntraProcessBufferType buffer_type, rmw_qos_profile_t qos, std::shared_ptr< Alloc > allocator)
Definition: create_intra_process_buffer.hpp:38
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
intra_process_buffer_type.hpp
intra_process_buffer.hpp
ring_buffer_implementation.hpp
rclcpp::IntraProcessBufferType::SharedPtr
@ SharedPtr
Set the data type used in the intra-process buffer as std::shared_ptr<MessageT>
std::runtime_error
rclcpp::experimental::buffers::TypedIntraProcessBuffer
Definition: intra_process_buffer.hpp:73
rclcpp::allocator::Deleter
typename std::conditional< std::is_same< typename std::allocator_traits< Alloc >::template rebind_alloc< T >, typename std::allocator< void >::template rebind< T >::other >::value, std::default_delete< T >, AllocatorDeleter< Alloc > >::type Deleter
Definition: allocator_deleter.hpp:101
rmw_qos_profile_t
rclcpp::IntraProcessBufferType
IntraProcessBufferType
Definition: intra_process_buffer_type.hpp:23
std::allocator
std::unique_ptr
rclcpp::experimental::buffers::IntraProcessBuffer
Definition: intra_process_buffer.hpp:51
std::default_delete
rmw_qos_profile_t::depth
size_t depth