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