Fawkes API  Fawkes Development Version
clock.h
1 
2 /***************************************************************************
3  * clock.h - A central clock
4  *
5  * Generated: Sun Jun 03 00:16:29 2007
6  * Copyright 2007 Daniel Beck
7  * 2007 Tim Niemueller [www.niemueller.de]
8  *
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version. A runtime exception applies to
15  * this software (see LICENSE.GPL_WRE file mentioned below for details).
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23  */
24 
25 #ifndef _UTILS_TIME_CLOCK_H_
26 #define _UTILS_TIME_CLOCK_H_
27 
28 #include <utils/time/time.h>
29 
30 namespace fawkes {
31 
32 class TimeSource;
33 
34 class Clock
35 {
36 public:
37  /** Select the time source. */
38  typedef enum {
39  DEFAULT, /**< select the default time source */
40  REALTIME, /**< select the system time source */
41  EXTERNAL /**< select the external time source */
43 
44  virtual ~Clock();
45 
46  static Clock *instance();
47  static void finalize();
48 
49  void register_ext_timesource(TimeSource *ts, bool make_default = false);
50  void set_ext_default_timesource(bool ext_is_default);
51  bool is_ext_default_timesource() const;
52  bool has_ext_timesource() const;
53  Time ext_to_realtime(const Time &t);
54  Time native_to_time(const Time &t);
55  void remove_ext_timesource(TimeSource *ts = 0);
56 
57  void get_time(struct timeval *tv) const;
58  void get_time(struct timeval *tv, TimesourceSelector sel) const;
59 
60  void get_time(Time &time) const;
61  void get_time(Time &time, TimesourceSelector sel) const;
62 
63  void get_time(Time *time) const;
64  void get_time(Time *time, TimesourceSelector sel) const;
65 
66  void get_systime(struct timeval *tv) const;
67  void get_systime(Time &time) const;
68  void get_systime(Time *time) const;
69 
70  Time now() const;
71  float elapsed(Time *t) const;
72  float sys_elapsed(Time *t) const;
73 
74 private:
75  Clock();
76 
77  TimeSource *ext_timesource;
78  bool ext_default;
79 
80  static Clock *_instance;
81 };
82 
83 } // end namespace fawkes
84 
85 #endif /* UTILS_TIME_CLOCK_H__ */
fawkes::Clock::set_ext_default_timesource
void set_ext_default_timesource(bool ext_is_default)
Set/unset the external time source as the default time source.
Definition: clock.cpp:118
fawkes::Clock::get_time
void get_time(struct timeval *tv) const
Returns the time of the selected time source.
Definition: clock.cpp:161
fawkes::Clock::native_to_time
Time native_to_time(const Time &t)
Convert some native time to a Fawkes time.
Definition: clock.cpp:302
fawkes::Clock::remove_ext_timesource
void remove_ext_timesource(TimeSource *ts=0)
Remove external time source.
Definition: clock.cpp:103
fawkes::Clock::elapsed
float elapsed(Time *t) const
How much time has elapsed since t? Calculated as "now - t" in seconds.
Definition: clock.cpp:254
fawkes::Clock::EXTERNAL
@ EXTERNAL
select the external time source
Definition: clock.h:41
fawkes::Clock::TimesourceSelector
TimesourceSelector
Select the time source.
Definition: clock.h:38
fawkes::Clock::REALTIME
@ REALTIME
select the system time source
Definition: clock.h:40
fawkes::Clock::finalize
static void finalize()
Finalize.
Definition: clock.cpp:74
fawkes::Clock::~Clock
virtual ~Clock()
Destructor.
Definition: clock.cpp:52
fawkes::Clock::DEFAULT
@ DEFAULT
select the default time source
Definition: clock.h:39
fawkes::Clock::now
Time now() const
Get the current time.
Definition: clock.cpp:242
fawkes
Fawkes library namespace.
fawkes::Clock::register_ext_timesource
void register_ext_timesource(TimeSource *ts, bool make_default=false)
Register an external time source.
Definition: clock.cpp:88
fawkes::Clock::ext_to_realtime
Time ext_to_realtime(const Time &t)
Convert a time given w.r.t.
Definition: clock.cpp:278
fawkes::Clock::get_systime
void get_systime(struct timeval *tv) const
Returns the system time.
Definition: clock.cpp:215
fawkes::Time
A class for handling time.
Definition: time.h:93
fawkes::TimeSource
TimeSource interface.
Definition: timesource.h:37
fawkes::Clock::instance
static Clock * instance()
Clock initializer.
Definition: clock.cpp:63
fawkes::Clock::is_ext_default_timesource
bool is_ext_default_timesource() const
Checks whether the external time source is the default time soucre.
Definition: clock.cpp:136
fawkes::Clock
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35
fawkes::Clock::sys_elapsed
float sys_elapsed(Time *t) const
How much system time has elapsed since t? Use only for system time criteria like timeouts.
Definition: clock.cpp:266
fawkes::Clock::has_ext_timesource
bool has_ext_timesource() const
Check whether an external time source is registered.
Definition: clock.cpp:319