[Positioner] Add Timestamp::current_time

This commit is contained in:
Matteo Cypriani 2012-06-04 18:07:47 +02:00
parent ff5bab01cc
commit 0d527ec77d
2 changed files with 30 additions and 0 deletions

View File

@ -11,6 +11,10 @@
Timestamp Timestamp::current_time ;
/* *** Constructors *** */
@ -86,6 +90,25 @@ inline void Timestamp::set(const uint64_t source_ms)
/* *** Operations *** */
Timestamp Timestamp::get_current_time()
{
return 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)
{
if (source)
current_time = *source ;
else
current_time.now() ;
}
bool Timestamp::now()
{
return clock_gettime(CLOCK_REALTIME, &timestamp) == 0 ;

View File

@ -21,6 +21,9 @@
*/
class Timestamp
{
private:
static Timestamp current_time ;
protected:
/// Time data
struct timespec timestamp ;
@ -63,6 +66,10 @@ public:
/** @name Operations */
//@{
/// 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) ;
/// \brief Initialises #timestamp at the current time whith a
/// nanosecond precision
bool now(void) ;