From d44680751c73454f7e8662101f6f244ca2e1c2b8 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 8 Jun 2012 12:17:25 +0200 Subject: [PATCH] [Positioner] Timestamp: *current_time() use "replay" Timestamp::get_current_time() now returns the current time if the replay mode is unactivated, or the most recent request's time in replay mode. --- owlps-positioner/src/timestamp.cc | 15 ++++++++++----- owlps-positioner/src/timestamp.hh | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/owlps-positioner/src/timestamp.cc b/owlps-positioner/src/timestamp.cc index 70dcee6..587eef5 100644 --- a/owlps-positioner/src/timestamp.cc +++ b/owlps-positioner/src/timestamp.cc @@ -6,6 +6,7 @@ #include "timestamp.hh" +#include "configuration.hh" #include @@ -92,6 +93,8 @@ inline void Timestamp::set(const uint64_t source_ms) Timestamp Timestamp::get_current_time() { + if (! Configuration::is_configured("replay")) + current_time.now() ; return current_time ; } @@ -100,12 +103,14 @@ Timestamp Timestamp::get_current_time() * @source A pointer to the new time. If NULL, #current_time is updated * to the current time. */ -void Timestamp::set_current_time(const Timestamp *const source) +void Timestamp::update_current_time(const Timestamp &source) { - if (source) - current_time = *source ; - else - current_time.now() ; + // We should never call this function if we are in replay mode: + assert(Configuration::is_configured("replay")) ; + + // According to human perception, time generally goes only forward: + if (current_time < source) + current_time = source ; } diff --git a/owlps-positioner/src/timestamp.hh b/owlps-positioner/src/timestamp.hh index 2b36244..a15167b 100644 --- a/owlps-positioner/src/timestamp.hh +++ b/owlps-positioner/src/timestamp.hh @@ -69,7 +69,7 @@ public: /// Returns a Timestamp containing the current time static Timestamp get_current_time(void) ; /// Sets #current_time to a new timestamp - static void set_current_time(const Timestamp *const source = NULL) ; + static void update_current_time(const Timestamp &source) ; /// \brief Initialises #timestamp at the current time whith a /// nanosecond precision bool now(void) ;