From 12277406c321c3c93c05906d02a0ecbb73ff288d 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 (cherry picked from commit e7493d38fa85e2979972bbc44a0a6021c290343e) # Conflicts: # rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp --- 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 | 11 ++++++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_client_data.cpp index f85dab86..a0463945 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 @@ -413,10 +412,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 769ff47e..4a373254 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp @@ -161,10 +161,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 cce67b33..edbd9f05 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,8 +224,13 @@ bool SubscriptionData::init() sub_data->add_new_message( std::make_unique( +<<<<<<< HEAD sample.get_payload().as_vector(), std::chrono::system_clock::now().time_since_epoch().count(), +======= + sample.get_payload(), + get_system_time_in_ns(), +>>>>>>> e7493d3 (Switch to using get_system_time_in_ns() function everywhere. (#354)) std::move(attachment_data)), std::string(sample.get_keyexpr().as_string_view())); }, @@ -309,8 +313,13 @@ bool SubscriptionData::init() AttachmentData attachment_data(attachment_value); sub_data->add_new_message( std::make_unique( +<<<<<<< HEAD payload.as_vector(), std::chrono::system_clock::now().time_since_epoch().count(), +======= + sample.get_payload(), + get_system_time_in_ns(), +>>>>>>> e7493d3 (Switch to using get_system_time_in_ns() function everywhere. (#354)) std::move(attachment_data)), std::string(sample.get_keyexpr().as_string_view())); },