ARPDAS_QNX6 1.0
|
00001 /** 00002 * DG_tmr Object definitions 00003 */ 00004 #include <signal.h> 00005 #include <errno.h> 00006 #include <unistd.h> 00007 #include <sys/neutrino.h> 00008 #include <sys/netmgr.h> 00009 #include <sys/iomsg.h> 00010 #include "tm.h" 00011 #include "DG_Resmgr.h" 00012 #include "DG_cmd.h" 00013 #include "DG_tmr.h" 00014 00015 int DG_tmr_pulse_func( message_context_t *ctp, int code, 00016 unsigned flags, void *handle ) { 00017 DG_tmr *tmr = (DG_tmr *)handle; 00018 tmr->dg->service_row_timer(); 00019 return 0; 00020 } 00021 00022 DG_tmr::DG_tmr(data_generator *data_gen) : DG_dispatch_client() { 00023 timerid = -1; 00024 dg = data_gen; 00025 struct timespec ts; 00026 if (clock_getres(CLOCK_REALTIME, &ts)) 00027 nl_error(4, "Error from clock_getres()"); 00028 timer_resolution_nsec = timespec2nsec(&ts); 00029 } 00030 00031 void DG_tmr::attach() { 00032 struct sigevent tmr_ev; 00033 int rc; 00034 00035 pulse_code = 00036 pulse_attach( dg->dispatch->dpp, MSG_FLAG_ALLOC_PULSE, 0, DG_tmr_pulse_func, this ); 00037 if ( pulse_code < 0 ) 00038 nl_error(3, "Error %d from pulse_attach", errno ); 00039 int coid = message_connect( dg->dispatch->dpp, MSG_FLAG_SIDE_CHANNEL ); 00040 if ( coid == -1 ) 00041 nl_error(3, "Error %d from message_connect", errno ); 00042 tmr_ev.sigev_notify = SIGEV_PULSE; 00043 tmr_ev.sigev_coid = coid; 00044 tmr_ev.sigev_priority = getprio(0); 00045 tmr_ev.sigev_code = pulse_code; 00046 rc = timer_create( CLOCK_REALTIME, &tmr_ev, &timerid ); 00047 if ( rc < 0 ) nl_error( 3, "Error creating timer" ); 00048 DG_dispatch_client::attach(dg->dispatch); 00049 } 00050 00051 int DG_tmr::ready_to_quit() { 00052 if ( timerid != -1 ) { 00053 if ( pulse_detach(dg->dispatch->dpp, pulse_code, 0) == -1 ) { 00054 nl_error( 2, "pulse_detach returned -1" ); 00055 } 00056 if ( timer_delete(timerid) == -1 ) { 00057 nl_error( 2, "timer_delete returned errno %d", errno ); 00058 } 00059 timerid = -1; 00060 } 00061 return 1; 00062 } 00063 00064 DG_tmr::~DG_tmr() { 00065 nl_error( 0, "Destructing DG_tmr object" ); 00066 } 00067 00068 void DG_tmr::settime( int per_sec, int per_nsec ) { 00069 struct itimerspec itime; 00070 00071 itime.it_value.tv_sec = itime.it_interval.tv_sec = per_sec; 00072 itime.it_value.tv_nsec = itime.it_interval.tv_nsec = per_nsec; 00073 timer_settime(timerid, 0, &itime, NULL); 00074 } 00075 00076 void DG_tmr::settime( uint64_t per_nsec ) { 00077 struct itimerspec itime; 00078 nsec2timespec( &itime.it_value, per_nsec ); 00079 itime.it_interval = itime.it_value; 00080 timer_settime(timerid, 0, &itime, NULL); 00081 }