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
30namespace fawkes {
31
32class TimeSource;
33
34class Clock
35{
36public:
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);
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
74private:
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__ */
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35
void remove_ext_timesource(TimeSource *ts=0)
Remove external time source.
Definition: clock.cpp:103
TimesourceSelector
Select the time source.
Definition: clock.h:38
@ DEFAULT
select the default time source
Definition: clock.h:39
@ REALTIME
select the system time source
Definition: clock.h:40
@ EXTERNAL
select the external time source
Definition: clock.h:41
Time native_to_time(const Time &t)
Convert some native time to a Fawkes time.
Definition: clock.cpp:302
static void finalize()
Finalize.
Definition: clock.cpp:74
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
void register_ext_timesource(TimeSource *ts, bool make_default=false)
Register an external time source.
Definition: clock.cpp:88
bool is_ext_default_timesource() const
Checks whether the external time source is the default time soucre.
Definition: clock.cpp:136
virtual ~Clock()
Destructor.
Definition: clock.cpp:52
Time now() const
Get the current time.
Definition: clock.cpp:242
void get_time(struct timeval *tv) const
Returns the time of the selected time source.
Definition: clock.cpp:161
bool has_ext_timesource() const
Check whether an external time source is registered.
Definition: clock.cpp:319
static Clock * instance()
Clock initializer.
Definition: clock.cpp:63
void get_systime(struct timeval *tv) const
Returns the system time.
Definition: clock.cpp:215
void set_ext_default_timesource(bool ext_is_default)
Set/unset the external time source as the default time source.
Definition: clock.cpp:118
Time ext_to_realtime(const Time &t)
Convert a time given w.r.t.
Definition: clock.cpp:278
float elapsed(Time *t) const
How much time has elapsed since t? Calculated as "now - t" in seconds.
Definition: clock.cpp:254
TimeSource interface.
Definition: timesource.h:37
A class for handling time.
Definition: time.h:93
Fawkes library namespace.