15 #ifndef RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ 16 #define RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_ 23 #include <type_traits> 33 template<
typename MessageT,
typename Alloc>
37 using MessageAlloc =
typename MessageAllocTraits::allocator_type;
61 : shared_ptr_callback_(nullptr), shared_ptr_with_info_callback_(nullptr),
62 const_shared_ptr_callback_(nullptr), const_shared_ptr_with_info_callback_(nullptr),
63 unique_ptr_callback_(nullptr), unique_ptr_with_info_callback_(nullptr)
65 message_allocator_ = std::make_shared<MessageAlloc>(*allocator.
get());
80 void set(CallbackT callback)
82 shared_ptr_callback_ = callback;
94 void set(CallbackT callback)
96 shared_ptr_with_info_callback_ = callback;
108 void set(CallbackT callback)
110 const_shared_ptr_callback_ = callback;
122 void set(CallbackT callback)
124 const_shared_ptr_with_info_callback_ = callback;
136 void set(CallbackT callback)
138 unique_ptr_callback_ = callback;
150 void set(CallbackT callback)
152 unique_ptr_with_info_callback_ = callback;
158 if (shared_ptr_callback_) {
159 shared_ptr_callback_(message);
160 }
else if (shared_ptr_with_info_callback_) {
161 shared_ptr_with_info_callback_(message, message_info);
162 }
else if (const_shared_ptr_callback_) {
163 const_shared_ptr_callback_(message);
164 }
else if (const_shared_ptr_with_info_callback_) {
165 const_shared_ptr_with_info_callback_(message, message_info);
166 }
else if (unique_ptr_callback_) {
167 auto ptr = MessageAllocTraits::allocate(*message_allocator_.
get(), 1);
168 MessageAllocTraits::construct(*message_allocator_.
get(), ptr, *message);
170 }
else if (unique_ptr_with_info_callback_) {
171 auto ptr = MessageAllocTraits::allocate(*message_allocator_.
get(), 1);
172 MessageAllocTraits::construct(*message_allocator_.
get(), ptr, *message);
173 unique_ptr_with_info_callback_(
MessageUniquePtr(ptr, message_deleter_), message_info);
182 if (const_shared_ptr_callback_) {
183 const_shared_ptr_callback_(message);
184 }
else if (const_shared_ptr_with_info_callback_) {
185 const_shared_ptr_with_info_callback_(message, message_info);
187 if (unique_ptr_callback_ || unique_ptr_with_info_callback_ ||
188 shared_ptr_callback_ || shared_ptr_with_info_callback_)
191 "message call with no const shared_ptr callback");
201 if (shared_ptr_callback_) {
203 shared_ptr_callback_(shared_message);
204 }
else if (shared_ptr_with_info_callback_) {
206 shared_ptr_with_info_callback_(shared_message, message_info);
207 }
else if (unique_ptr_callback_) {
208 unique_ptr_callback_(
std::move(message));
209 }
else if (unique_ptr_with_info_callback_) {
210 unique_ptr_with_info_callback_(
std::move(message), message_info);
211 }
else if (const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_) {
213 " with const shared_ptr callback");
221 return const_shared_ptr_callback_ || const_shared_ptr_with_info_callback_;
226 MessageDeleter message_deleter_;
231 #endif // RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_
void dispatch_intra_process(ConstMessageSharedPtr message, const rmw_message_info_t &message_info)
Definition: any_subscription_callback.hpp:179
This header provides the get_node_topics_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:198
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:60
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
Definition: any_subscription_callback.hpp:34
Definition: function_traits.hpp:143
bool use_take_shared_method()
Definition: any_subscription_callback.hpp:219
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:155