libassa 3.5.1
Loading...
Searching...
No Matches
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
26namespace ASSA {
27
28typedef unsigned long TimerId;
29
36{
37public:
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
92private:
95};
96
97//------------------------------------------------------------------------------
98// Inline functions
99//------------------------------------------------------------------------------
100
101inline
103TimerQueue ()
104{
105 trace("TimerQueue::TimerQueue");
106}
107
108inline bool
110isEmpty ()
111{
112 return m_queue.size () == 0;
113}
114
115inline TimeVal&
117top (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.
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
EventHandler class.
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.
void dump(void)
Dump Queue information to the log file.
~TimerQueue()
Destructor.
int remove(EventHandler *eh_)
Cancel all timers for the EventHandler eh_.
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.
TimerQueue()
Constructor.
Definition TimerQueue.h:103
TimeVal & top(void)
Return expiration time of the top element in the queue.
Definition TimerQueue.h:117
unsigned long TimerId
Timer Id is used in handle_timeout() calls.