ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
subscription_callback_type_helper.hpp
1 // Copyright 2021 Open Source Robotics Foundation, 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__DETAIL__SUBSCRIPTION_CALLBACK_TYPE_HELPER_HPP_
16 #define RCLCPP__DETAIL__SUBSCRIPTION_CALLBACK_TYPE_HELPER_HPP_
17 
18 #include <memory>
19 #include <type_traits>
20 
21 #include "rclcpp/function_traits.hpp"
22 #include "rclcpp/message_info.hpp"
23 
24 namespace rclcpp
25 {
26 namespace detail
27 {
28 
30 
64 template<typename MessageT, typename CallbackT, typename Enable = void>
66 {
67  using callback_type = typename rclcpp::function_traits::as_std_function<CallbackT>::type;
68 };
69 
70 template<typename MessageT, typename CallbackT>
72  MessageT,
73  CallbackT,
74  typename std::enable_if_t<
75  rclcpp::function_traits::same_arguments<
76  CallbackT,
77  std::function<void(std::shared_ptr<const MessageT>)>
78  >::value
79  >
80 >
81 {
82  using callback_type = std::function<void (std::shared_ptr<const MessageT>)>;
83 };
84 
85 template<typename MessageT, typename CallbackT>
87  MessageT,
88  CallbackT,
89  typename std::enable_if_t<
90  rclcpp::function_traits::same_arguments<
91  CallbackT,
92  std::function<void(std::shared_ptr<const MessageT>, const rclcpp::MessageInfo &)>
93  >::value
94  >
95 >
96 {
97  using callback_type =
98  std::function<void (std::shared_ptr<const MessageT>, const rclcpp::MessageInfo &)>;
99 };
100 
101 template<typename MessageT, typename CallbackT>
103  MessageT,
104  CallbackT,
105  typename std::enable_if_t<
106  rclcpp::function_traits::same_arguments<
107  CallbackT,
108  std::function<void(const std::shared_ptr<const MessageT> &)>
109  >::value
110  >
111 >
112 {
113  using callback_type = std::function<void (const std::shared_ptr<const MessageT> &)>;
114 };
115 
116 template<typename MessageT, typename CallbackT>
118  MessageT,
119  CallbackT,
120  typename std::enable_if_t<
121  rclcpp::function_traits::same_arguments<
122  CallbackT,
123  std::function<void(const std::shared_ptr<const MessageT> &, const rclcpp::MessageInfo &)>
124  >::value
125  >
126 >
127 {
128  using callback_type =
129  std::function<void (const std::shared_ptr<const MessageT> &, const rclcpp::MessageInfo &)>;
130 };
131 
132 template<typename MessageT, typename CallbackT>
134  MessageT,
135  CallbackT,
136  typename std::enable_if_t<
137  rclcpp::function_traits::same_arguments<
138  CallbackT,
139  std::function<void(std::shared_ptr<MessageT>)>
140  >::value
141  >
142 >
143 {
144  using callback_type = std::function<void (std::shared_ptr<MessageT>)>;
145 };
146 
147 template<typename MessageT, typename CallbackT>
149  MessageT,
150  CallbackT,
151  typename std::enable_if_t<
152  rclcpp::function_traits::same_arguments<
153  CallbackT,
154  std::function<void(std::shared_ptr<MessageT>, const rclcpp::MessageInfo &)>
155  >::value
156  >
157 >
158 {
159  using callback_type =
160  std::function<void (std::shared_ptr<MessageT>, const rclcpp::MessageInfo &)>;
161 };
162 
163 } // namespace detail
164 } // namespace rclcpp
165 
166 #endif // RCLCPP__DETAIL__SUBSCRIPTION_CALLBACK_TYPE_HELPER_HPP_
Additional meta data about messages taken from subscriptions.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Template metaprogramming helper used to resolve the callback argument into a std::function.