25 #include <utils/time/clock.h> 26 #include <utils/time/timesource.h> 27 #include <core/exception.h> 42 Clock* Clock::_instance = NULL;
55 delete ext_timesource;
67 if (NULL == _instance) {
68 _instance =
new Clock();
110 if ( (ts == NULL) || (ext_timesource == ts) ) {
111 ext_timesource = NULL;
114 throw Exception(
"Time sources do not match. Not removing.");
126 if ( ext_is_default ) {
127 if (NULL != ext_timesource) {
130 throw Exception(
"Trying to make the external timesource the default timesource but there is no external timesource");
155 if ( (
DEFAULT == sel && !ext_default) ||
161 (NULL == ext_timesource) )
163 throw Exception(
"No external time source registered");
179 if ( NULL == ext_timesource ) {
180 throw Exception(
"No external time source registered");
184 gettimeofday(tv, NULL);
251 gettimeofday(&(time.__time), 0);
261 gettimeofday(&(time->__time), 0);
284 Time nowt(_instance);
298 gettimeofday(&nowt, NULL);
313 if (NULL != ext_timesource) {
338 if (NULL != ext_timesource) {
352 if (0 != ext_timesource) {
TimesourceSelector
Select the time source.
const timeval * get_timeval() const
Obtain the timeval where the time is stored.
static Clock * instance()
Clock initializer.
void get_time(struct timeval *tv) const
Returns the time of the selected time source.
Fawkes library namespace.
void get_systime(struct timeval *tv) const
Returns the system time.
This is supposed to be the central clock in Fawkes.
bool is_ext_default_timesource() const
Checks whether the external time source is the default time soucre.
Time native_to_time(const Time &t)
Convert some native time to a Fawkes time.
float elapsed(Time *t) const
How much time has elapsed since t? Calculated as "now - t" in seconds.
A class for handling time.
bool has_ext_timesource() const
Check whether an external time source is registered.
virtual ~Clock()
Destructor.
void set_ext_default_timesource(bool ext_is_default)
Set/unset the external time source as the default time source.
Time now() const
Get the current time.
select the external time source
Base class for exceptions in Fawkes.
Time ext_to_realtime(const Time &t)
Convert a time given w.r.t.
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
virtual timeval conv_to_realtime(const timeval *tv) const =0
Convert a time given w.r.t.
select the system time source
void register_ext_timesource(TimeSource *ts, bool make_default=false)
Register an external time source.
static void finalize()
Finalize.
float sys_elapsed(Time *t) const
How much system time has elapsed since t? Use only for system time criteria like timeouts.
virtual void get_time(timeval *tv) const =0
Get the current time.
void set_time(const timeval *tv)
Sets the time.
virtual timeval conv_native_to_exttime(const timeval *tv) const =0
Convert a native time to the external time.
Time & stamp()
Set this time to the current time.
void remove_ext_timesource(TimeSource *ts=0)
Remove external time source.
select the default time source