Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion rclcpp/include/rclcpp/generic_subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class GenericSubscription : public rclcpp::SubscriptionBase
node_base,
*rclcpp::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *ts_lib),
topic_name,
options.to_rcl_subscription_options(qos),
force_cpu_buffer_backend(options).to_rcl_subscription_options(qos),
options.event_callbacks,
options.use_default_callbacks,
DeliveredMessageKind::SERIALIZED_MESSAGE),
Expand Down Expand Up @@ -182,6 +182,17 @@ class GenericSubscription : public rclcpp::SubscriptionBase

private:
RCLCPP_DISABLE_COPY(GenericSubscription)

template<typename AllocatorT>
static rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>
force_cpu_buffer_backend(
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options)
{
auto opts = options;
opts.acceptable_buffer_backends = "cpu";
return opts;
}

AnySubscriptionCallback<rclcpp::SerializedMessage, std::allocator<void>> any_callback_;
// The type support library should stay loaded, so it is stored in the GenericSubscription
std::shared_ptr<rcpputils::SharedLibrary> ts_lib_;
Expand Down
19 changes: 19 additions & 0 deletions rclcpp/include/rclcpp/subscription_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ struct SubscriptionOptionsBase
QosOverridingOptions qos_overriding_options;

ContentFilterOptions content_filter_options;

/// Acceptable buffer backend names for this subscription.
/**
* Empty string or "cpu" means CPU-only (default for backward compatibility).
* "any" means all installed backends are acceptable.
* Comma-separated for specific backends, e.g. "cuda,demo".
* CPU is always implicitly acceptable regardless of this value.
*/
std::string acceptable_buffer_backends{"cpu"};
};

/// Structure containing optional configuration for Subscriptions.
Expand Down Expand Up @@ -145,6 +154,16 @@ struct SubscriptionOptionsWithAllocator : public SubscriptionOptionsBase
}
}

if (!acceptable_buffer_backends.empty()) {
rcl_ret_t ret = rcl_subscription_options_set_acceptable_buffer_backends(
acceptable_buffer_backends.c_str(),
&result);
if (RCL_RET_OK != ret) {
rclcpp::exceptions::throw_from_rcl_error(
ret, "failed to set acceptable_buffer_backends");
}
}

return result;
}

Expand Down