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;
60 : shared_ptr_callback_(nullptr), shared_ptr_with_info_callback_(nullptr),
61 const_shared_ptr_callback_(nullptr), const_shared_ptr_with_info_callback_(nullptr),
62 unique_ptr_callback_(nullptr), unique_ptr_with_info_callback_(nullptr)
64 message_allocator_ = std::make_shared<MessageAlloc>(*allocator.
get());
79 void set(CallbackT callback)
81 shared_ptr_callback_ = callback;
89 SharedPtrWithInfoCallback
93 void set(CallbackT callback)
95 shared_ptr_with_info_callback_ = callback;
103 ConstSharedPtrCallback
107 void set(CallbackT callback)
109 const_shared_ptr_callback_ = callback;
117 ConstSharedPtrWithInfoCallback
121 void set(CallbackT callback)
123 const_shared_ptr_with_info_callback_ = callback;
135 void set(CallbackT callback)
137 unique_ptr_callback_ = callback;
145 UniquePtrWithInfoCallback
149 void set(CallbackT callback)
151 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);
183 if (shared_ptr_callback_) {
185 shared_ptr_callback_(shared_message);
186 }
else if (shared_ptr_with_info_callback_) {
188 shared_ptr_with_info_callback_(shared_message, message_info);
189 }
else if (const_shared_ptr_callback_) {
191 const_shared_ptr_callback_(const_shared_message);
192 }
else if (const_shared_ptr_with_info_callback_) {
194 const_shared_ptr_with_info_callback_(const_shared_message, message_info);
195 }
else if (unique_ptr_callback_) {
196 unique_ptr_callback_(
std::move(message));
197 }
else if (unique_ptr_with_info_callback_) {
198 unique_ptr_with_info_callback_(
std::move(message), message_info);
206 MessageDeleter message_deleter_;
211 #endif // RCLCPP__ANY_SUBSCRIPTION_CALLBACK_HPP_
AnySubscriptionCallback(std::shared_ptr< Alloc > allocator)
Definition: any_subscription_callback.hpp:59
Definition: allocator_common.hpp:24
void dispatch_intra_process(MessageUniquePtr &message, const rmw_message_info_t &message_info)
Definition: any_subscription_callback.hpp:179
void set_allocator_for_deleter(D *deleter, Alloc *alloc)
Definition: allocator_deleter.hpp:72
Definition: any_subscription_callback.hpp:34
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
Definition: function_traits.hpp:143
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:154