15 #ifndef RCLCPP__CREATE_SUBSCRIPTION_HPP_
16 #define RCLCPP__CREATE_SUBSCRIPTION_HPP_
25 #include "rclcpp/detail/qos_parameters.hpp"
26 #include "rclcpp/node_interfaces/get_node_topics_interface.hpp"
27 #include "rclcpp/node_interfaces/node_parameters_interface.hpp"
28 #include "rclcpp/node_interfaces/node_topics_interface.hpp"
30 #include "rclcpp/qos.hpp"
31 #include "rclcpp/subscription_factory.hpp"
32 #include "rclcpp/subscription_options.hpp"
33 #include "rmw/qos_profiles.h"
44 typename SubscriptionT,
45 typename MessageMemoryStrategyT,
46 typename NodeParametersT,
49 typename std::shared_ptr<SubscriptionT>
51 NodeParametersT & node_parameters,
52 NodeTopicsT & node_topics,
53 const std::string & topic_name,
55 CallbackT && callback,
59 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
60 MessageMemoryStrategyT::create_default()
64 using rclcpp::node_interfaces::get_node_topics_interface;
65 auto node_topics_interface = get_node_topics_interface(node_topics);
67 auto factory = rclcpp::create_subscription_factory<MessageT>(
68 std::forward<CallbackT>(callback),
73 const rclcpp::QoS & actual_qos = options.qos_overriding_options.get_policy_kinds().size() ?
74 rclcpp::detail::declare_qos_parameters(
75 options.qos_overriding_options, node_parameters,
76 node_topics_interface->resolve_topic_name(topic_name),
80 auto sub = node_topics_interface->create_subscription(topic_name, factory, actual_qos);
81 node_topics_interface->add_subscription(sub, options.callback_group);
83 return std::dynamic_pointer_cast<SubscriptionT>(sub);
115 typename AllocatorT = std::allocator<void>,
117 typename MessageMemoryStrategyT =
typename SubscriptionT::MessageMemoryStrategyType,
119 typename std::shared_ptr<SubscriptionT>
122 const std::string & topic_name,
124 CallbackT && callback,
128 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
129 MessageMemoryStrategyT::create_default()
133 return rclcpp::detail::create_subscription<
134 MessageT, CallbackT, AllocatorT, SubscriptionT, MessageMemoryStrategyT>(
135 node, node, topic_name, qos, std::forward<CallbackT>(callback), options, msg_mem_strat);
145 typename AllocatorT = std::allocator<void>,
147 typename MessageMemoryStrategyT =
typename SubscriptionT::MessageMemoryStrategyType>
148 typename std::shared_ptr<SubscriptionT>
150 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr & node_parameters,
151 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr & node_topics,
152 const std::string & topic_name,
154 CallbackT && callback,
158 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
159 MessageMemoryStrategyT::create_default()
163 return rclcpp::detail::create_subscription<
164 MessageT, CallbackT, AllocatorT, SubscriptionT, MessageMemoryStrategyT>(
165 node_parameters, node_topics, topic_name, qos,
166 std::forward<CallbackT>(callback), options, msg_mem_strat);
Encapsulation of Quality of Service settings.
Subscription implementation, templated on the type of message this subscription receives.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
std::shared_ptr< SubscriptionT > create_subscription(NodeT &node, const std::string &topic_name, const rclcpp::QoS &qos, CallbackT &&callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()), typename MessageMemoryStrategyT::SharedPtr msg_mem_strat=(MessageMemoryStrategyT::create_default()))
Create and return a subscription of the given MessageT type.
Structure containing optional configuration for Subscriptions.