TimeUtil Class Reference

provides utility functions for getting the current time More...

#include <ArmarXCore/core/time/TimeUtil.h>

Static Public Member Functions

static IceUtil::Time GetTime (bool forceSystemTime)
 get the current time More...
 
static IceUtil::Time GetTime (TimeMode timeMode=TimeMode::VirtualTime)
 Get the current time. More...
 
static LocalTimeServerPtr GetTimeServer ()
 
static IceUtil::Time GetTimeSince (IceUtil::Time referenceTime, bool forceSystemTime)
 Get the difference between the current time and a reference time. More...
 
static IceUtil::Time GetTimeSince (IceUtil::Time referenceTime, TimeMode timeMode=TimeMode::VirtualTime)
 Get the difference between the current time and a reference time. More...
 
static bool HasTimeServer ()
 check if we have been initialized with a Timeserver More...
 
static void MSSleep (int durationMS)
 lock the calling thread for a given duration (like usleep(...) but using Timeserver time) More...
 
static int NanoSleep (long usec)
 Nanosleep convenience function. More...
 
static void SetTimeServer (LocalTimeServerPtr ts)
 
static void Sleep (float seconds)
 
static void Sleep (IceUtil::Time duration)
 lock the calling thread for a given duration (like usleep(...) but using Timeserver time) More...
 
template<class Rep , class Period >
static void Sleep (std::chrono::duration< Rep, Period > d)
 lock the calling thread for a given duration (like usleep(...) but using Timeserver time) More...
 
static void SleepMS (float milliseconds)
 
static void SleepUS (float microseconds)
 
static std::string toStringDate (const IceUtil::Time &time)
 Return a date string like "2020-01-31" (Y-M-D). More...
 
static std::string toStringDateTime (const IceUtil::Time &time)
 Return a date & time string like "2020-01-31_15-30-05" (Y-M-D_H-M-S). More...
 
static std::string toStringTime (const IceUtil::Time &time)
 Return a time string like "15-30-05" (H-M-S). More...
 
static int USleep (long usec)
 like timed_wait on boost condition_variables, but with timeserver support More...
 
static void WaitForNextTick ()
 block until the next tick of the timeserver. More...
 

Protected Member Functions

 TimeUtil ()
 

Static Protected Attributes

static LocalTimeServerPtr timeServerPtr = nullptr
 pointer to the applications LocalTimeServer if NULL, system time is used More...
 

Detailed Description

provides utility functions for getting the current time

Definition at line 130 of file TimeUtil.h.

Constructor & Destructor Documentation

◆ TimeUtil()

TimeUtil ( )
protected

Member Function Documentation

◆ GetTime() [1/2]

IceUtil::Time GetTime ( bool  forceSystemTime)
static

get the current time

Parameters
forceSystemTimeIf true, this function will always return the time of the system and never the virtual time.
Returns
the current time

Depending on if a TimeServer is used, the system time or the TimeServer time is returned

Definition at line 54 of file TimeUtil.cpp.

+ Here is the call graph for this function:

◆ GetTime() [2/2]

IceUtil::Time GetTime ( TimeMode  timeMode = TimeMode::VirtualTime)
static

Get the current time.

Parameters
timeModeTime mode to be used.
Returns
The current time considering timeMode

Definition at line 42 of file TimeUtil.cpp.

◆ GetTimeServer()

LocalTimeServerPtr GetTimeServer ( )
static

Definition at line 109 of file TimeUtil.cpp.

+ Here is the caller graph for this function:

◆ GetTimeSince() [1/2]

IceUtil::Time GetTimeSince ( IceUtil::Time  referenceTime,
bool  forceSystemTime 
)
static

Get the difference between the current time and a reference time.

Parameters
referenceTimeReference point in time.
forceSystemTimeIf true, this function will always return the time of the system and never the virtual time.
Returns
Current timestamp minus the given reference time to get the delta.

Definition at line 71 of file TimeUtil.cpp.

+ Here is the call graph for this function:

◆ GetTimeSince() [2/2]

IceUtil::Time GetTimeSince ( IceUtil::Time  referenceTime,
TimeMode  timeMode = TimeMode::VirtualTime 
)
static

