00001
00002
00003 #ifndef __J2K__TimerSignal_HPP__
00004 #define __J2K__TimerSignal_HPP__
00005
00006 #include <j2k/Fred/Standard.hpp>
00007 #include <j2k/Fred/Error/JErrorController.hpp>
00008
00009 #include <unistd.h>
00010 #include <errno.h>
00011 #include <pthread.h>
00012 #include <signal.h>
00013 #include <sys/time.h>
00014
00015 #if !defined( linux )
00016 #include <sys/siginfo.h>
00017 #endif
00018
00019
00020 #if defined( __QNXNTO__ )
00021
00022 #include <sys/neutrino.h>
00023
00024 #endif
00025
00026
00027 #ifndef TimerSignalEvent
00028 #define TimerSignalEvent SIGUSR1
00029 #endif
00030
00031 class TimerSignal;
00032
00033
00034
00035 class TimerSignal {
00036 protected:
00037 static TimerSignal* theTimer;
00038
00039 public:
00040
00041 static const ULONG TimerSignal::Period_1_ms = 1000000L;
00042 static const ULONG TimerSignal::Period_10_ms = 10000000L;
00043 static const ULONG TimerSignal::Period_20_ms = 20000000L;
00044 static const ULONG TimerSignal::Period_50_ms = 50000000L;
00045 static const ULONG TimerSignal::Period_100_ms = 100000000L;
00046 static const ULONG TimerSignal::Period_250_ms = 250000000L;
00047 static const ULONG TimerSignal::Period_500_ms = 500000000L;
00048 static const ULONG TimerSignal::Period_750_ms = 750000000L;
00049
00050 public:
00051
00052
00053 TimerSignal( ULONG nsec = Period_500_ms, ULONG sec = 0 );
00054
00055 inline virtual void start();
00056 inline virtual void stop();
00057
00058 void set( ULONG nsec = Period_500_ms, ULONG sec = 0 );
00059
00060
00061
00062 protected:
00063
00064
00065 static void wrapper( int signo )
00066 {
00067 assert( signo == TimerSignalEvent );
00068 theTimer->tick( signo );
00069 }
00070
00071
00072 virtual void tick( int signo ) = 0;
00073
00074
00075 private:
00076 timer_t timer_id;
00077 struct sigevent event;
00078 struct itimerspec t;
00079 };
00080
00081 #include <j2k/nto/TimerSignal.inl>
00082
00083
00084 #ifndef __TIMER__ALIAS
00085 #define __TIMER__ALIAS
00086
00087 typedef TimerSignal Timer;
00088
00089 #endif
00090
00091 #endif