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 
38  /** Select the time source. */
39  typedef enum {
40  DEFAULT, /**< select the default time source */
41  REALTIME, /**< select the system time source */
42  EXTERNAL /**< select the external time source */
44 
45  virtual ~Clock();
46 
47  static Clock * instance();
48  static void finalize();
49 
50  void register_ext_timesource(TimeSource* ts, bool make_default = false);
51  void set_ext_default_timesource(bool ext_is_default);
52  bool is_ext_default_timesource() const;
53  bool has_ext_timesource() const;
54  Time ext_to_realtime(const Time& t);
55  Time native_to_time(const Time &t);
56  void remove_ext_timesource(TimeSource *ts = 0);
57 
58  void get_time(struct timeval *tv) const;
59  void get_time(struct timeval *tv, TimesourceSelector sel) const;
60 
61  void get_time(Time &time) const;
62  void get_time(Time &time, TimesourceSelector sel) const;
63 
64  void get_time(Time *time) const;
65  void get_time(Time *time, TimesourceSelector sel) const;
66 
67  void get_systime(struct timeval *tv) const;
68  void get_systime(Time &time) const;
69  void get_systime(Time *time) const;
70 
71  Time now() const;
72  float elapsed(Time *t) const;
73  float sys_elapsed(Time *t) const;
74 
75  private:
76  Clock();
77 
78  TimeSource *ext_timesource;
79  bool ext_default;
80 
81  static Clock* _instance;
82 };
83 
84 } // end namespace fawkes
85 
86 #endif /* __UTILS_TIME_CLOCK_H_ */
TimesourceSelector
Select the time source.
Definition: clock.h:39
static Clock * instance()
Clock initializer.
Definition: clock.cpp:65
void get_time(struct timeval *tv) const
Returns the time of the selected time source.
Definition: clock.cpp:176
Fawkes library namespace.
void get_systime(struct timeval *tv) const
Returns the system time.
Definition: clock.cpp:239
This is supposed to be the central clock in Fawkes.
Definition: clock.h:34
bool is_ext_default_timesource() const
Checks whether the external time source is the default time soucre.
Definition: clock.cpp:142
Time native_to_time(const Time &t)
Convert some native time to a Fawkes time.
Definition: clock.cpp:333
float elapsed(Time *t) const
How much time has elapsed since t? Calculated as "now - t" in seconds.
Definition: clock.cpp:282
A class for handling time.
Definition: time.h:91
TimeSource interface.
Definition: timesource.h:36
bool has_ext_timesource() const
Check whether an external time source is registered.
Definition: clock.cpp:350
virtual ~Clock()
Destructor.
Definition: clock.cpp:53
void set_ext_default_timesource(bool ext_is_default)
Set/unset the external time source as the default time source.
Definition: clock.cpp:124
Time now() const
Get the current time.
Definition: clock.cpp:269
select the external time source
Definition: clock.h:42
Time ext_to_realtime(const Time &t)
Convert a time given w.r.t.
Definition: clock.cpp:308
select the system time source
Definition: clock.h:41
void register_ext_timesource(TimeSource *ts, bool make_default=false)
Register an external time source.
Definition: clock.cpp:92
static void finalize()
Finalize.
Definition: clock.cpp:77
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:295
void remove_ext_timesource(TimeSource *ts=0)
Remove external time source.
Definition: clock.cpp:108
select the default time source
Definition: clock.h:40