Fawkes API Fawkes Development Version

fawkes::Clock Class Reference

This is supposed to be the central clock in Fawkes. More...

#include <utils/time/clock.h>

List of all members.

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 Clockinstance ()
 Clock initializer.
static void finalize ()
 Finalize.

Detailed Description

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.

Author:
Daniel Beck, Tim Niemueller

Definition at line 34 of file clock.h.


Member Enumeration Documentation

Select the time source.

Enumerator:
DEFAULT 

select the default time source

REALTIME 

select the system time source

EXTERNAL 

select the external time source

Definition at line 39 of file clock.h.


Constructor & Destructor Documentation

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


Member Function Documentation

float fawkes::Clock::elapsed ( Time t) const

How much time has elapsed since t? Calculated as "now - t" in seconds.

Parameters:
ttime
Returns:
elapsed seconds

Definition at line 295 of file clock.cpp.

Time fawkes::Clock::ext_to_realtime ( const Time t)

Convert a time given w.r.t.

the external time source into the system time.

Parameters:
tthe time that is converted to the system time
Returns:
the time in 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]

Finalize.

Sets a boolean flag which prevents a log message from being generated in the destructor.

Definition at line 89 of file clock.cpp.

void fawkes::Clock::get_systime ( Time time) const

Returns the time of the selected time source.

Parameters:
timereference to Time instance where the time is stored

Definition at line 262 of file clock.cpp.

void fawkes::Clock::get_systime ( Time time) const

Returns the time of the selected time source.

Parameters:
timepointer to Time instance where the time is stored

Definition at line 272 of file clock.cpp.

void fawkes::Clock::get_systime ( struct timeval *  tv) const
void fawkes::Clock::get_time ( struct timeval *  tv) const

Returns the time of the selected time source.

Parameters:
tvpointer 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::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

Returns the time of the selected time source.

Parameters:
tvpointer to a timeval struct where the time is written to
selallows to select the time source

Definition at line 166 of file clock.cpp.

References DEFAULT, EXTERNAL, fawkes::TimeSource::get_time(), and REALTIME.

void fawkes::Clock::get_time ( Time time) const

Returns the time of the selected time source.

Parameters:
timereference 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.

Parameters:
timereference to a time where the result is stored
selallows 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.

Parameters:
timepointer 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.

Parameters:
timepointer to a Time instance where the time is stored
selallows to select the time source

Definition at line 242 of file clock.cpp.

References get_time().

bool fawkes::Clock::has_ext_timesource ( ) const

Check whether an external time source is registered.

Returns:
true if an external time source is registered

Definition at line 344 of file clock.cpp.

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.

Returns:
a pointer to the Clock object

Definition at line 73 of file clock.cpp.

Referenced by fawkes::Interface::Interface(), fawkes::SimulatorTimeSource::SimulatorTimeSource(), and fawkes::TimeWait::wait().

bool fawkes::Clock::is_ext_default_timesource ( ) const

Checks whether the external time source is the default time soucre.

Returns:
true if external time source is default time source

Definition at line 155 of file clock.cpp.

Time fawkes::Clock::now ( ) const

Get the current time.

Returns:
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.

Parameters:
tsa pointer to the external time source
make_defaultif 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.

Parameters:
tsonly 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)

Set/unset the external time source as the default time source.

Parameters:
ext_is_defaulttrue to make external time source the default, false to disable it as the default.

Definition at line 137 of file clock.cpp.

float fawkes::Clock::sys_elapsed ( Time t) const

How much system time has elapsed since t? Use only for system time criteria like timeouts.

Parameters:
ttime
Returns:
elapsed system seconds

Definition at line 308 of file clock.cpp.

References fawkes::time_diff_sec().


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends