diff --git a/rmw_zenoh_cpp/src/detail/graph_cache.cpp b/rmw_zenoh_cpp/src/detail/graph_cache.cpp index 3143950b..24cbc23e 100644 --- a/rmw_zenoh_cpp/src/detail/graph_cache.cpp +++ b/rmw_zenoh_cpp/src/detail/graph_cache.cpp @@ -1316,8 +1316,8 @@ void GraphCache::set_querying_subscriber_callback( std::unordered_map >::iterator cb_it = querying_subs_cbs_.find(sub_keyexpr); if (cb_it == querying_subs_cbs_.end()) { - querying_subs_cbs_[sub_keyexpr] = std::move( - std::unordered_map{}); + querying_subs_cbs_[sub_keyexpr] = + std::unordered_map{}; cb_it = querying_subs_cbs_.find(sub_keyexpr); } cb_it->second.insert(std::make_pair(sub_keyxpr_hash, std::move(cb))); diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp index c0442df6..206c84b8 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp @@ -12,13 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include #include #include -#include "liveliness_utils.hpp" #include "logging_macros.hpp" #include "rmw_data_types.hpp" @@ -167,7 +165,9 @@ void client_data_handler(z_loaned_reply_t * reply, void * data) if (z_reply_is_ok(reply)) { z_owned_reply_t owned_reply; z_reply_clone(&owned_reply, reply); - client_data->add_new_reply(std::make_unique(owned_reply)); + std::chrono::nanoseconds::rep received_timestamp = + std::chrono::system_clock::now().time_since_epoch().count(); + client_data->add_new_reply(std::make_unique(owned_reply, received_timestamp)); } else { z_view_string_t keystr; z_keyexpr_as_view_string(z_loan(client_data->keyexpr), &keystr); diff --git a/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp index ee0af35f..5cb53d58 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_service_data.cpp @@ -317,7 +317,6 @@ rmw_ret_t ServiceData::take_request( memcpy(request_header->request_id.writer_guid, attachment.source_gid, RMW_GID_STORAGE_SIZE); - request_header->source_timestamp = attachment.source_timestamp; if (request_header->source_timestamp < 0) { RMW_SET_ERROR_MSG("Failed to get source_timestamp from client call attachment"); diff --git a/rmw_zenoh_cpp/src/detail/zenoh_utils.cpp b/rmw_zenoh_cpp/src/detail/zenoh_utils.cpp index 27d4e319..f8f61a2e 100644 --- a/rmw_zenoh_cpp/src/detail/zenoh_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/zenoh_utils.cpp @@ -43,7 +43,13 @@ ZenohQuery::~ZenohQuery() {z_drop(z_move(query_));} const z_loaned_query_t * ZenohQuery::get_query() const {return z_loan(query_);} ///============================================================================= -ZenohReply::ZenohReply(z_owned_reply_t reply) {reply_ = reply;} +ZenohReply::ZenohReply( + z_owned_reply_t reply, + std::chrono::nanoseconds::rep received_timestamp) +{ + reply_ = reply; + received_timestamp_ = received_timestamp; +} ///============================================================================= ZenohReply::~ZenohReply() {z_drop(z_move(reply_));} @@ -57,4 +63,10 @@ std::optional ZenohReply::get_sample() const return std::nullopt; } + +///============================================================================= +std::chrono::nanoseconds::rep ZenohReply::get_received_timestamp() const +{ + return received_timestamp_; +} } // namespace rmw_zenoh_cpp diff --git a/rmw_zenoh_cpp/src/detail/zenoh_utils.hpp b/rmw_zenoh_cpp/src/detail/zenoh_utils.hpp index 6d45401c..97e1446f 100644 --- a/rmw_zenoh_cpp/src/detail/zenoh_utils.hpp +++ b/rmw_zenoh_cpp/src/detail/zenoh_utils.hpp @@ -17,6 +17,7 @@ #include +#include #include #include "rmw/types.h" @@ -34,14 +35,17 @@ create_map_and_set_sequence_num( class ZenohReply final { public: - ZenohReply(z_owned_reply_t reply); + ZenohReply(z_owned_reply_t reply, std::chrono::nanoseconds::rep received_timestamp); ~ZenohReply(); std::optional get_sample() const; + std::chrono::nanoseconds::rep get_received_timestamp() const; + private: z_owned_reply_t reply_; + std::chrono::nanoseconds::rep received_timestamp_; }; // A class to store the queries made by clients. diff --git a/rmw_zenoh_cpp/src/rmw_init.cpp b/rmw_zenoh_cpp/src/rmw_init.cpp index 64dc6dae..f1d89f61 100644 --- a/rmw_zenoh_cpp/src/rmw_init.cpp +++ b/rmw_zenoh_cpp/src/rmw_init.cpp @@ -31,7 +31,7 @@ extern "C" { //============================================================================== -/// Initialize the middleware with the given options, and yielding an context. +/// Initialize the middleware with the given options, and yield a context. rmw_ret_t rmw_init(const rmw_init_options_t * options, rmw_context_t * context) { diff --git a/rmw_zenoh_cpp/src/rmw_init_options.cpp b/rmw_zenoh_cpp/src/rmw_init_options.cpp index 2b79566a..783c5a6a 100644 --- a/rmw_zenoh_cpp/src/rmw_init_options.cpp +++ b/rmw_zenoh_cpp/src/rmw_init_options.cpp @@ -98,7 +98,7 @@ rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst) return ret; } auto free_discovery_options = rcpputils::make_scope_exit( - [&tmp, allocator]() { + [&tmp]() { rmw_ret_t tmp_ret = rmw_discovery_options_fini(&tmp.discovery_options); static_cast(tmp_ret); }); diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 25b2e02c..920b12dd 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1419,7 +1419,12 @@ rmw_create_client( allocator->deallocate(client_data, allocator->state); }); - RMW_TRY_PLACEMENT_NEW(client_data, client_data, return nullptr, rmw_zenoh_cpp::rmw_client_data_t); + RMW_TRY_PLACEMENT_NEW( + client_data, + client_data, + return nullptr, + rmw_zenoh_cpp::rmw_client_data_t, + ); auto destruct_client_data = rcpputils::make_scope_exit( [client_data]() { RMW_TRY_DESTRUCTOR_FROM_WITHIN_FAILURE( @@ -1869,9 +1874,7 @@ rmw_take_response( return RMW_RET_ERROR; } - auto now = std::chrono::system_clock::now().time_since_epoch(); - auto now_ns = std::chrono::duration_cast(now); - request_header->received_timestamp = now_ns.count(); + request_header->received_timestamp = latest_reply->get_received_timestamp(); z_drop(z_move(payload)); *taken = true;