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
 
static IceUtil::Time GetTime (TimeMode timeMode=TimeMode::VirtualTime)
 Get the current time.
 
static LocalTimeServerPtr GetTimeServer ()
 
static IceUtil::Time GetTimeSince (IceUtil::Time referenceTime, bool forceSystemTime)
 Get the difference between the current time and a reference time.
 
static IceUtil::Time GetTimeSince (IceUtil::Time referenceTime, TimeMode timeMode=TimeMode::VirtualTime)
 Get the difference between the current time and a reference time.
 
static bool HasTimeServer ()
 check if we have been initialized with a Timeserver
 
static void MSSleep (int durationMS)
 lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
 
static int NanoSleep (long usec)
 Nanosleep convenience function.
 
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)
 
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)
 
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).
 
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).
 
static std::string toStringTime (const IceUtil::Time &time)
 Return a time string like "15-30-05" (H-M-S).
 
static int USleep (long usec)
 like timed_wait on boost condition_variables, but with timeserver support
 
static void WaitForNextTick ()
 block until the next tick of the timeserver.
 

Protected Member Functions

 TimeUtil ()
 

Static Protected Attributes

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

Detailed Description

provides utility functions for getting the current time

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

◆ 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

◆ GetTimeServer()

LocalTimeServerPtr GetTimeServer ( )
static

◆ 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.

◆ 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.

◆ HasTimeServer()

bool HasTimeServer ( )
static

check if we have been initialized with a Timeserver

◆ 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

◆ NanoSleep()

int NanoSleep ( long usec)
static

Nanosleep convenience function.

Note
This function does not use virtual time!

◆ SetTimeServer()

void SetTimeServer ( LocalTimeServerPtr ts)
static

◆ Sleep() [1/3]

static void Sleep ( float seconds)
inlinestatic

◆ 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).

◆ Sleep() [3/3]

template<class Rep, class Period>
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).

◆ SleepMS()

static void SleepMS ( float milliseconds)
inlinestatic

◆ SleepUS()

static void SleepUS ( float microseconds)
inlinestatic

◆ toStringDate()

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

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

◆ 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).

◆ toStringTime()

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

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

◆ 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!

◆ 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).

Member Data Documentation

◆ timeServerPtr

LocalTimeServerPtr timeServerPtr = nullptr
staticprotected

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


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