timer.h

00001 /*   
00002  *   (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net)
00003  *
00004  *   This file is part of FREESECS.
00005  *
00006  *   FREESECS is free software: you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation, either version 3 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   FREESECS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with FREESECS, see COPYING.
00018  *   If not, see <http://www.gnu.org/licenses/>.
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 }//namespace
00084 #endif //_TIMER_H

Generated on Fri Oct 3 15:30:01 2008 for FREESECS hsms by  doxygen 1.5.1