Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

EventQueue Class Reference

#include <events.hh>

Collaboration diagram for EventQueue:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 EventQueue ()
virtual ~EventQueue ()
virtual void eqAddAfter (handle hdl, void *payload, int delay_msec)
QueueEventeqPop ()
QueueEventeqFindEvent (handle hdl)
void eqNextTimer (struct timeval *tv)
virtual bool eqRemove (handle hdl)

Private Member Functions

int eqTopInPast ()
void eqPrint ()
bool eqRemoveEvent (QueueEvent *e)
QueueEventeqFindNextEvent (handle hdl, QueueEvent *e)
void eqAdd (QueueEvent *e)
void setDelay (QueueEvent *e, int delay_msec)
int randDelay (int timer[2])
int eventCmp (QueueEvent *x, QueueEvent *y)

Private Attributes

QueueEventhead_

Constructor & Destructor Documentation

EventQueue::EventQueue  )  [inline]
 

Definition at line 66 of file events.hh.

References head_.

00066               {
00067     // Empty
00068     head_ = NULL;
00069   };

virtual EventQueue::~EventQueue  )  [inline, virtual]
 

Definition at line 70 of file events.hh.

00070                        {
00071     // Empty
00072   };


Member Function Documentation

void EventQueue::eqAdd QueueEvent e  )  [private]
 

Definition at line 76 of file events.cc.

References eventCmp(), head_, and QueueEvent::next_.

Referenced by eqAddAfter().

00077 {
00078   QueueEvent *ptr = head_;
00079   QueueEvent *last = ptr;
00080 
00081   while (ptr && (eventCmp(e, ptr) > 0)){
00082     last = ptr; 
00083     ptr = ptr->next_;
00084   }
00085   if (last == ptr){
00086     e->next_ = head_;
00087     head_ = e;
00088   }
00089   else{
00090     e->next_ = ptr;
00091     last->next_ = e;
00092   }
00093 }

Here is the call graph for this function:

void EventQueue::eqAddAfter handle  hdl,
void *  payload,
int  delay_msec
[virtual]
 

Definition at line 122 of file events.cc.

References eqAdd(), QueueEvent::handle_, QueueEvent::payload_, and setDelay().

Referenced by TimerManager::addTimer(), and TimerManager::executeNextTimer().

00123 {
00124   QueueEvent *e = new QueueEvent;
00125 
00126   e->handle_ = hdl;
00127   e->payload_ = payload;
00128   setDelay(e, delay_msec);
00129   eqAdd(e);
00130 }

Here is the call graph for this function:

QueueEvent * EventQueue::eqFindEvent handle  hdl  ) 
 

Definition at line 106 of file events.cc.

References eqFindNextEvent(), and head_.

Referenced by eqRemove(), and TimerManager::removeTimer().

00107 {
00108   return eqFindNextEvent(hdl, head_);
00109 }

Here is the call graph for this function:

QueueEvent * EventQueue::eqFindNextEvent handle  hdl,
QueueEvent e
[private]
 

Definition at line 111 of file events.cc.

References QueueEvent::handle_, and QueueEvent::next_.

Referenced by eqFindEvent().

00112 {
00113   while (e){
00114     if (e->handle_ == hdl)
00115       return e;
00116     e = e->next_;
00117   }
00118 
00119   return e;
00120 }

void EventQueue::eqNextTimer struct timeval *  tv  ) 
 

Definition at line 138 of file events.cc.

References GetTime(), head_, MAXVALUE, TimevalSub(), and QueueEvent::tv_.

Referenced by TimerManager::nextTimerTime().

00139 {
00140   struct timeval now;
00141 
00142   if (head_){
00143     GetTime(&now);
00144     TimevalSub(&(head_->tv_), &now, tv);
00145   }
00146   else{
00147     tv->tv_sec = MAXVALUE;
00148     tv->tv_usec = 0;
00149   }
00150 }

Here is the call graph for this function:

QueueEvent * EventQueue::eqPop  ) 
 

Definition at line 95 of file events.cc.

