Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using get_system_time_in_ns() function everywhere. (backport #354) #380

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -413,10 +412,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 @@ -161,10 +161,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 @@ -225,7 +224,7 @@ bool SubscriptionData::init()
sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
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()));
},
Expand Down Expand Up @@ -308,7 +307,7 @@ bool SubscriptionData::init()
sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
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()));
},
Expand Down
7 changes: 7 additions & 0 deletions rmw_zenoh_cpp/src/detail/zenoh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ std::chrono::nanoseconds::rep ZenohReply::get_received_timestamp() const
return received_timestamp_;
}

int64_t get_system_time_in_ns()
{
auto now = std::chrono::system_clock::now().time_since_epoch();
return std::chrono::duration_cast<std::chrono::nanoseconds>(now).count();
}

///=============================================================================
Payload::Payload(const zenoh::Bytes & bytes)
{
// NOTE(fuzzypixelz): `zenoh::Bytes` is an list of reference-couted buffers. When the list of
Expand Down
2 changes: 2 additions & 0 deletions rmw_zenoh_cpp/src/detail/zenoh_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class ZenohQuery final
std::chrono::nanoseconds::rep received_timestamp_;
};

int64_t get_system_time_in_ns();

class Payload
{
public:
Expand Down
Loading