Skip to content

Commit

Permalink
Initialize pubcache only if durability is transient local
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Jan 11, 2024
1 parent ba2e2a5 commit 4b5f14f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_ROUTER_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
timestamping: {
/// Whether data messages should be timestamped if not already.
/// Accepts a single boolean value or different values for router, peer and client.
enabled: { router: true, peer: false, client: false },
enabled: { router: true, peer: true, client: false },
/// Whether data messages with timestamps in the future should be dropped or not.
/// If set to false (default), messages with timestamps in the future are retimestamped.
/// Timestamps are ignored if timestamping is disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
timestamping: {
/// Whether data messages should be timestamped if not already.
/// Accepts a single boolean value or different values for router, peer and client.
enabled: { router: true, peer: false, client: false },
enabled: { router: true, peer: true, client: false },
/// Whether data messages with timestamps in the future should be dropped or not.
/// If set to false (default), messages with timestamps in the future are retimestamped.
/// Timestamps are ignored if timestamping is disabled.
Expand Down
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ struct rmw_publisher_data_t
// An owned publisher.
z_owned_publisher_t pub;

// Optional publication cache when durability is transient_local.
ze_owned_publication_cache_t pub_cache;

// Liveliness token for the publisher.
zc_owned_liveliness_token_t token;

Expand Down
25 changes: 25 additions & 0 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,29 @@ rmw_create_publisher(
RMW_SET_ERROR_MSG("unable to create zenoh keyexpr.");
return nullptr;
}

// Create a Publication Cache if durability is transient_local.
publisher_data->pub_cache = ze_publication_cache_null();
if (adapted_qos_profile.durability == RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL) {
ze_publication_cache_options_t pub_cache_opts = ze_publication_cache_options_default();
pub_cache_opts.history = adapted_qos_profile.depth;
publisher_data->pub_cache = ze_declare_publication_cache(
z_loan(context_impl->session),
z_loan(keyexpr),
&pub_cache_opts
);
if (!z_check(publisher_data->pub_cache)) {
RMW_SET_ERROR_MSG("unable to create zenoh publisher cache");
return nullptr;
}
}
auto undeclare_z_publisher_cache = rcpputils::make_scope_exit(
[publisher_data]() {
if (publisher_data) {
z_drop(z_move(publisher_data->pub_cache));
}
});

// TODO(clalancette): What happens if the key name is a valid but empty string?
publisher_data->pub = z_declare_publisher(
z_loan(context_impl->session),
Expand Down Expand Up @@ -647,6 +670,7 @@ rmw_create_publisher(
}

free_token.cancel();
undeclare_z_publisher_cache.cancel();
undeclare_z_publisher.cancel();
free_topic_name.cancel();
destruct_msg_type_support.cancel();
Expand Down Expand Up @@ -701,6 +725,7 @@ rmw_destroy_publisher(rmw_node_t * node, rmw_publisher_t * publisher)
// return RMW_RET_ERROR;
// }
z_drop(z_move(publisher_data->token));
z_drop(z_move(publisher_data->pub_cache));

RMW_TRY_DESTRUCTOR(publisher_data->type_support->~MessageTypeSupport(), MessageTypeSupport, );
allocator->deallocate(publisher_data->type_support, allocator->state);
Expand Down

0 comments on commit 4b5f14f

Please sign in to comment.