00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FBTK_TIMER_HH
00026 #define FBTK_TIMER_HH
00027
00028 #include "RefCount.hh"
00029
00030 #include <ctime>
00031 #include <list>
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif //HAVE_CONFIG_H
00036
00037 #ifdef HAVE_INTTYPES_H
00038 #include <inttypes.h>
00039 #include <sys/types.h>
00040 #endif // HAVE_INTTYPES_H
00041
00042 #include <sys/select.h>
00043 #include <sys/time.h>
00044 #include <sys/types.h>
00045 #include <unistd.h>
00046
00047 namespace FbTk {
00048
00049 class Command;
00050
00054 class Timer {
00055 public:
00056 Timer();
00057 explicit Timer(RefCount<Command> &handler);
00058 virtual ~Timer();
00059
00060 inline void fireOnce(bool once) { m_once = once; }
00062 void setTimeout(time_t val);
00064 void setTimeout(timeval val);
00065 void setCommand(RefCount<Command> &cmd);
00067 void start();
00069 void stop();
00071 static void updateTimers(int file_descriptor);
00072
00073 inline int isTiming() const { return m_timing; }
00074 inline int doOnce() const { return m_once; }
00075
00076 inline const timeval &getTimeout() const { return m_timeout; }
00077 inline const timeval &getStartTime() const { return m_start; }
00078
00079 protected:
00081 void fireTimeout();
00082
00083 private:
00085 static void addTimer(Timer *timer);
00087 static void removeTimer(Timer *timer);
00088
00089 typedef std::list<Timer *> TimerList;
00090 static TimerList m_timerlist;
00091
00092 RefCount<Command> m_handler;
00093
00094 bool m_timing;
00095 bool m_once;
00096
00097 timeval m_start;
00098 timeval m_timeout;
00099
00100 };
00101
00102 }
00103
00104 #endif // FBTK_TIMER_HH
00105