Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

RepeatTimerCore Class Reference

Inherits BaseModule.

Collaboration diagram for RepeatTimerCore:
Collaboration graph
[legend]

List of all members.

Classes

struct  TInfo

Public Types

typedef void( cleanup )(void *data)

Public Member Functions

void init (RepeatTimer *t)
void setRepeatTimer (unsigned int index, double when, int repeats=1)
unsigned int setRepeatTimer (double when, int repeats=1)
void cancelRepeatTimer (unsigned int index)
void resetRepeatTimer (unsigned int index)
void resetAllRepeatTimers (void)
bool timerExists (unsigned int index)
float remainingRepeatTimer (unsigned int index)
void setContextPointer (unsigned int index, void *data)
void * contextPointer (unsigned int index)
void setContextDestructor (unsigned int index, cleanup *)
void allocateRepeatTimers (unsigned int count)
void deleteRepeatTimer (unsigned int index)

Protected Member Functions

void checkExists (unsigned int index)
virtual void handleMessage (cMessage *msg)
 Handle self messages.

Protected Attributes

RepeatTimertimer
std::map< unsigned int, TInfo > * timer_map

Detailed Description

Definition at line 9 of file RepeatTimerCore.h.


Member Function Documentation

void RepeatTimerCore::cancelRepeatTimer ( unsigned int  index  ) 

Cancel an existing timer set by setRepeatTimer() If the timer has not been set, or has already fires, this does nothing Must call init() before using.

Parameters:
index RepeatTimer to cancel. Must be between 0 and the value given to init()

Definition at line 63 of file RepeatTimerCore.cc.

{
  Enter_Method_Silent();
  checkExists(index);
  if ((*timer_map)[index].timer->isScheduled())
    cancelEvent((*timer_map)[index].timer);
}

void * RepeatTimerCore::contextPointer ( unsigned int  index  ) 

Retreive a "context pointer" refering to some piece of opaque useful data

Parameters:
index RepeatTimer number
Returns:
Opaque pointer from

Definition at line 107 of file RepeatTimerCore.cc.

{
  checkExists(index);
  return (*timer_map)[index].timer->getContextPointer();
}

float RepeatTimerCore::remainingRepeatTimer ( unsigned int  index  ) 

Fires on expiration of a timer. Fires after a call to setRepeatTimer(). Subclasses should override this.

Parameters:
index RepeatTimer number that fired. Will be between 0 and the value given to init()

Definition at line 71 of file RepeatTimerCore.cc.

{
  checkExists(index);
  if ((*timer_map)[index].timer->isScheduled())
    return SIMTIME_DBL((*timer_map)[index].timer->getArrivalTime()-simTime());
  else
    return -1;
}

void RepeatTimerCore::setContextDestructor ( unsigned int  index,
cleanup *  c 
)

Provide a destructor function for a "context pointer" such that we can do complete cleanup even if there are still timers remaining at the end of a simulation. Called on end of sim for still scheduled timers.

Parameters:
index RepeatTimer number

Definition at line 80 of file RepeatTimerCore.cc.

{
  checkExists(index);
  (*timer_map)[index].destructor = c;
}

void RepeatTimerCore::setContextPointer ( unsigned int  index,
void *  data 
)

Set a "context pointer" refering to some piece of opaque useful data

Parameters:
index RepeatTimer number
data Opaque pointer. Never free'd or dereferenced

Definition at line 101 of file RepeatTimerCore.cc.

{
  checkExists(index);
  (*timer_map)[index].timer->setContextPointer(data);
}

void RepeatTimerCore::setRepeatTimer ( unsigned int  index,
double  when,
int  repeats = 1 
)

Set a timer to fire at a point in the future. If the timer with that id has already been set then this discards the old information.

Parameters:
index RepeatTimer number to set.
when Time in seconds in the future to fire the timer

Definition at line 43 of file RepeatTimerCore.cc.

Referenced by setRepeatTimer().

{
  Enter_Method_Silent();
  cMessage *timer;
  if (timer_map->find(index)==timer_map->end()) {
    timer = new cMessage("timer");
    timer->setKind(index);
    (*timer_map)[index].timer = timer;
    (*timer_map)[index].destructor = NULL;
  } else {
    timer = (*timer_map)[index].timer;
    if (timer->isScheduled())
      cancelEvent(timer);
  }
  (*timer_map)[index].count = (*timer_map)[index].repeats = repeats;
  (*timer_map)[index].when = when;

  scheduleAt(simTime() + when, timer);  
}

unsigned int RepeatTimerCore::setRepeatTimer ( double  when,
int  repeats = 1 
)

Set a timer to fire at a point in the future. Auto-generates a timer id that's guaranteed not to have been used by anyone else. If the timer with that id has already been set then this discards the old information.

Parameters:
when Time in seconds in the future to fire the timer
Returns:
RepeatTimer id

Definition at line 34 of file RepeatTimerCore.cc.

References setRepeatTimer().

{
  unsigned int key = timer_map->size();
  while (timer_map->find(key)!=timer_map->end())
    key++;
  setRepeatTimer(key,when,repeats);
  return key;
}


The documentation for this class was generated from the following files: