15 #ifndef RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
16 #define RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
24 #include "rclcpp/generic_subscription.hpp"
25 #include "rclcpp/node_interfaces/node_topics_interface.hpp"
26 #include "rclcpp/qos.hpp"
27 #include "rclcpp/serialized_message.hpp"
28 #include "rclcpp/subscription_options.hpp"
29 #include "rclcpp/typesupport_helpers.hpp"
50 typename AllocatorT = std::allocator<void>>
52 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface,
53 const std::string & topic_name,
54 const std::string & topic_type,
56 CallbackT && callback,
63 topic_type,
"rosidl_typesupport_cpp");
65 auto allocator = options.get_allocator();
69 any_subscription_callback(*allocator);
70 any_subscription_callback.
set(std::forward<CallbackT>(callback));
72 auto subscription = std::make_shared<GenericSubscription>(
73 topics_interface->get_node_base_interface(),
78 any_subscription_callback,
81 topics_interface->add_subscription(subscription, options.callback_group);
AnySubscriptionCallback< MessageT, AllocatorT > set(CallbackT callback)
Generic function for setting the callback.
Encapsulation of Quality of Service settings.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC std::shared_ptr< rcpputils::SharedLibrary > get_typesupport_library(const std::string &type, const std::string &typesupport_identifier)
Load the type support library for the given type.
std::shared_ptr< GenericSubscription > create_generic_subscription(rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface, const std::string &topic_name, const std::string &topic_type, const rclcpp::QoS &qos, CallbackT &&callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()))
Create and return a GenericSubscription.
Structure containing optional configuration for Subscriptions.