Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Net/TFTP/Timer.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__Timer_CPP__
00002 #define __J2K__Timer_CPP__
00003 
00004 #include <j2k/Net/TFTP/Timer.hpp>
00005 
00006 // Setup a timer, to be started later.
00007 Timer::Timer( ULONG nsec, ULONG sec = 0 ) 
00008 {
00009   if ( theTimer != NULL ) {
00010     delete theTimer;
00011   }
00012 
00013   theTimer = &(*this);
00014 
00015   memset( &event, 0, sizeof( event ) );
00016 
00017   event.sigev_notify = SIGEV_SIGNAL;
00018   event.sigev_signo  = TimerSignal;
00019 
00020   memset( &t, 0, sizeof( t ) );
00021 
00022   t.it_value.tv_nsec    = nsec;
00023   t.it_interval.tv_nsec = nsec;
00024 
00025   t.it_value.tv_sec     = sec;
00026   t.it_interval.tv_sec  = sec;
00027    
00028   // create the timer, binding it to the event
00029   if ( timer_create( CLOCK_REALTIME, &event, &timerid ) == -1 )
00030   {
00031      MC_OnError( errno, Error, "while creating a timer." )
00032   }
00033 
00034   struct sigaction act;
00035   sigset_t set;
00036 
00037   sigemptyset( &set );
00038   sigaddset(   &set, TimerSignal );
00039 
00040   // Define a handler for TimerSignal
00041   act.sa_flags   = 0;
00042   act.sa_mask    = set;
00043   act.sa_handler = &wrapper;
00044 
00045   sigaction( TimerSignal, &act, NULL );
00046 }
00047 
00048 inline void Timer::start() {
00049   timer_settime( timerid, 0, &t, NULL );
00050 }
00051 
00052 #endif

Generated on Sun Oct 14 18:46:20 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001