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
00031 #endif
00032
00033 class TimerPulse;
00034
00035 class TimerPulse : public Basic_PThread
00036 {
00037
00038 public:
00039
00040 static const ULONG TimerPulse::Period_1_ms = 1000000L;
00041 static const ULONG TimerPulse::Period_10_ms = 10000000L;
00042 static const ULONG TimerPulse::Period_20_ms = 20000000L;
00043 static const ULONG TimerPulse::Period_50_ms = 50000000L;
00044 static const ULONG TimerPulse::Period_100_ms = 100000000L;
00045 static const ULONG TimerPulse::Period_250_ms = 250000000L;
00046 static const ULONG TimerPulse::Period_500_ms = 500000000L;
00047 static const ULONG TimerPulse::Period_750_ms = 750000000L;
00048
00049 public:
00050
00051
00052 TimerPulse( ULONG nsec = Period_500_ms, ULONG sec = 0 );
00053
00054
00055
00056
00057 inline virtual void stop()
00058 {
00059 set( 0, 0 );
00060 }
00061
00062 void set( ULONG nsec = Period_500_ms, ULONG sec = 0 );
00063
00064 inline int getChid() { return chid; }
00065
00066 protected:
00067
00068
00069 virtual void tick( int signo ) = 0;
00070 virtual void run();
00071
00072
00073 int pulse_id;
00074 int timer_pid;
00075 int chid;
00076
00077 timer_t timer_id;
00078
00079 struct _pulse pulse;
00080 struct sigevent event;
00081 struct _clockperiod clkper;
00082 struct itimerspec t;
00083
00084 };
00085
00086 #ifndef __TIMER__ALIAS
00087 #define __TIMER__ALIAS
00088
00089 typedef TimerPulse Timer;
00090
00091 #endif
00092
00093 #endif