libassa
3.5.1
assa
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
35
class
TimerQueue
36
{
37
public
:
39
TimerQueue
();
40
42
~TimerQueue
();
43
47
bool
isEmpty
();
48
61
TimerId
insert
(
EventHandler
* eh_,
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
:
94
PriorityQueue <Timer*, TimerCompare>
m_queue
;
95
};
96
97
//------------------------------------------------------------------------------
98
// Inline functions
99
//------------------------------------------------------------------------------
100
101
inline
102
TimerQueue::
103
TimerQueue
()
104
{
105
trace
(
"TimerQueue::TimerQueue"
);
106
}
107
108
inline
bool
109
TimerQueue::
110
isEmpty
()
111
{
112
return
m_queue
.size () == 0;
113
}
114
115
inline
TimeVal
&
116
TimerQueue::
117
top
(
void
)
118
{
119
return
(
TimeVal
&)
m_queue
.top ()->getExpirationTime ();
120
}
121
122
}
// end namespace ASSA
123
124
#endif
/* TIMER_QUEUE_H */
ASSA::TimerQueue::remove
int remove(EventHandler *eh_)
Cancel all timers for the EventHandler eh_.
Definition:
TimerQueue.cpp:31
ASSA::TimerQueue::insert
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
ASSA::TimerId
unsigned long TimerId
Definition:
EventHandler.h:27
ASSA::TimeVal
Definition:
TimeVal.h:30
ASSA::TimerQueue::dump
void dump(void)
Dump Queue information to the log file.
Definition:
TimerQueue.cpp:152
ASSA::TimerQueue::isEmpty
bool isEmpty()
Is queue empty?
Definition:
TimerQueue.h:110
Timer.h
Logger.h
ASSA::PriorityQueue
Definition:
PriorityQueue.h:34
trace
#define trace(s)
Definition:
Logger.h:429
ASSA::EventHandler
EventHandler class.
Definition:
EventHandler.h:102
PriorityQueue.h
EventHandler.h
ASSA::TimerQueue::top
TimeVal & top(void)
Return expiration time of the top element in the queue.
Definition:
TimerQueue.h:117
ASSA::TimerQueue::expire
int expire(const TimeVal &tv_)
Traverse the queue, triggering all timers that are past argument timeval.
Definition:
TimerQueue.cpp:89
ASSA::TimerQueue::m_queue
PriorityQueue< Timer *, TimerCompare > m_queue
Timer queue itself.
Definition:
TimerQueue.h:94
ASSA::TimerQueue::~TimerQueue
~TimerQueue()
Destructor.
Definition:
TimerQueue.cpp:20
ASSA::TimerQueue::TimerQueue
TimerQueue()
Constructor.
Definition:
TimerQueue.h:103
ASSA
Definition:
Acceptor.h:40
ASSA::TimerQueue
Definition:
TimerQueue.h:35
Generated by
1.8.17