rclcpp  master
C++ ROS Client Library API
subscription_options.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_OPTIONS_HPP_
16 #define RCLCPP__SUBSCRIPTION_OPTIONS_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
26 #include "rclcpp/qos.hpp"
27 #include "rclcpp/qos_event.hpp"
29 
30 namespace rclcpp
31 {
32 
35 {
38 
41 
43  rclcpp::callback_group::CallbackGroup::SharedPtr callback_group = nullptr;
44 
47 
50 
54 };
55 
57 template<typename Allocator>
59 {
61  std::shared_ptr<Allocator> allocator = nullptr;
62 
64 
67  const SubscriptionOptionsBase & subscription_options_base)
68  : SubscriptionOptionsBase(subscription_options_base)
69  {}
70 
72  template<typename MessageT>
75  {
77  using AllocatorTraits = std::allocator_traits<Allocator>;
78  using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
79  auto message_alloc = std::make_shared<MessageAllocatorT>(*allocator.get());
80  result.allocator = allocator::get_rcl_allocator<MessageT>(*message_alloc);
81  result.qos = qos.get_rmw_qos_profile();
83 
84  // Apply payload to rcl_subscription_options if necessary.
85  if (rmw_implementation_payload && rmw_implementation_payload->has_been_customized()) {
86  rmw_implementation_payload->modify_rmw_subscription_options(result.rmw_subscription_options);
87  }
88 
89  return result;
90  }
91 
94  get_allocator() const
95  {
96  if (!this->allocator) {
97  return std::make_shared<Allocator>();
98  }
99  return this->allocator;
100  }
101 };
102 
104 
105 } // namespace rclcpp
106 
107 #endif // RCLCPP__SUBSCRIPTION_OPTIONS_HPP_
std::shared_ptr< Allocator > get_allocator() const
Get the allocator, creating one if needed.
Definition: subscription_options.hpp:94
Non-template base class for subscription options.
Definition: subscription_options.hpp:34
Encapsulation of Quality of Service settings.
Definition: qos.hpp:55
SubscriptionEventCallbacks event_callbacks
Callbacks for events related to this subscription.
Definition: subscription_options.hpp:37
IntraProcessSetting
Used as argument in create_publisher and create_subscriber.
Definition: intra_process_setting.hpp:22
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rmw_qos_profile_t qos
std::shared_ptr< rclcpp::detail::RMWImplementationSpecificSubscriptionPayload > rmw_implementation_payload
Optional RMW implementation specific payload to be used during creation of the subscription.
Definition: subscription_options.hpp:53
rcl_subscription_options_t rcl_subscription_get_default_options(void)
Set the data type used in the intra-process buffer as the same used in the callback.
T get(T... args)
rmw_subscription_options_t rmw_subscription_options
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:58
rcl_subscription_options_t to_rcl_subscription_options(const rclcpp::QoS &qos) const
Convert this class, with a rclcpp::QoS, into an rcl_subscription_options_t.
Definition: subscription_options.hpp:74
rclcpp::callback_group::CallbackGroup::SharedPtr callback_group
The callback group for this subscription. NULL to use the default callback group. ...
Definition: subscription_options.hpp:43
IntraProcessBufferType
Definition: intra_process_buffer_type.hpp:23
IntraProcessBufferType intra_process_buffer_type
Setting the data-type stored in the intraprocess buffer.
Definition: subscription_options.hpp:49
IntraProcessSetting use_intra_process_comm
Setting to explicitly set intraprocess communications.
Definition: subscription_options.hpp:46
rcl_allocator_t allocator
Contains callbacks for non-message events that a Subscription can receive from the middleware...
Definition: qos_event.hpp:49
SubscriptionOptionsWithAllocator(const SubscriptionOptionsBase &subscription_options_base)
Constructor using base class as input.
Definition: subscription_options.hpp:66
Take intraprocess configuration from the node.
bool ignore_local_publications
True to ignore local publications.
Definition: subscription_options.hpp:40