Get the difference between the current time and a reference time.

Parameters
referenceTimeReference point in time.
timeModeTime mode to be used.
Returns
Current timestamp minus the given reference time to get the delta.

Definition at line 66 of file TimeUtil.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasTimeServer()

bool HasTimeServer ( )
static

check if we have been initialized with a Timeserver

Definition at line 114 of file TimeUtil.cpp.

+ Here is the caller graph for this function:

◆ MSSleep()

void MSSleep ( int  durationMS)
static

lock the calling thread for a given duration (like usleep(...) but using Timeserver time)

Parameters
durationMShow long to sleep in milliseconds

Definition at line 94 of file TimeUtil.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NanoSleep()

int NanoSleep ( long  usec)
static

Nanosleep convenience function.

Note
This function does not use virtual time!

Definition at line 153 of file TimeUtil.cpp.

+ Here is the caller graph for this function:

◆ SetTimeServer()

void SetTimeServer ( LocalTimeServerPtr  ts)
static

Definition at line 99 of file TimeUtil.cpp.

◆ Sleep() [1/3]

static void Sleep ( float  seconds)
inlinestatic

Definition at line 191 of file TimeUtil.h.

+ Here is the call graph for this function:

◆ Sleep() [2/3]

void Sleep ( IceUtil::Time  duration)
static

lock the calling thread for a given duration (like usleep(...) but using Timeserver time)

Parameters
durationhow long to sleep

Sleep for the given duration using timeserver time. Granularity is limited to 1 ms when a Timeserver is running (else 1 us).

Definition at line 76 of file TimeUtil.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Sleep() [3/3]

static void Sleep ( std::chrono::duration< Rep, Period >  d)
inlinestatic

lock the calling thread for a given duration (like usleep(...) but using Timeserver time)

Parameters
durationhow long to sleep

Sleep for the given duration using timeserver time. Granularity is limited to 1 ms when a Timeserver is running (else 1 us).

Definition at line 186 of file TimeUtil.h.

+ Here is the call graph for this function:

◆ SleepMS()

static void SleepMS ( float  milliseconds)
inlinestatic

Definition at line 195 of file TimeUtil.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SleepUS()

static void SleepUS ( float  microseconds)
inlinestatic

Definition at line 199 of file TimeUtil.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toStringDate()

std::string toStringDate ( const IceUtil::Time &  time)
static

Return a date string like "2020-01-31" (Y-M-D).

Definition at line 162 of file TimeUtil.cpp.

◆ toStringDateTime()

std::string toStringDateTime ( const IceUtil::Time &  time)
static

Return a date & time string like "2020-01-31_15-30-05" (Y-M-D_H-M-S).

Definition at line 172 of file TimeUtil.cpp.

◆ toStringTime()

std::string toStringTime ( const IceUtil::Time &  time)
static

Return a time string like "15-30-05" (H-M-S).

Definition at line 167 of file TimeUtil.cpp.

◆ USleep()

int USleep ( long  usec)
static

like timed_wait on boost condition_variables, but with timeserver support

The implementation only checks for timeout periodically (see granularity parameter), so precision is limited

Parameters
condthe boost::condition_variable to wait on (as shared_ptr)
lockan already locked unique_lock
durationtimeout
granularityhow often timeout is checked, default is to use a tenth of duration
Returns
false, if the thread was unlocked due to a timeout, else true Usleep convenience function that uses internally nanosleep.
Note
This function does not use virtual time!

Definition at line 148 of file TimeUtil.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WaitForNextTick()

void WaitForNextTick ( )
static

block until the next tick of the timeserver.

Noop if no timeserver in use.

Can be used to pause execution if the timeserver is paused. If the timeserver is runing, this may block for up to one tick interval (typically 1ms).

Definition at line 104 of file TimeUtil.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ timeServerPtr

LocalTimeServerPtr timeServerPtr = nullptr
staticprotected

pointer to the applications LocalTimeServer if NULL, system time is used

Definition at line 267 of file TimeUtil.h.


The documentation for this class was generated from the following files: