Skip to content

Commit

Permalink
Switch to using get_system_time_in_ns() function everywhere.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
clalancette committed Dec 20, 2024
1 parent 79fc5ce commit ad561b0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
5 changes: 1 addition & 4 deletions rmw_zenoh_cpp/src/detail/rmw_client_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <fastcdr/FastBuffer.h>

#include <array>
#include <chrono>
#include <cinttypes>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -422,10 +421,8 @@ rmw_ret_t ClientData::send_request(
return;
}

std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();

sub_data->add_new_reply(
std::make_unique<rmw_zenoh_cpp::ZenohReply>(reply, now.time_since_epoch().count()));
std::make_unique<rmw_zenoh_cpp::ZenohReply>(reply, get_system_time_in_ns()));
},
zenoh::closures::none,
std::move(opts),
Expand Down
5 changes: 1 addition & 4 deletions rmw_zenoh_cpp/src/detail/rmw_service_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ std::shared_ptr<ServiceData> 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<ZenohQuery>(query, received_timestamp));
sub_data->add_new_query(std::make_unique<ZenohQuery>(query, get_system_time_in_ns()));
},
zenoh::closures::none,
std::move(qable_options),
Expand Down
5 changes: 2 additions & 3 deletions rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <fastcdr/FastBuffer.h>

#include <chrono>
#include <cinttypes>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -226,7 +225,7 @@ bool SubscriptionData::init()
sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
sample.get_payload().as_vector(),
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()));
},
Expand Down Expand Up @@ -310,7 +309,7 @@ bool SubscriptionData::init()
sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
payload.as_vector(),
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()));
},
Expand Down

0 comments on commit ad561b0

Please sign in to comment.