#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 549 of file common.cpp. References tdelay_, tid_, and timerProc(). 00550 {
00551 tdelay_.tv_nsec = (long int)((delay - (int)delay)*1e9);
00552 tdelay_.tv_sec = (int)delay;
00553 int error = pthread_create(&tid_, NULL, &timerProc, this );
00554 if (error)
00555 throw "Timer thread creation failed...";
00556
00557 }
|
|
|
Function to stop a timer Definition at line 558 of file common.cpp. References tid_. 00559 {
00560 pthread_cancel(tid_);
00561 }
|
|
|
Function to create a seperate thread for this timer it will call timerHandler() function of the port_ Definition at line 542 of file common.cpp. References port_, tdelay_, and SendingPort::timerHandler(). Referenced by startTimer(). 00542 {
00543 TxTimer *th = (TxTimer *)arg;
00544 nanosleep(&(th->tdelay_), NULL);
00545 th->port_->timerHandler();
00546 return NULL;
00547 }
|
|
|
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(). |
1.4.2