Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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  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_ */