Fawkes API Fawkes Development Version

clock.h

00001 
00002 /***************************************************************************
00003  *  clock.h - A central clock
00004  *
00005  *  Generated: Sun Jun 03 00:16:29 2007
00006  *  Copyright  2007  Daniel Beck 
00007  *             2007  Tim Niemueller [www.niemueller.de]
00008  *
00009  ****************************************************************************/
00010 
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version. A runtime exception applies to
00015  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU Library General Public License for more details.
00021  *
00022  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00023  */
00024 
00025 #ifndef __UTILS_TIME_CLOCK_H_
00026 #define __UTILS_TIME_CLOCK_H_
00027 
00028 #include <utils/time/time.h>
00029 
00030 namespace fawkes {
00031 
00032 class TimeSource;
00033 
00034 class Clock
00035 {
00036  public:
00037 
00038   /** Select the time source. */
00039   typedef enum {
00040     DEFAULT,            /**< select the default time source */
00041     REALTIME,           /**< select the system time source */
00042     EXTERNAL            /**< select the external time source */
00043   } TimesourceSelector;
00044 
00045   virtual ~Clock();
00046   
00047   static Clock * instance();
00048   static void    finalize();
00049 
00050   void register_ext_timesource(TimeSource* ts, bool make_default = false);
00051   void set_ext_default_timesource(bool ext_is_default);
00052   bool is_ext_default_timesource() const;
00053   bool has_ext_timesource() const;
00054   Time ext_to_realtime(const Time& t);
00055   void remove_ext_timesource(TimeSource *ts = 0);
00056 
00057   void get_time(struct timeval *tv) const;
00058   void get_time(struct timeval *tv, TimesourceSelector sel) const;
00059 
00060   void get_time(Time &time) const;
00061   void get_time(Time &time, TimesourceSelector sel) const;
00062 
00063   void get_time(Time *time) const;
00064   void get_time(Time *time, TimesourceSelector sel) const;
00065 
00066   void get_systime(struct timeval *tv) const;
00067   void get_systime(Time &time) const;
00068   void get_systime(Time *time) const;
00069 
00070   Time  now() const;
00071   float elapsed(Time *t) const;
00072   float sys_elapsed(Time *t) const;
00073 
00074  private:
00075   Clock();
00076 
00077   static bool destruct_ok;
00078 
00079   TimeSource *ext_timesource;
00080   bool ext_default;
00081 
00082   static Clock* _instance;
00083 };
00084 
00085 } // end namespace fawkes
00086 
00087 #endif /* __UTILS_TIME_CLOCK_H_ */
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends