From e7493d38fa85e2979972bbc44a0a6021c290343e Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 24 Dec 2024 05:46:41 -0500 Subject: [PATCH] Switch to using get_system_time_in_ns() function everywhere. (#354) That way we have just a single place where this is defined, and everywhere can be sure they are getting the correct value in nanoseconds. Signed-off-by: Chris Lalancette --- rmw_zenoh_cpp/src/detail/rmw_client_data.cpp | 5 +---- rmw_zenoh_cpp/src/detail/rmw_service_data.cpp | 5 +---- rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp | 5 ++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp index 736e1dbe..6446c710 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -422,10 +421,8 @@ rmw_ret_t ClientData::send_request( return; } - std::chrono::time_point now = std::chrono::system_clock::now(); - sub_data->add_new_reply( - std::make_unique(reply, now.time_since_epoch().count())); + std::make_unique(reply, get_system_time_in_ns())); }, zenoh::closures::none, std::move(opts), diff --git a/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp index 0a76d5ce..289aeb7d 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp @@ -165,10 +165,7 @@ std::shared_ptr ServiceData::make( return; } - std::chrono::nanoseconds::rep received_timestamp = - std::chrono::system_clock::now().time_since_epoch().count(); - - sub_data->add_new_query(std::make_unique(query, received_timestamp)); + sub_data->add_new_query(std::make_unique(query, get_system_time_in_ns())); }, zenoh::closures::none, std::move(qable_options), diff --git a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp index b98f0308..279d3aa6 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp @@ -16,7 +16,6 @@ #include -#include #include #include #include @@ -225,7 +224,7 @@ bool SubscriptionData::init() sub_data->add_new_message( std::make_unique( sample.get_payload(), - std::chrono::system_clock::now().time_since_epoch().count(), + get_system_time_in_ns(), std::move(attachment_data)), std::string(sample.get_keyexpr().as_string_view())); }, @@ -308,7 +307,7 @@ bool SubscriptionData::init() sub_data->add_new_message( std::make_unique( sample.get_payload(), - std::chrono::system_clock::now().time_since_epoch().count(), + get_system_time_in_ns(), std::move(attachment_data)), std::string(sample.get_keyexpr().as_string_view())); },