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 <chrono>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
27 #include "rclcpp/qos.hpp"
28 #include "rclcpp/qos_event.hpp"
31 
32 namespace rclcpp
33 {
34 
37 {
40 
42  bool use_default_callbacks = true;
43 
46 
48  rclcpp::CallbackGroup::SharedPtr callback_group = nullptr;
49 
52 
55 
59 
60  // Options to configure topic statistics collector in the subscription.
62  {
63  // Enable and disable topic statistics calculation and publication. Defaults to disabled.
65 
66  // Topic to which topic statistics get published when enabled. Defaults to /statistics.
67  std::string publish_topic = "/statistics";
68 
69  // Topic statistics publication period in ms. Defaults to one second.
70  // Only values greater than zero are allowed.
72  };
73 
75 };
76 
78 template<typename Allocator>
80 {
83 
85 
88  const SubscriptionOptionsBase & subscription_options_base)
89  : SubscriptionOptionsBase(subscription_options_base)
90  {}
91 
93 
97  template<typename MessageT>
100  {
101  rcl_subscription_options_t result = rcl_subscription_get_default_options();
102  using AllocatorTraits = std::allocator_traits<Allocator>;
103  using MessageAllocatorT = typename AllocatorTraits::template rebind_alloc<MessageT>;
104  auto message_alloc = std::make_shared<MessageAllocatorT>(*allocator.get());
105  result.allocator = allocator::get_rcl_allocator<MessageT>(*message_alloc);
106  result.qos = qos.get_rmw_qos_profile();
108 
109  // Apply payload to rcl_subscription_options if necessary.
110  if (rmw_implementation_payload && rmw_implementation_payload->has_been_customized()) {
111  rmw_implementation_payload->modify_rmw_subscription_options(result.rmw_subscription_options);
112  }
113 
114  return result;
115  }
116 
120  {
121  if (!this->allocator) {
122  return std::make_shared<Allocator>();
123  }
124  return this->allocator;
125  }
126 };
127 
129 } // namespace rclcpp
130 
131 #endif // RCLCPP__SUBSCRIPTION_OPTIONS_HPP_
rclcpp::SubscriptionOptionsBase::intra_process_buffer_type
IntraProcessBufferType intra_process_buffer_type
Setting the data-type stored in the intraprocess buffer.
Definition: subscription_options.hpp:54
rclcpp::SubscriptionOptionsBase::TopicStatisticsOptions::publish_topic
std::string publish_topic
Definition: subscription_options.hpp:67
rclcpp::SubscriptionOptionsBase::ignore_local_publications
bool ignore_local_publications
True to ignore local publications.
Definition: subscription_options.hpp:45
callback_group.hpp
rcl_subscription_options_t::allocator
rcl_allocator_t allocator
std::string
std::shared_ptr< rclcpp::detail::RMWImplementationSpecificSubscriptionPayload >
rcl_subscription_options_t::rmw_subscription_options
rmw_subscription_options_t rmw_subscription_options
rclcpp::IntraProcessSetting::NodeDefault
@ NodeDefault
Take intraprocess configuration from the node.
rclcpp::SubscriptionOptionsBase::rmw_implementation_payload
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:58
rclcpp::SubscriptionOptionsBase::TopicStatisticsOptions
Definition: subscription_options.hpp:61
rclcpp::QoS::get_rmw_qos_profile
rmw_qos_profile_t & get_rmw_qos_profile()
Return the rmw qos profile.
rmw_implementation_specific_subscription_payload.hpp
intra_process_setting.hpp
std::chrono::milliseconds
rclcpp::SubscriptionOptionsBase::TopicStatisticsOptions::state
TopicStatisticsState state
Definition: subscription_options.hpp:64
topic_statistics_state.hpp
std::shared_ptr::get
T get(T... args)
rclcpp::SubscriptionOptionsWithAllocator
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:79
rclcpp::SubscriptionOptionsWithAllocator::to_rcl_subscription_options
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:99
rclcpp::SubscriptionOptionsWithAllocator::get_allocator
std::shared_ptr< Allocator > get_allocator() const
Get the allocator, creating one if needed.
Definition: subscription_options.hpp:119
std::allocator_traits
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
qos.hpp
rclcpp::SubscriptionOptionsBase::event_callbacks
SubscriptionEventCallbacks event_callbacks
Callbacks for events related to this subscription.
Definition: subscription_options.hpp:39
rclcpp::TopicStatisticsState
TopicStatisticsState
Definition: topic_statistics_state.hpp:23
rclcpp::SubscriptionOptionsBase::use_default_callbacks
bool use_default_callbacks
Whether or not to use default callbacks when user doesn't supply any in event_callbacks.
Definition: subscription_options.hpp:42
rclcpp::QoS
Encapsulation of Quality of Service settings.
Definition: qos.hpp:59
rclcpp::TopicStatisticsState::NodeDefault
@ NodeDefault
Take topic statistics state from the node.
rcl_subscription_options_t::qos
rmw_qos_profile_t qos
intra_process_buffer_type.hpp
rclcpp::SubscriptionOptionsBase::TopicStatisticsOptions::publish_period
std::chrono::milliseconds publish_period
Definition: subscription_options.hpp:71
rclcpp::SubscriptionOptionsBase::callback_group
rclcpp::CallbackGroup::SharedPtr callback_group
The callback group for this subscription. NULL to use the default callback group.
Definition: subscription_options.hpp:48
rclcpp::IntraProcessSetting
IntraProcessSetting
Used as argument in create_publisher and create_subscriber.
Definition: intra_process_setting.hpp:22
rcl_subscription_options_t
rclcpp::SubscriptionOptionsWithAllocator::SubscriptionOptionsWithAllocator
SubscriptionOptionsWithAllocator(const SubscriptionOptionsBase &subscription_options_base)
Constructor using base class as input.
Definition: subscription_options.hpp:87
rclcpp::IntraProcessBufferType::CallbackDefault
@ CallbackDefault
Set the data type used in the intra-process buffer as the same used in the callback.
visibility_control.hpp
rmw_subscription_options_t::ignore_local_publications
bool ignore_local_publications
rclcpp::SubscriptionOptionsBase::use_intra_process_comm
IntraProcessSetting use_intra_process_comm
Setting to explicitly set intraprocess communications.
Definition: subscription_options.hpp:51
rclcpp::IntraProcessBufferType
IntraProcessBufferType
Definition: intra_process_buffer_type.hpp:23
rclcpp::SubscriptionOptionsWithAllocator::allocator
std::shared_ptr< Allocator > allocator
Optional custom allocator.
Definition: subscription_options.hpp:82
rclcpp::SubscriptionOptionsBase
Non-template base class for subscription options.
Definition: subscription_options.hpp:36
rclcpp::SubscriptionEventCallbacks
Contains callbacks for non-message events that a Subscription can receive from the middleware.
Definition: qos_event.hpp:57
qos_event.hpp
rclcpp::SubscriptionOptionsBase::topic_stats_options
TopicStatisticsOptions topic_stats_options
Definition: subscription_options.hpp:74