Loading...
Searching...
No Matches
TimerQueue.h
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// TimerQueue.h
//------------------------------------------------------------------------------
// Copyright (c) 1999,2005 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
// Created: 07/28/1999
//------------------------------------------------------------------------------
#ifndef TIMER_QUEUE_H
#define TIMER_QUEUE_H
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include "assa/Logger.h"
#include "assa/EventHandler.h"
#include "assa/Timer.h"
#include "assa/PriorityQueue.h"
namespace ASSA {
typedef unsigned long TimerId;
class TimerQueue
{
public:
TimerQueue ();
~TimerQueue ();
bool isEmpty ();
TimerId insert (EventHandler* eh_,
const TimeVal& tv_,
const TimeVal& delta_,
const std::string& name_);
int remove (EventHandler* eh_);
bool remove (TimerId tid_);
int expire (const TimeVal& tv_);
TimeVal& top (void);
void dump (void);
private:
PriorityQueue <Timer*, TimerCompare> m_queue;
};
//------------------------------------------------------------------------------
// Inline functions
//------------------------------------------------------------------------------
inline
TimerQueue::
TimerQueue ()
{
trace("TimerQueue::TimerQueue");
}
inline bool
TimerQueue::
isEmpty ()
{
return m_queue.size () == 0;
}
inline TimeVal&
TimerQueue::
top (void)
{
return (TimeVal&) m_queue.top ()->getExpirationTime ();
}
} // end namespace ASSA
#endif /* TIMER_QUEUE_H */
EventHandler.h
An abstract interface for handling I/O events, timers, and such.
Logger.h
An abstraction to message logging facility.
trace
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429
PriorityQueue.h
Priority Queue class that allows removal of arbitrariy element from the queue.
Timer.h
Timer class represents tuple that is stored in TimerQueue.
ASSA::EventHandler
EventHandler class.
Definition EventHandler.h:103
ASSA::TimeVal
Definition TimeVal.h:31
ASSA::TimerQueue::m_queue
PriorityQueue< Timer *, TimerCompare > m_queue
Timer queue itself.
Definition TimerQueue.h:94
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::dump
void dump(void)
Dump Queue information to the log file.
Definition TimerQueue.cpp:152
ASSA::TimerQueue::~TimerQueue
~TimerQueue()
Destructor.
Definition TimerQueue.cpp:20
ASSA::TimerQueue::remove
int remove(EventHandler *eh_)
Cancel all timers for the EventHandler eh_.
Definition TimerQueue.cpp:31
ASSA::TimerQueue::isEmpty
bool isEmpty()
Is queue empty?
Definition TimerQueue.h:110
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::TimerQueue::TimerQueue
TimerQueue()
Constructor.
Definition TimerQueue.h:103
ASSA::TimerQueue::top
TimeVal & top(void)
Return expiration time of the top element in the queue.
Definition TimerQueue.h:117
ASSA
Definition Acceptor.h:40
ASSA::TimerId
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
Definition EventHandler.h:27