15 #ifndef RCLCPP__SUBSCRIPTION_FACTORY_HPP_ 16 #define RCLCPP__SUBSCRIPTION_FACTORY_HPP_ 25 #include "rosidl_typesupport_cpp/message_type_support.hpp" 50 rclcpp::SubscriptionBase::SharedPtr(
60 rclcpp::intra_process_manager::IntraProcessManager::SharedPtr ipm,
61 rclcpp::SubscriptionBase::SharedPtr subscription,
68 template<
typename MessageT,
typename CallbackT,
typename Alloc,
typename SubscriptionT>
71 CallbackT && callback,
80 any_subscription_callback.
set(std::forward<CallbackT>(callback));
83 std::make_shared<typename Subscription<MessageT, Alloc>::MessageAlloc>();
87 [allocator, msg_mem_strat, any_subscription_callback, message_alloc](
91 ) -> rclcpp::SubscriptionBase::SharedPtr
93 subscription_options.allocator =
94 rclcpp::allocator::get_rcl_allocator<MessageT>(*message_alloc.get());
100 node_base->get_shared_rcl_node_handle(),
102 subscription_options,
103 any_subscription_callback,
112 rclcpp::intra_process_manager::IntraProcessManager::SharedPtr ipm,
113 rclcpp::SubscriptionBase::SharedPtr subscription,
116 rclcpp::intra_process_manager::IntraProcessManager::WeakPtr weak_ipm = ipm;
117 uint64_t intra_process_subscription_id = ipm->add_subscription(subscription);
120 intra_process_options.allocator = rclcpp::allocator::get_rcl_allocator<MessageT>(
121 *message_alloc.get());
122 intra_process_options.qos = subscription_options.qos;
123 intra_process_options.ignore_local_publications =
false;
126 auto take_intra_process_message_func =
128 uint64_t publisher_id,
129 uint64_t message_sequence,
130 uint64_t subscription_id,
133 auto ipm = weak_ipm.lock();
137 "intra process take called after destruction of intra process manager");
139 ipm->take_intra_process_message<MessageT, Alloc>(
140 publisher_id, message_sequence, subscription_id, message);
144 auto matches_any_publisher_func =
145 [weak_ipm](
const rmw_gid_t * sender_gid) ->
bool 147 auto ipm = weak_ipm.lock();
150 "intra process publisher check called " 151 "after destruction of intra process manager");
153 return ipm->matches_any_publishers(sender_gid);
157 typed_sub_ptr->setup_intra_process(
158 intra_process_subscription_id,
159 take_intra_process_message_func,
160 matches_any_publisher_func,
161 intra_process_options
172 #endif // RCLCPP__SUBSCRIPTION_FACTORY_HPP_ Subscription implementation, templated on the type of message this subscription receives.
Definition: subscription.hpp:123
SetupIntraProcessFunction setup_intra_process
Definition: subscription_factory.hpp:64
Definition: allocator_common.hpp:24
Definition: any_subscription_callback.hpp:34
SubscriptionFactory create_subscription_factory(CallbackT &&callback, typename rclcpp::message_memory_strategy::MessageMemoryStrategy< MessageT, Alloc >::SharedPtr msg_mem_strat, std::shared_ptr< Alloc > allocator)
Return a SubscriptionFactory with functions for creating a SubscriptionT<MessageT, Alloc>.
Definition: subscription_factory.hpp:70
rcl_subscription_options_t rcl_subscription_get_default_options(void)
Definition: subscription.hpp:50
T dynamic_pointer_cast(T... args)
Default allocation strategy for messages received by subscriptions.
Definition: message_memory_strategy.hpp:33
Pure virtual interface class for the NodeBase part of the Node API.
Definition: node_base_interface.hpp:36
SubscriptionFactoryFunction create_typed_subscription
Definition: subscription_factory.hpp:55
Factory with functions used to create a Subscription<MessageT>.
Definition: subscription_factory.hpp:46
void set(CallbackT callback)
Definition: any_subscription_callback.hpp:79