15 #ifndef RCLCPP__CREATE_SUBSCRIPTION_HPP_
16 #define RCLCPP__CREATE_SUBSCRIPTION_HPP_
50 typename CallbackMessageT,
51 typename SubscriptionT,
52 typename MessageMemoryStrategyT,
53 typename NodeParametersT,
57 NodeParametersT & node_parameters,
58 NodeTopicsT & node_topics,
61 CallbackT && callback,
65 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
66 MessageMemoryStrategyT::create_default()
74 subscription_topic_stats =
nullptr;
78 *node_topics_interface->get_node_base_interface()))
82 "topic_stats_options.publish_period must be greater than 0, specified value of " +
83 std::to_string(options.topic_stats_options.publish_period.count()) +
88 publisher = rclcpp::detail::create_publisher<statistics_msgs::msg::MetricsMessage>(
90 node_topics_interface,
91 options.topic_stats_options.publish_topic,
96 >(node_topics_interface->get_node_base_interface()->get_name(), publisher);
100 > weak_subscription_topic_stats(subscription_topic_stats);
101 auto sub_call_back = [weak_subscription_topic_stats]() {
102 auto subscription_topic_stats = weak_subscription_topic_stats.lock();
103 if (subscription_topic_stats) {
104 subscription_topic_stats->publish_message_and_reset_measurements();
108 auto node_timer_interface = node_topics_interface->get_node_timers_interface();
111 std::chrono::duration_cast<std::chrono::nanoseconds>(
112 options.topic_stats_options.publish_period),
114 options.callback_group,
115 node_topics_interface->get_node_base_interface(),
119 subscription_topic_stats->set_publisher_timer(timer);
122 auto factory = rclcpp::create_subscription_factory<MessageT>(
123 std::forward<CallbackT>(callback),
126 subscription_topic_stats
129 const rclcpp::QoS & actual_qos = options.qos_overriding_options.get_policy_kinds().size() ?
131 options.qos_overriding_options, node_parameters,
132 node_topics_interface->resolve_topic_name(topic_name),
136 auto sub = node_topics_interface->create_subscription(topic_name, factory, actual_qos);
137 node_topics_interface->add_subscription(sub, options.callback_group);
139 return std::dynamic_pointer_cast<SubscriptionT>(sub);
174 typename CallbackMessageT =
187 CallbackT && callback,
191 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
192 MessageMemoryStrategyT::create_default()
197 MessageT, CallbackT, AllocatorT, CallbackMessageT, SubscriptionT, MessageMemoryStrategyT>(
198 node, node, topic_name, qos, std::forward<CallbackT>(callback), options, msg_mem_strat);
209 typename CallbackMessageT =
218 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr & node_parameters,
219 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr & node_topics,
222 CallbackT && callback,
226 typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
227 MessageMemoryStrategyT::create_default()
232 MessageT, CallbackT, AllocatorT, CallbackMessageT, SubscriptionT, MessageMemoryStrategyT>(
233 node_parameters, node_topics, topic_name, qos,
234 std::forward<CallbackT>(callback), options, msg_mem_strat);
239 #endif // RCLCPP__CREATE_SUBSCRIPTION_HPP_