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

C:/temp/src/j2k/nto/bak2/TimerPulse.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__TimerPulse_CPP__
00002 #define __J2K__TimerPulse_CPP__
00003 
00004 #include <j2k/nto/TimerPulse.hpp>
00005 #include <j2k/nto/fixprio.hpp>
00006 
00007 // Setup a timer, to be started later.
00008 TimerPulse::TimerPulse( ULONG nsec, ULONG sec )  
00009  : pulse_id( TimerSignalEvent ), chid( ~0 )
00010 {
00011   memset( &event, 0, sizeof( event ) );
00012 
00013   // Set priority to max, so we don't get disrupted 
00014   // by anything else then interrupts
00015 
00016   printf( "Creating channel" );
00017 
00018   // Create a channel to receive the timer event
00019   chid = ChannelCreate( 0 );
00020   assert( chid != -1 );
00021 
00022   // Setup timer and timer event
00023   event.sigev_notify     = SIGEV_PULSE;
00024   event.sigev_coid       = ConnectAttach( ND_LOCAL_NODE, 0, chid, 0, 0 );
00025   event.sigev_priority   = getprio( 0 ); // fixprio( 20 );
00026   event.sigev_code       = 1023;
00027   event.sigev_value.sival_ptr = (void*)pulse_id;
00028 
00029   assert( event.sigev_coid != -1 );
00030 
00031   // Create the timer, binding it to the event
00032 
00033   if ( timer_create( CLOCK_REALTIME, &event, &timer_id ) == -1 )
00034   {
00035     MC_OnError( errno, Error, "while creating a timer." )
00036     perror( "Can't create timer.\n" );
00037     exit( 1 );
00038   }
00039   
00040   memset( &t, 0, sizeof( t ) );
00041 
00042   set( nsec, sec );
00043 
00044 }
00045 
00046 void TimerPulse::set( ULONG nsec, ULONG sec )
00047 {
00048   // Change timer request to alter behavior
00049   t.it_value.tv_sec         = sec;
00050   t.it_value.tv_nsec        = nsec;
00051   t.it_interval.tv_sec      = sec;
00052   t.it_interval.tv_nsec     = nsec;
00053 
00054   // Start the timer
00055   if ( timer_settime( timer_id, 0, &t, NULL ) == -1 )
00056   {
00057     MC_OnError( errno, Error, "Can't start timer." )
00058     perror( "Can't start timer\n" );
00059     exit( 1 );
00060   }
00061 }
00062 
00063 void TimerPulse::run() 
00064 {
00065   // Start the timer
00066   if ( timer_settime( timer_id, 0, &t, NULL ) == -1 )
00067   {
00068     MC_OnError( errno, Error, "Can't start timer." )
00069     perror( "Can't start timer\n" );
00070     exit( 1 );
00071   }
00072 
00073   for(;;) 
00074   {
00075     // Wait for pulse
00076     if ( MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL ) ) 
00077     {
00078      MC_OnError( errno, Error, "Invalid pulse received by TimerPulse.\n" )
00079     }
00080     tick( pulse_id );
00081   }
00082 } 
00083 
00084 #endif

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