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 Clock * instance ()
 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

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.

Definition at line 53 of file clock.cpp.


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 282 of file clock.cpp.

Referenced by FvAqtVisionThreads::empty_time().

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

Definition at line 77 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 249 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 259 of file clock.cpp.

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 176 of file clock.cpp.

References fawkes::TimeSource::get_time().

Referenced by get_time(), fawkes::Time::Time(), fawkes::TimeWait::mark_start(), fawkes::TimeWait::wait(), fawkes::Watch::start(), fawkes::Watch::stop(), fawkes::Watch::pause(), fawkes::Watch::reset(), fawkes::Watch::watch_time(), and fawkes::Watch::clock_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 153 of file clock.cpp.

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

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 193 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 206 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 216 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 229 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 331 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 65 of file clock.cpp.

Referenced by fawkes::FawkesMainThread::FawkesMainThread(), 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 142 of file clock.cpp.

Time fawkes::Clock::now ( ) const

Get the current time.

Returns:
current time

Definition at line 269 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 92 of file clock.cpp.

Referenced by fawkes::TimeSourceAspectIniFin::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 108 of file clock.cpp.

Referenced by fawkes::TimeSourceAspectIniFin::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 124 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 295 of file clock.cpp.

References fawkes::time_diff_sec().


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