15 #ifndef RCLCPP__SUBSCRIPTION_FACTORY_HPP_
16 #define RCLCPP__SUBSCRIPTION_FACTORY_HPP_
25 #include "rosidl_typesupport_cpp/message_type_support.hpp"
27 #include "rclcpp/any_subscription_callback.hpp"
28 #include "rclcpp/get_message_type_support_handle.hpp"
29 #include "rclcpp/node_interfaces/node_base_interface.hpp"
30 #include "rclcpp/qos.hpp"
31 #include "rclcpp/subscription.hpp"
32 #include "rclcpp/subscription_options.hpp"
33 #include "rclcpp/subscription_traits.hpp"
34 #include "rclcpp/topic_statistics/subscription_topic_statistics.hpp"
35 #include "rclcpp/visibility_control.hpp"
57 using SubscriptionFactoryFunction = std::function<
58 rclcpp::SubscriptionBase::SharedPtr(
60 const std::string & topic_name,
63 const SubscriptionFactoryFunction create_typed_subscription;
78 typename MessageMemoryStrategyT =
typename SubscriptionT::MessageMemoryStrategyType
82 CallbackT && callback,
84 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat,
85 std::shared_ptr<rclcpp::topic_statistics::SubscriptionTopicStatistics>
86 subscription_topic_stats =
nullptr
89 auto allocator = options.get_allocator();
93 any_subscription_callback.
set(std::forward<CallbackT>(callback));
97 [options, msg_mem_strat, any_subscription_callback, subscription_topic_stats](
99 const std::string & topic_name,
101 ) -> rclcpp::SubscriptionBase::SharedPtr
108 rclcpp::get_message_type_support_handle<MessageT>(),
111 any_subscription_callback,
114 subscription_topic_stats);
118 sub->post_init_setup(node_base, qos, options);
119 auto sub_base_ptr = std::dynamic_pointer_cast<SubscriptionBase>(sub);
AnySubscriptionCallback< MessageT, AllocatorT > set(CallbackT callback)
Generic function for setting the callback.
Encapsulation of Quality of Service settings.
Subscription implementation, templated on the type of message this subscription receives.
Pure virtual interface class for the NodeBase part of the Node API.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
SubscriptionFactory create_subscription_factory(CallbackT &&callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options, typename MessageMemoryStrategyT::SharedPtr msg_mem_strat, std::shared_ptr< rclcpp::topic_statistics::SubscriptionTopicStatistics > subscription_topic_stats=nullptr)
Return a SubscriptionFactory setup to create a SubscriptionT<MessageT, AllocatorT>.
Factory containing a function used to create a Subscription<MessageT>.
Structure containing optional configuration for Subscriptions.