.. _program_listing_file_include_rclcpp_create_generic_subscription.hpp: Program Listing for File create_generic_subscription.hpp ======================================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/rclcpp/create_generic_subscription.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2020, Apex.AI Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_ #define RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_ #include #include #include #include #include "rcl/subscription.h" #include "rclcpp/generic_subscription.hpp" #include "rclcpp/node_interfaces/node_topics_interface.hpp" #include "rclcpp/qos.hpp" #include "rclcpp/serialized_message.hpp" #include "rclcpp/subscription_options.hpp" #include "rclcpp/typesupport_helpers.hpp" namespace rclcpp { template> std::shared_ptr create_generic_subscription( rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface, const std::string & topic_name, const std::string & topic_type, const rclcpp::QoS & qos, std::function)> callback, const rclcpp::SubscriptionOptionsWithAllocator & options = ( rclcpp::SubscriptionOptionsWithAllocator() ) ) { auto ts_lib = rclcpp::get_typesupport_library( topic_type, "rosidl_typesupport_cpp"); auto subscription = std::make_shared( topics_interface->get_node_base_interface(), std::move(ts_lib), topic_name, topic_type, qos, callback, options); topics_interface->add_subscription(subscription, options.callback_group); return subscription; } } // namespace rclcpp #endif // RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_