TimerQueue.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                          TimerQueue.h
00004 //------------------------------------------------------------------------------
00005 //  Copyright (c) 1999,2005 by Vladislav Grinchenko
00006 //
00007 //  This library is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU Library General Public
00009 //  License as published by the Free Software Foundation; either
00010 //  version 2 of the License, or (at your option) any later version.
00011 //------------------------------------------------------------------------------
00012 //  Created: 07/28/1999
00013 //------------------------------------------------------------------------------
00014 #ifndef TIMER_QUEUE_H
00015 #define TIMER_QUEUE_H
00016 
00017 #include <time.h>
00018 #include <sys/time.h>
00019 #include <unistd.h>
00020 
00021 #include "assa/Logger.h"
00022 #include "assa/EventHandler.h"
00023 #include "assa/Timer.h"
00024 #include "assa/PriorityQueue.h"
00025 
00026 namespace ASSA {
00027 
00028 typedef unsigned long TimerId;
00029 
00035 class TimerQueue
00036 {
00037 public:
00039     TimerQueue ();
00040 
00042     ~TimerQueue ();
00043 
00047     bool isEmpty ();
00048 
00060     TimerId insert (EventHandler* eh_, 
00061                     const TimeVal& tv_, 
00062                     const TimeVal& delta_,
00063                     const std::string& name_);
00064 
00069     int remove (EventHandler* eh_);
00070 
00075     bool remove (TimerId tid_);
00076 
00083     int expire (const TimeVal& tv_);
00084 
00086     TimeVal& top (void);
00087 
00089     void dump (void);
00090 
00091 private:
00093     PriorityQueue <Timer*, TimerCompare> m_queue;
00094 };
00095 
00096 //------------------------------------------------------------------------------
00097 // Inline functions
00098 //------------------------------------------------------------------------------
00099 
00100 inline
00101 TimerQueue::
00102 TimerQueue () 
00103 {
00104     trace("TimerQueue::TimerQueue");
00105 }
00106 
00107 inline bool
00108 TimerQueue::
00109 isEmpty ()
00110 { 
00111     return m_queue.size () == 0;
00112 }
00113 
00114 inline TimeVal&
00115 TimerQueue::
00116 top (void)
00117 {
00118     return (TimeVal&) m_queue.top ()->getExpirationTime ();
00119 }
00120 
00121 } // end namespace ASSA
00122 
00123 #endif /* TIMER_QUEUE_H */  

Generated on Mon Dec 19 16:37:15 2005 for libassa by  doxygen 1.4.5