rclcpp  master
C++ ROS Client Library API
create_generic_subscription.hpp
Go to the documentation of this file.
1 // Copyright 2020, Apex.AI Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
16 #define RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
17 
18 #include <functional>
19 #include <memory>
20 #include <string>
21 #include <utility>
22 
23 #include "rcl/subscription.h"
26 #include "rclcpp/qos.hpp"
30 
31 namespace rclcpp
32 {
33 
35 
48 template<typename AllocatorT = std::allocator<void>>
50  rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr topics_interface,
51  const std::string & topic_name,
52  const std::string & topic_type,
53  const rclcpp::QoS & qos,
57  )
58 )
59 {
60  auto ts_lib = rclcpp::get_typesupport_library(
61  topic_type, "rosidl_typesupport_cpp");
62 
63  auto subscription = std::make_shared<GenericSubscription>(
64  topics_interface->get_node_base_interface(),
65  std::move(ts_lib),
66  topic_name,
67  topic_type,
68  qos,
69  callback,
70  options);
71 
72  topics_interface->add_subscription(subscription, options.callback_group);
73 
74  return subscription;
75 }
76 
77 } // namespace rclcpp
78 
79 #endif // RCLCPP__CREATE_GENERIC_SUBSCRIPTION_HPP_
std::string
std::shared_ptr
std::move
T move(T... args)
typesupport_helpers.hpp
rclcpp::SubscriptionOptionsWithAllocator
Structure containing optional configuration for Subscriptions.
Definition: subscription_options.hpp:87
std::function
subscription.h
serialized_message.hpp
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
qos.hpp
node_topics_interface.hpp
rclcpp::QoS
Encapsulation of Quality of Service settings.
Definition: qos.hpp:110
subscription_options.hpp
rclcpp::get_typesupport_library
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.
generic_subscription.hpp
rclcpp::create_generic_subscription
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, std::function< void(std::shared_ptr< rclcpp::SerializedMessage >)> callback, const rclcpp::SubscriptionOptionsWithAllocator< AllocatorT > &options=(rclcpp::SubscriptionOptionsWithAllocator< AllocatorT >()))
Create and return a GenericSubscription.
Definition: create_generic_subscription.hpp:49