00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _TIMER_H
00021 #define _TIMER_H
00022
00023 #include <signal.h>
00024 #include <time.h>
00025 #include "callback.h"
00026
00027 namespace freesecs
00028 {
00029 class async_reception_t;
00030
00039 class ms_timer_t
00040 {
00041 public:
00046 ms_timer_t();
00047 ~ms_timer_t();
00053 int start(unsigned long timeout_ms);
00057 int stop();
00058
00062 template<class T>
00063 void add_handler(T *p_class, int (T::*p_func)())
00064 {
00065 _cb = callback_t(p_class, p_func);
00066 }
00067
00068 private:
00069 int _timeout_fd[2];
00070 async_reception_t *_ar;
00071 int ar_handler(const size_t&);
00072
00073
00074 private:
00075 static void interrupt(int signo, siginfo_t *info, void *context);
00076
00077 timer_t _id;
00078 callback_t _cb;
00079
00080 static int _subscr_count;
00081 static struct sigaction _old_act;
00082 };
00083 }
00084 #endif //_TIMER_H