From 9cc776bd8cc7fddfea8dec0ad703a22d3a6c96d3 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Mon, 13 Jan 2025 16:28:40 +0800 Subject: [PATCH] fix: reorder the advanced pub/sub options to match the ROS2 QoS --- rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp | 6 ++++-- rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp index 44acbd15..573e846a 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp @@ -108,11 +108,13 @@ std::shared_ptr PublisherData::make( } auto adv_pub_opts = zenoh::ext::SessionExt::AdvancedPublisherOptions::create_default(); - adv_pub_opts.publisher_detection = true; - adv_pub_opts.sample_miss_detection = true; // Create a Publication Cache if durability is transient_local. if (adapted_qos_profile.durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) { + // Retransmission can only be done if history is enabled on subscriber side. + adv_pub_opts.publisher_detection = true; + // Allow this publisher to be detected through liveliness. + adv_pub_opts.sample_miss_detection = true; adv_pub_opts.cache = zenoh::ext::SessionExt::AdvancedPublisherOptions::CacheOptions::create_default(); adv_pub_opts.cache->max_samples = adapted_qos_profile.depth; diff --git a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp index 0e23d3da..ae3b4c81 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp @@ -174,14 +174,16 @@ bool SubscriptionData::init() sess_ = context_impl->session(); auto adv_sub_opts = zenoh::ext::SessionExt::AdvancedSubscriberOptions::create_default(); - adv_sub_opts.subscriber_detection = true; // Instantiate the subscription with suitable options depending on the // adapted_qos_profile. // TODO(Yadunund): Rely on a separate function to return the sub // as we start supporting more qos settings. if (entity_->topic_info()->qos_.durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) { + // Allow this subscriber to be detected through liveliness. + adv_sub_opts.subscriber_detection = true; adv_sub_opts.query_timeout_ms = std::numeric_limits::max(); + // History can only be retransmitted by Publishers that enable caching. adv_sub_opts.history = zenoh::ext::SessionExt::AdvancedSubscriberOptions::HistoryOptions::create_default(); adv_sub_opts.history->detect_late_publishers = true;