[Positioner] Add Timestamp::current_time
This commit is contained in:
parent
ff5bab01cc
commit
0d527ec77d
|
@ -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, ×tamp) == 0 ;
|
||||
|
|
|
@ -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) ;
|
||||
|
|
Loading…
Reference in New Issue