#include <common.h>
Public Member Functions | |
TxTimer (SendingPort *txport) | |
TxTimer class. | |
void | startTimer (float delay) |
void | stopTimer () |
Static Public Member Functions | |
static void * | timerProc (void *arg) |
Protected Attributes | |
SendingPort * | port_ |
timespec | tdelay_ |
pthread_t | tid_ |
Friends | |
class | SendingPort |
The timer is associated with a SendingPort object. when the timer expires, the SendingPort::timerHandler() will be called.
The intenal design of this class is a little tricky. Usually, LinuxThreads does not support a thread function as a member function of C++ class. I designed timerProc as a static function, and give the class pointer as the 4th argument of the pthread_create
Definition at line 268 of file common.h.
|
Function to start a timer which will expire after a certain delay
Definition at line 554 of file common.cpp. References tdelay_, tid_, and timerProc(). 00555 { 00556 tdelay_.tv_nsec = (long int)((delay - (int)delay)*1e9); 00557 tdelay_.tv_sec = (int)delay; 00558 int error = pthread_create(&tid_, NULL, &timerProc, this ); 00559 if (error) 00560 throw "Timer thread creation failed..."; 00561 00562 }
|
|
Function to stop a timer Definition at line 563 of file common.cpp. References tid_. 00564 { 00565 pthread_cancel(tid_); 00566 }
|
|
Function to create a seperate thread for this timer it will call timerHandler() function of the port_ Definition at line 547 of file common.cpp. References port_, tdelay_, and SendingPort::timerHandler(). Referenced by startTimer(). 00547 { 00548 TxTimer *th = (TxTimer *)arg; 00549 nanosleep(&(th->tdelay_), NULL); 00550 th->port_->timerHandler(); 00551 return NULL; 00552 }
|
|
port the timer belongs to Definition at line 290 of file common.h. Referenced by timerProc(), and TxTimer(). |
|
delay variable used by nanosleep() Definition at line 294 of file common.h. Referenced by startTimer(), timerProc(), and TxTimer(). |
|
thread id variable Definition at line 298 of file common.h. Referenced by startTimer(), and stopTimer(). |