15 #ifndef RCLCPP__EXPERIMENTAL__SUBSCRIPTION_INTRA_PROCESS_HPP_
16 #define RCLCPP__EXPERIMENTAL__SUBSCRIPTION_INTRA_PROCESS_HPP_
18 #include <rmw/types.h>
23 #include <type_traits>
28 #include "rclcpp/any_subscription_callback.hpp"
29 #include "rclcpp/context.hpp"
30 #include "rclcpp/experimental/buffers/intra_process_buffer.hpp"
31 #include "rclcpp/experimental/subscription_intra_process_buffer.hpp"
32 #include "rclcpp/qos.hpp"
33 #include "rclcpp/type_support_decl.hpp"
34 #include "tracetools/tracetools.h"
38 namespace experimental
43 typename SubscribedType,
44 typename SubscribedTypeAlloc = std::allocator<SubscribedType>,
45 typename SubscribedTypeDeleter = std::default_delete<SubscribedType>,
46 typename ROSMessageType = SubscribedType,
47 typename Alloc = std::allocator<void>
53 SubscribedTypeDeleter,
60 SubscribedTypeDeleter,
67 using MessageAllocTraits =
68 typename SubscriptionIntraProcessBufferT::SubscribedTypeAllocatorTraits;
69 using MessageAlloc =
typename SubscriptionIntraProcessBufferT::SubscribedTypeAllocator;
70 using ConstMessageSharedPtr =
typename SubscriptionIntraProcessBufferT::ConstDataSharedPtr;
71 using MessageUniquePtr =
typename SubscriptionIntraProcessBufferT::SubscribedTypeUniquePtr;
72 using BufferUniquePtr =
typename SubscriptionIntraProcessBufferT::BufferUniquePtr;
76 std::shared_ptr<Alloc> allocator,
77 rclcpp::Context::SharedPtr context,
78 const std::string & topic_name,
82 SubscribedTypeDeleter, ROSMessageType>(
83 std::make_shared<SubscribedTypeAlloc>(*allocator),
88 any_callback_(callback)
91 rclcpp_subscription_callback_added,
92 static_cast<const void *
>(
this),
93 static_cast<const void *
>(&any_callback_));
97 #ifndef TRACETOOLS_DISABLED
98 any_callback_.register_callback_for_tracing();
104 std::shared_ptr<void>
107 ConstMessageSharedPtr shared_msg;
108 MessageUniquePtr unique_msg;
110 if (any_callback_.use_take_shared_method()) {
111 shared_msg = this->buffer_->consume_shared();
116 unique_msg = this->buffer_->consume_unique();
122 if (this->buffer_->has_data()) {
125 this->trigger_guard_condition();
128 return std::static_pointer_cast<void>(
129 std::make_shared<std::pair<ConstMessageSharedPtr, MessageUniquePtr>>(
130 std::pair<ConstMessageSharedPtr, MessageUniquePtr>(
131 shared_msg, std::move(unique_msg)))
135 void execute(std::shared_ptr<void> & data)
override
137 execute_impl<SubscribedType>(data);
142 typename std::enable_if<std::is_same<T, rcl_serialized_message_t>::value,
void>::type
143 execute_impl(std::shared_ptr<void> & data)
146 throw std::runtime_error(
"Subscription intra-process can't handle serialized messages");
150 typename std::enable_if<!std::is_same<T, rcl_serialized_message_t>::value,
void>::type
151 execute_impl(std::shared_ptr<void> & data)
157 rmw_message_info_t msg_info;
158 msg_info.publisher_gid = {0, {0}};
159 msg_info.from_intra_process =
true;
161 auto shared_ptr = std::static_pointer_cast<std::pair<ConstMessageSharedPtr, MessageUniquePtr>>(
164 if (any_callback_.use_take_shared_method()) {
165 ConstMessageSharedPtr shared_msg = shared_ptr->first;
166 any_callback_.dispatch_intra_process(shared_msg, msg_info);
168 MessageUniquePtr unique_msg = std::move(shared_ptr->second);
169 any_callback_.dispatch_intra_process(std::move(unique_msg), msg_info);
174 AnySubscriptionCallback<MessageT, Alloc> any_callback_;
Encapsulation of Quality of Service settings.
void execute(std::shared_ptr< void > &data) override
Execute data that is passed in.
std::shared_ptr< void > take_data() override
Take the data so that it can be consumed with execute.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.