References head_, and QueueEvent::next_.

Referenced by TimerManager::executeNextTimer().

00096 {
00097   QueueEvent *e = head_;
00098 
00099   if (e){
00100     head_ = head_->next_;
00101     e->next_ = NULL;
00102   }
00103   return e;
00104 }

void EventQueue::eqPrint  )  [private]
 

Definition at line 163 of file events.cc.

References QueueEvent::handle_, head_, QueueEvent::next_, and QueueEvent::tv_.

00164 {
00165   QueueEvent *e = head_;
00166 
00167   for (; (e); e = e->next_){
00168     fprintf(stderr, "time = %d:%06d, handle = %ld\n",
00169             e->tv_.tv_sec, e->tv_.tv_usec, e->handle_);
00170   }
00171 }

bool EventQueue::eqRemove handle  hdl  )  [virtual]
 

Definition at line 201 of file events.cc.

References eqFindEvent(), and eqRemoveEvent().

Referenced by TimerManager::removeTimer().

00202 {
00203   QueueEvent *e = NULL;
00204 
00205   // Look in the event queue for an event with handle hdl
00206   e = eqFindEvent(hdl);
00207 
00208   // If found, delete event
00209   if (e){
00210     return (eqRemoveEvent(e));
00211   }
00212 
00213   return false;
00214 }

Here is the call graph for this function:

bool EventQueue::eqRemoveEvent QueueEvent e  )  [private]
 

Definition at line 173 of file events.cc.

References head_, and QueueEvent::next_.

Referenced by eqRemove().

00174 {
00175   QueueEvent *ce, *pe;
00176 
00177   if (e){
00178     if (head_ == e){
00179       head_ = e->next_;
00180       return true;
00181     }
00182 
00183     pe = head_;
00184     ce = head_->next_;
00185 
00186     while (ce){
00187       if (ce == e){
00188         pe->next_ = e->next_;
00189         return true;
00190       }
00191       else{
00192         pe = ce;
00193         ce = ce->next_;
00194       }
00195     }
00196   }
00197 
00198   return false;
00199 }

int EventQueue::eqTopInPast  )  [private]
 

Definition at line 152 of file events.cc.

References GetTime(), head_, TimevalCmp(), and QueueEvent::tv_.

00153 {
00154   struct timeval now;
00155 
00156   if (head_){
00157     GetTime(&now);
00158     return (TimevalCmp(&(head_->tv_), &now) <= 0);
00159   }
00160   return 0;
00161 }

Here is the call graph for this function:

int EventQueue::eventCmp QueueEvent x,
QueueEvent y
[private]
 

Definition at line 71 of file events.cc.

References TimevalCmp(), and QueueEvent::tv_.

Referenced by eqAdd().

00072 {
00073   return TimevalCmp(&(x->tv_), &(y->tv_));
00074 }

Here is the call graph for this function:

int EventQueue::randDelay int  timer[2]  )  [private]
 

Definition at line 219 of file events.cc.

References GetRand(), and RAND_MAX.

00220 {
00221   return (int) (timer[0] + ((((float) GetRand()) /
00222                              ((float) RAND_MAX)) - 0.5) * timer[1]);
00223 }

Here is the call graph for this function:

void EventQueue::setDelay QueueEvent e,
int  delay_msec
[private]
 

Definition at line 132 of file events.cc.

References GetTime(), TimevalAddusecs(), and QueueEvent::tv_.

Referenced by eqAddAfter().

00133 {
00134   GetTime(&(e->tv_));
00135   TimevalAddusecs(&(e->tv_), delay_msec * 1000);
00136 }

Here is the call graph for this function:


Member Data Documentation

QueueEvent* EventQueue::head_ [private]
 

Definition at line 102 of file events.hh.

Referenced by eqAdd(), eqFindEvent(), eqNextTimer(), eqPop(), eqPrint(), eqRemoveEvent(), eqTopInPast(), and EventQueue().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:46:02 2004 for NS2.26SourcesOriginal by doxygen 1.3.3