Main Page | Class Hierarchy | Class List | File List | Class Members

TxTimer Class Reference

A timer to schedule a later event/transmission occured in a port. More...

#include <common.h>

List of all members.

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

timespec tdelay_
pthread_t tid_


class SendingPort

Detailed Description

A timer to schedule a later event/transmission occured in a port.

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.

Member Function Documentation

void TxTimer::startTimer float  delay  ) 

Function to start a timer which will expire after a certain delay

delay,: the timing delay in seconds.

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...";
00557 }

void TxTimer::stopTimer  ) 

Function to stop a timer

Definition at line 558 of file common.cpp.

References tid_.

00559 {
00560   pthread_cancel(tid_);
00561 }

void * TxTimer::timerProc void *  arg  )  [static]

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 }

Member Data Documentation

SendingPort* TxTimer::port_ [protected]

port the timer belongs to

Definition at line 290 of file common.h.

Referenced by timerProc(), and TxTimer().

struct timespec TxTimer::tdelay_ [protected]

delay variable used by nanosleep()

Definition at line 294 of file common.h.

Referenced by startTimer(), timerProc(), and TxTimer().

pthread_t TxTimer::tid_ [protected]

thread id variable

Definition at line 298 of file common.h.

Referenced by startTimer(), and stopTimer().

The documentation for this class was generated from the following files:
Generated on Fri Feb 17 17:55:49 2006 for Common_Classes_Projects_ECE544 by  doxygen 1.4.2