15 #ifndef RCLCPP__SUBSCRIPTION_HPP_ 16 #define RCLCPP__SUBSCRIPTION_HPP_ 32 #include "rcl_interfaces/msg/intra_process_message.hpp" 50 namespace node_interfaces
52 class NodeTopicsInterface;
57 typename CallbackMessageT,
85 const rosidl_message_type_support_t & type_support_handle,
86 const
std::
string & topic_name,
90 typename message_memory_strategy::MessageMemoryStrategy<CallbackMessageT, Alloc>::SharedPtr
91 memory_strategy = message_memory_strategy::MessageMemoryStrategy<CallbackMessageT,
92 Alloc>::create_default())
98 rclcpp::subscription_traits::is_serialized_subscription_argument<CallbackMessageT>::value),
99 any_callback_(callback),
100 message_memory_strategy_(memory_strategy)
102 if (event_callbacks.deadline_callback) {
103 this->add_event_handler(event_callbacks.deadline_callback,
106 if (event_callbacks.liveliness_callback) {
107 this->add_event_handler(event_callbacks.liveliness_callback,
119 Alloc>::SharedPtr message_memory_strategy)
121 message_memory_strategy_ = message_memory_strategy;
130 return message_memory_strategy_->borrow_message();
135 return message_memory_strategy_->borrow_serialized_message();
140 if (matches_any_intra_process_publishers(&message_info.
publisher_gid)) {
146 any_callback_.dispatch(typed_message, message_info);
154 message_memory_strategy_->return_message(typed_message);
159 message_memory_strategy_->return_serialized_message(message);
163 rcl_interfaces::msg::IntraProcessMessage & ipm,
166 if (!use_intra_process_) {
173 if (any_callback_.use_take_shared_method()) {
175 take_intra_process_message(
177 ipm.message_sequence,
178 intra_process_subscription_id_,
188 any_callback_.dispatch_intra_process(msg, message_info);
191 take_intra_process_message(
193 ipm.message_sequence,
194 intra_process_subscription_id_,
204 any_callback_.dispatch_intra_process(
std::move(msg), message_info);
212 if (!use_intra_process_) {
215 return intra_process_subscription_handle_;
220 take_intra_process_message(
221 uint64_t publisher_id,
222 uint64_t message_sequence,
223 uint64_t subscription_id,
226 auto ipm = weak_ipm_.lock();
229 "intra process take called after destruction of intra process manager");
231 ipm->template take_intra_process_message<CallbackMessageT, Alloc>(
232 publisher_id, message_sequence, subscription_id, message);
236 take_intra_process_message(
237 uint64_t publisher_id,
238 uint64_t message_sequence,
239 uint64_t subscription_id,
242 auto ipm = weak_ipm_.lock();
245 "intra process take called after destruction of intra process manager");
247 ipm->template take_intra_process_message<CallbackMessageT, Alloc>(
248 publisher_id, message_sequence, subscription_id, message);
252 matches_any_intra_process_publishers(
const rmw_gid_t * sender_gid)
254 if (!use_intra_process_) {
257 auto ipm = weak_ipm_.lock();
260 "intra process publisher check called " 261 "after destruction of intra process manager");
263 return ipm->matches_any_publishers(sender_gid);
270 message_memory_strategy_;
275 #endif // RCLCPP__SUBSCRIPTION_HPP_ Default allocation strategy for messages received by subscriptions.
Definition: message_memory_strategy.hpp:40
#define RCLCPP_DISABLE_COPY(...)
Definition: macros.hpp:26
std::shared_ptr< rcl_serialized_message_t > create_serialized_message()
Borrow a new serialized message.
Definition: subscription.hpp:133
void return_message(std::shared_ptr< void > &message)
Return the loaned message.
Definition: subscription.hpp:151
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
void handle_message(std::shared_ptr< void > &message, const rmw_message_info_t &message_info)
Check if we need to handle the message, and execute the callback if we do.
Definition: subscription.hpp:138
allocator::Deleter< MessageAlloc, CallbackMessageT > MessageDeleter
Definition: subscription.hpp:66
Subscription implementation, templated on the type of message this subscription receives.
Definition: subscription.hpp:59
void handle_intra_process_message(rcl_interfaces::msg::IntraProcessMessage &ipm, const rmw_message_info_t &message_info)
Definition: subscription.hpp:162
typename MessageAllocTraits::allocator_type MessageAlloc
Definition: subscription.hpp:65
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
Definition: any_subscription_callback.hpp:34
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
std::shared_ptr< void > create_message()
Borrow a new message.
Definition: subscription.hpp:124
RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED
allocator::AllocRebind< CallbackMessageT, Alloc > MessageAllocTraits
Definition: subscription.hpp:64
void return_serialized_message(std::shared_ptr< rcl_serialized_message_t > &message)
Return the message borrowed in create_serialized_message.
Definition: subscription.hpp:157
T static_pointer_cast(T... args)
const std::shared_ptr< rcl_subscription_t > get_intra_process_subscription_handle() const
Implemenation detail.
Definition: subscription.hpp:210
Pure virtual interface class for the NodeTopics part of the Node API.
Definition: node_topics_interface.hpp:38
Definition: subscription_base.hpp:53
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 set_message_memory_strategy(typename message_memory_strategy::MessageMemoryStrategy< CallbackMessageT, Alloc >::SharedPtr message_memory_strategy)
Support dynamically setting the message memory strategy.
Definition: subscription.hpp:117
RCL_SUBSCRIPTION_LIVELINESS_CHANGED
Contains callbacks for non-message events that a Subscription can receive from the middleware...
Definition: qos_event.hpp:49