15 #ifndef RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ 16 #define RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ 23 #include <type_traits> 29 #include "tracetools/tracetools.h" 30 #include "tracetools/utils.hpp" 35 template<
typename MessageT,
typename Alloc>
39 using MessageAlloc =
typename MessageAllocTraits::allocator_type;
63 : shared_ptr_callback_(nullptr), shared_ptr_with_info_callback_(nullptr),
64 const_shared_ptr_callback_(nullptr), const_shared_ptr_with_info_callback_(nullptr),
65 unique_ptr_callback_(nullptr), unique_ptr_with_info_callback_(nullptr)
67 message_allocator_ = std::make_shared<MessageAlloc>(*allocator.
get());
82 void set(CallbackT callback)
84 shared_ptr_callback_ = callback;
96 void set(CallbackT callback)
98 shared_ptr_with_info_callback_ = callback;
110 void set(CallbackT callback)
112 const_shared_ptr_callback_ = callback;
124 void set(CallbackT callback)
126 const_shared_ptr_with_info_callback_ = callback;
138 void set(CallbackT callback)
140 unique_ptr_callback_ = callback;
152 void set(CallbackT callback)
154 unique_ptr_with_info_callback_ = callback;
160 TRACEPOINT(callback_start, (
const void *)
this,
false);
161 if (shared_ptr_callback_) {
162 shared_ptr_callback_(message);
163 }
else if (shared_ptr_with_info_callback_) {
164 shared_ptr_with_info_callback_(message, message_info);
165 }
else if (const_shared_ptr_callback_) {
166 const_shared_ptr_callback_(message);
167 }
else if (const_shared_ptr_with_info_callback_) {
168 const_shared_ptr_with_info_callback_(message, message_info);
169 }
else if (unique_ptr_callback_) {
170 auto ptr = MessageAllocTraits::allocate(*message_allocator_.
get(), 1);
171 MessageAllocTraits::construct(*message_allocator_.
get(), ptr, *message);
173 }
else if (unique_ptr_with_info_callback_) {
174 auto ptr = MessageAllocTraits::allocate(*message_allocator_.
get(), 1);
175 MessageAllocTraits::construct(*message_allocator_.
get(), ptr, *message);
176 unique_ptr_with_info_callback_(
MessageUniquePtr(ptr, message_deleter_), message_info);
180 TRACEPOINT(callback_end, (
const void *)
this);
186 TRACEPOINT(callback_start, (
const void *)
this,
true);
187 if (const_shared_ptr_callback_) {
188 const_shared_ptr_callback_(message);
189 }
else if (const_shared_ptr_with_info_callback_) {
190 const_shared_ptr_with_info_callback_(message, message_info);
193 unique_ptr_callback_ || unique_ptr_with_info_callback_ ||
194 shared_ptr_callback_ || shared_ptr_with_info_callback_)
197 "unexpected dispatch_intra_process const shared " 198 "message call with no const shared_ptr callback");
203 TRACEPOINT(callback_end, (
const void *)
this);
209 TRACEPOINT(callback_start, (
const void *)
this,
true);
210 if (shared_ptr_callback_) {
212 shared_ptr_callback_(shared_message);
213 }
else if (shared_ptr_with_info_callback_) {
215 shared_ptr_with_info_callback_(shared_message, message_info);
216 }
else if (unique_ptr_callback_) {
217 unique_ptr_callback_(
std::move(message));
218 }
else if (unique_ptr_with_info_callback_) {
219 unique_ptr_with_info_callback_(
std::move(message), message_info);
220 }
else if (const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_) {
222 "unexpected dispatch_intra_process unique message call" 223 " with const shared_ptr callback");
227 TRACEPOINT(callback_end, (
const void *)
this);
232 return const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_;
237 if (shared_ptr_callback_) {
239 rclcpp_callback_register,
241 get_symbol(shared_ptr_callback_));
242 }
else if (shared_ptr_with_info_callback_) {
244 rclcpp_callback_register,
246 get_symbol(shared_ptr_with_info_callback_));
247 }
else if (unique_ptr_callback_) {
249 rclcpp_callback_register,
251 get_symbol(unique_ptr_callback_));
252 }
else if (unique_ptr_with_info_callback_) {
254 rclcpp_callback_register,
256 get_symbol(unique_ptr_with_info_callback_));
262 MessageDeleter message_deleter_;
267 #endif // RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ bool use_take_shared_method() const
Definition: any_subscription_callback.hpp:230
void dispatch_intra_process(ConstMessageSharedPtr message, const rmw_message_info_t &message_info)
Definition: any_subscription_callback.hpp:183
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
void dispatch_intra_process(MessageUniquePtr message, const rmw_message_info_t &message_info)
Definition: any_subscription_callback.hpp:206
void set_allocator_for_deleter(D *deleter, Alloc *alloc)
Definition: allocator_deleter.hpp:72
AnySubscriptionCallback(std::shared_ptr< Alloc > allocator)
Definition: any_subscription_callback.hpp:62
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
Definition: any_subscription_callback.hpp:36
Definition: function_traits.hpp:161
void register_callback_for_tracing()
Definition: any_subscription_callback.hpp:235
typename std::conditional< std::is_same< typename std::allocator_traits< Alloc >::template rebind_alloc< T >, typename std::allocator< void >::template rebind< T >::other >::value, std::default_delete< T >, AllocatorDeleter< Alloc > >::type Deleter
Definition: allocator_deleter.hpp:101
void dispatch(std::shared_ptr< MessageT > message, const rmw_message_info_t &message_info)
Definition: any_subscription_callback.hpp:157