libassa  3.5.1
TimerQueue.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // TimerQueue.h
4 //------------------------------------------------------------------------------
5 // Copyright (c) 1999,2005 by Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 // Created: 07/28/1999
13 //------------------------------------------------------------------------------
14 #ifndef TIMER_QUEUE_H
15 #define TIMER_QUEUE_H
16 
17 #include <time.h>
18 #include <sys/time.h>
19 #include <unistd.h>
20 
21 #include "assa/Logger.h"
22 #include "assa/EventHandler.h"
23 #include "assa/Timer.h"
24 #include "assa/PriorityQueue.h"
25 
26 namespace ASSA {
27 
28 typedef unsigned long TimerId;
29 
36 {
37 public:
39  TimerQueue ();
40 
42  ~TimerQueue ();
43 
47  bool isEmpty ();
48 
62  const TimeVal& tv_,
63  const TimeVal& delta_,
64  const std::string& name_);
65 
70  int remove (EventHandler* eh_);
71 
76  bool remove (TimerId tid_);
77 
84  int expire (const TimeVal& tv_);
85 
87  TimeVal& top (void);
88 
90  void dump (void);
91 
92 private:
95 };
96 
97 //------------------------------------------------------------------------------
98 // Inline functions
99 //------------------------------------------------------------------------------
100 
101 inline
103 TimerQueue ()
104 {
105  trace("TimerQueue::TimerQueue");
106 }
107 
108 inline bool
110 isEmpty ()
111 {
112  return m_queue.size () == 0;
113 }
114 
115 inline TimeVal&
117 top (void)
118 {
119  return (TimeVal&) m_queue.top ()->getExpirationTime ();
120 }
121 
122 } // end namespace ASSA
123 
124 #endif /* TIMER_QUEUE_H */
An abstract interface for handling I/O events, timers, and such.
An abstraction to message logging facility.
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition: Logger.h:429
Priority Queue class that allows removal of arbitrariy element from the queue.
Timer class represents tuple that is stored in TimerQueue.
EventHandler class.
Definition: EventHandler.h:103
PriorityQueue< Timer *, TimerCompare > m_queue
Timer queue itself.
Definition: TimerQueue.h:94
int expire(const TimeVal &tv_)
Traverse the queue, triggering all timers that are past argument timeval.
Definition: TimerQueue.cpp:89
void dump(void)
Dump Queue information to the log file.
Definition: TimerQueue.cpp:152
~TimerQueue()
Destructor.
Definition: TimerQueue.cpp:20
int remove(EventHandler *eh_)
Cancel all timers for the EventHandler eh_.
Definition: TimerQueue.cpp:31
bool isEmpty()
Is queue empty?
Definition: TimerQueue.h:110
TimerId insert(EventHandler *eh_, const TimeVal &tv_, const TimeVal &delta_, const std::string &name_)
Add timer (EventHandler object) to the queue to be dispatch at the time specified.
Definition: TimerQueue.cpp:138
TimerQueue()
Constructor.
Definition: TimerQueue.h:103
TimeVal & top(void)
Return expiration time of the top element in the queue.
Definition: TimerQueue.h:117
Definition: Acceptor.h:40
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
Definition: EventHandler.h:27