This is supposed to be the central clock in Fawkes. More...
#include <utils/time/clock.h>
Public Types | |
enum | TimesourceSelector { DEFAULT, REALTIME, EXTERNAL } |
Select the time source. More... | |
Public Member Functions | |
virtual | ~Clock () |
Destructor. | |
void | register_ext_timesource (TimeSource *ts, bool make_default=false) |
Register an external time source. | |
void | set_ext_default_timesource (bool ext_is_default) |
Set/unset the external time source as the default time source. | |
bool | is_ext_default_timesource () const |
Checks whether the external time source is the default time soucre. | |
bool | has_ext_timesource () const |
Check whether an external time source is registered. | |
Time | ext_to_realtime (const Time &t) |
Convert a time given w.r.t. | |
void | remove_ext_timesource (TimeSource *ts=0) |
Remove external time source. | |
void | get_time (struct timeval *tv) const |
Returns the time of the selected time source. | |
void | get_time (struct timeval *tv, TimesourceSelector sel) const |
Returns the time of the selected time source. | |
void | get_time (Time &time) const |
Returns the time of the selected time source. | |
void | get_time (Time &time, TimesourceSelector sel) const |
Returns the time of the selected time source. | |
void | get_time (Time *time) const |
Returns the time of the selected time source. | |
void | get_time (Time *time, TimesourceSelector sel) const |
Returns the time of the selected time source. | |
void | get_systime (struct timeval *tv) const |
Returns the system time. | |
void | get_systime (Time &time) const |
Returns the time of the selected time source. | |
void | get_systime (Time *time) const |
Returns the time of the selected time source. | |
Time | now () const |
Get the current time. | |
float | elapsed (Time *t) const |
How much time has elapsed since t? Calculated as "now - t" in seconds. | |
float | sys_elapsed (Time *t) const |
How much system time has elapsed since t? Use only for system time criteria like timeouts. | |
Static Public Member Functions | |
static Clock * | instance () |
Clock initializer. | |
static void | finalize () |
Finalize. |
This is supposed to be the central clock in Fawkes.
It is implemented as a singleton to ensure that there is only one object. So-called TimeSources can be registered at the Clock their current time can be retrieved through the Clock.
Definition at line 34 of file clock.h.
fawkes::Clock::~Clock | ( | ) | [virtual] |
Destructor.
Generates a log message if Clock::finalize wasn't called beforehand
Definition at line 57 of file clock.cpp.
References fawkes::LibLogger::log_error().
float fawkes::Clock::elapsed | ( | Time * | t | ) | const |
How much time has elapsed since t? Calculated as "now - t" in seconds.
t | time |
Definition at line 295 of file clock.cpp.
Referenced by FvAqtVisionThreads::empty_time().
Convert a time given w.r.t.
the external time source into the system time.
t | the time that is converted to the system time |
Definition at line 321 of file clock.cpp.
References fawkes::TimeSource::conv_to_realtime(), fawkes::Time::get_timeval(), and fawkes::Time::set_time().
void fawkes::Clock::finalize | ( | ) | [static] |
void fawkes::Clock::get_systime | ( | Time & | time | ) | const |
void fawkes::Clock::get_systime | ( | Time * | time | ) | const |
void fawkes::Clock::get_systime | ( | struct timeval * | tv | ) | const |
Returns the system time.
tv | pointer to a timeval struct where the time is written to |
Definition at line 252 of file clock.cpp.
Referenced by FvAqtVisionThreads::FvAqtVisionThreads(), fawkes::TimeWait::mark_start(), FvAqtVisionThreads::remove_thread(), FvAqtVisionThreads::remove_waiting_thread(), FestivalSynthThread::say(), fawkes::SimulatorTimeSource::set_sim_offset(), fawkes::SimulatorTimeSource::set_start(), fawkes::SimulatorTimeSource::SimulatorTimeSource(), fawkes::Time::stamp_systime(), fawkes::TimeWait::wait_systime(), and fawkes::Time::wait_systime().
void fawkes::Clock::get_time | ( | struct timeval * | tv | ) | const |
Returns the time of the selected time source.
tv | pointer to a timeval struct where the time is written to |
Definition at line 189 of file clock.cpp.
References fawkes::TimeSource::get_time().
Referenced by fawkes::Watch::clock_time(), get_time(), fawkes::TimeWait::mark_start(), fawkes::Watch::pause(), fawkes::Watch::reset(), fawkes::Time::stamp(), fawkes::Watch::start(), fawkes::Watch::stop(), fawkes::Time::Time(), fawkes::TimeWait::wait(), and fawkes::Watch::watch_time().
void fawkes::Clock::get_time | ( | struct timeval * | tv, | |
TimesourceSelector | sel | |||
) | const |
void fawkes::Clock::get_time | ( | Time & | time | ) | const |
Returns the time of the selected time source.
time | reference to a time where the result is stored |
Definition at line 206 of file clock.cpp.
References get_time().
void fawkes::Clock::get_time | ( | Time & | time, | |
TimesourceSelector | sel | |||
) | const |
Returns the time of the selected time source.
time | reference to a time where the result is stored | |
sel | allows to select the time source |
Definition at line 219 of file clock.cpp.
References get_time().
void fawkes::Clock::get_time | ( | Time * | time | ) | const |
Returns the time of the selected time source.
time | pointer to a Time instance |
Definition at line 229 of file clock.cpp.
References get_time().
void fawkes::Clock::get_time | ( | Time * | time, | |
TimesourceSelector | sel | |||
) | const |
Returns the time of the selected time source.
time | pointer to a Time instance where the time is stored | |
sel | allows to select the time source |
Definition at line 242 of file clock.cpp.
References get_time().
bool fawkes::Clock::has_ext_timesource | ( | ) | const |
Clock * fawkes::Clock::instance | ( | ) | [static] |
Clock initializer.
This one is static and has to be called to instantiate a Clock object. In further calls it just returns a pointer to the Clock object.
Definition at line 73 of file clock.cpp.
Referenced by fawkes::Interface::Interface(), fawkes::SimulatorTimeSource::SimulatorTimeSource(), fawkes::Time::Time(), and fawkes::TimeWait::wait().
bool fawkes::Clock::is_ext_default_timesource | ( | ) | const |
Time fawkes::Clock::now | ( | ) | const |
Get the current time.
Definition at line 282 of file clock.cpp.
References fawkes::Time::stamp().
void fawkes::Clock::register_ext_timesource | ( | TimeSource * | ts, | |
bool | make_default = false | |||
) |
Register an external time source.
ts | a pointer to the external time source | |
make_default | if true, this time source is made the default timesource which means that for every call of get_time() the time of the external time source is returned |
Definition at line 105 of file clock.cpp.
Referenced by fawkes::AspectIniFin::init().
void fawkes::Clock::remove_ext_timesource | ( | TimeSource * | ts = 0 |
) |
Remove external time source.
If an external timesource is currently set it is removed. The time source will not be deleted but only the reference to it is removed.
ts | only remove time source if it equals ts, if NULL remove no matter what. |
Definition at line 121 of file clock.cpp.
Referenced by fawkes::AspectIniFin::finalize().
void fawkes::Clock::set_ext_default_timesource | ( | bool | ext_is_default | ) |
float fawkes::Clock::sys_elapsed | ( | Time * | t | ) | const |
How much system time has elapsed since t? Use only for system time criteria like timeouts.
t | time |
Definition at line 308 of file clock.cpp.
References fawkes::time_diff_sec().