@@ -59,7 +59,8 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
5959 std::size_t subscription_id,
6060 const std::string & topic_name,
6161 const rosidl_message_type_support_t * type_support,
62- const rmw_qos_profile_t * qos_profile)
62+ const rmw_qos_profile_t * qos_profile,
63+ const rmw_subscription_options_t & sub_options)
6364{
6465 rmw_qos_profile_t adapted_qos_profile = *qos_profile;
6566 rmw_ret_t ret = QoS::get ().best_available_qos (
@@ -120,7 +121,8 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
120121 std::move (entity),
121122 std::move (session),
122123 type_support->data ,
123- std::move (message_type_support)
124+ std::move (message_type_support),
125+ sub_options
124126 });
125127
126128 if (!sub_data->init ()) {
@@ -138,13 +140,15 @@ SubscriptionData::SubscriptionData(
138140 std::shared_ptr<liveliness::Entity> entity,
139141 std::shared_ptr<zenoh::Session> session,
140142 const void * type_support_impl,
141- std::unique_ptr<MessageTypeSupport> type_support)
143+ std::unique_ptr<MessageTypeSupport> type_support,
144+ rmw_subscription_options_t sub_options)
142145: rmw_node_(rmw_node),
143146 graph_cache_ (std::move(graph_cache)),
144147 entity_(std::move(entity)),
145148 sess_(std::move(session)),
146149 type_support_impl_(type_support_impl),
147150 type_support_(std::move(type_support)),
151+ sub_options_(std::move(sub_options)),
148152 last_known_published_msg_({}),
149153 wait_set_data_(nullptr ),
150154 is_shutdown_(false ),
@@ -153,6 +157,7 @@ SubscriptionData::SubscriptionData(
153157 events_mgr_ = std::make_shared<EventsManager>();
154158}
155159
160+ // /=============================================================================
156161// We have to use an "init" function here, rather than do this in the constructor, because we use
157162// enable_shared_from_this, which is not available in constructors.
158163bool SubscriptionData::init ()
@@ -171,6 +176,14 @@ bool SubscriptionData::init()
171176 using AdvancedSubscriberOptions = zenoh::ext::SessionExt::AdvancedSubscriberOptions;
172177 auto adv_sub_opts = AdvancedSubscriberOptions::create_default ();
173178
179+ // By default, this subscription will receive publications from publishers within and outside of
180+ // the same Zenoh session as this subscription.
181+ // If ignore_local_publications is true, we restrict this subscription to only receive samples
182+ // from publishers in remote sessions.
183+ if (sub_options_.ignore_local_publications ) {
184+ adv_sub_opts.subscriber_options .allowed_origin = ZC_LOCALITY_REMOTE;
185+ }
186+
174187 // Instantiate the subscription with suitable options depending on the
175188 // adapted_qos_profile.
176189 if (entity_->topic_info ()->qos_ .durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) {
0 commit comments