reSIProcate/stack  9694
Public Member Functions | Protected Types | Protected Attributes
resip::TimerQueue< T > Class Template Reference

This class takes a fifo as a place to where you can write your stuff. When using this in the main loop, call process() on this. During Transaction processing, TimerMessages and SIP messages are generated. More...

#include <TimerQueue.hxx>

Inheritance diagram for resip::TimerQueue< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual void processTimer (const T &timer)=0
virtual ~TimerQueue ()
 deletes the message associated with the timer as well.
unsigned int msTillNextTimer ()
 provides the time in milliseconds before the next timer will fire
virtual UInt64 process ()
 gets the set of timers that have fired, and inserts TimerMsg into the state machine fifo and application messages into the TU fifo
int size () const
bool empty () const
std::ostream & encode (std::ostream &str) const
EncodeStreamencode (EncodeStream &str) const

Protected Types

typedef std::vector< T,
std::allocator< T > > 
TimerVector

Protected Attributes

std::priority_queue< T,
TimerVector, std::greater< T > > 
mTimers

Detailed Description

template<class T>
class resip::TimerQueue< T >

This class takes a fifo as a place to where you can write your stuff. When using this in the main loop, call process() on this. During Transaction processing, TimerMessages and SIP messages are generated.

Todo:

!dcm! - refactor, templatize

.dlb. timer wheel for transaction-bound timers and a heap for everything longer.

Definition at line 39 of file TimerQueue.hxx.


Member Typedef Documentation

template<class T>
typedef std::vector<T, std::allocator<T> > resip::TimerQueue< T >::TimerVector [protected]

Definition at line 154 of file TimerQueue.hxx.


Constructor & Destructor Documentation

template<class T>
virtual resip::TimerQueue< T >::~TimerQueue ( ) [inline, virtual]

deletes the message associated with the timer as well.

Definition at line 49 of file TimerQueue.hxx.

      {
         //xkd-2004-11-4
         // delete the message associated with the timer
         while (!mTimers.empty())
         {
            mTimers.pop();
         }
      }

Member Function Documentation

template<class T>
bool resip::TimerQueue< T >::empty ( ) const [inline]

Definition at line 119 of file TimerQueue.hxx.

      {
         return mTimers.empty();
      }
template<class T>
std::ostream& resip::TimerQueue< T >::encode ( std::ostream &  str) const [inline]

Definition at line 125 of file TimerQueue.hxx.

      {
         if(mTimers.size() > 0)
         {
            return str << "TimerQueue[ size =" << mTimers.size() 
                       << " top=" << mTimers.top() << "]" ;
         }
         else
         {
            return str << "TimerQueue[ size = 0 ]";
         }
      }
template<class T>
EncodeStream& resip::TimerQueue< T >::encode ( EncodeStream str) const [inline]

Definition at line 139 of file TimerQueue.hxx.

      {
         if(mTimers.size() > 0)
         {
            return str << "TimerQueue[ size =" << mTimers.size() 
                       << " top=" << mTimers.top() << "]" ;
         }
         else
         {
            return str << "TimerQueue[ size = 0 ]";
         }
      }
template<class T>
unsigned int resip::TimerQueue< T >::msTillNextTimer ( ) [inline]

provides the time in milliseconds before the next timer will fire

Return values:
millisecondstime until the next timer will fire
0implies that timers occur in the past
INT_MAXimplies that there are no timers

Definition at line 64 of file TimerQueue.hxx.

Referenced by resip::TransactionController::getTimeTillNextProcessMS(), resip::SipStack::getTimeTillNextProcessMS(), main(), and resip::TransactionController::process().

      {
         if (!mTimers.empty())
         {
            UInt64 next = mTimers.top().getWhen();
            UInt64 now = Timer::getTimeMs();
            if (now > next) 
            {
               return 0;
            }
            else
            {
               UInt64 ret64 = next - now;
               if ( ret64 > UInt64(INT_MAX) )
               {
                  return INT_MAX;
               }
               else
               { 
                  int ret = int(ret64);
                  return ret;
               }
            }
         }
         else
         {
            return INT_MAX;
         }
      }
template<class T>
virtual UInt64 resip::TimerQueue< T >::process ( ) [inline, virtual]

gets the set of timers that have fired, and inserts TimerMsg into the state machine fifo and application messages into the TU fifo

Definition at line 96 of file TimerQueue.hxx.

Referenced by main(), resip::TransactionController::process(), and resip::SipStack::processTimers().

      {
         if (!mTimers.empty())
         {
            UInt64 now=Timer::getTimeMs();
            while (!mTimers.empty() && !(mTimers.top().getWhen() > now))
            {
               processTimer(mTimers.top());
               mTimers.pop();
            }

            if(!mTimers.empty())
            {
               return mTimers.top().getWhen();
            }
         }
         return 0;
      }
template<class T>
virtual void resip::TimerQueue< T >::processTimer ( const T &  timer) [pure virtual]
template<class T>
int resip::TimerQueue< T >::size ( ) const [inline]

Definition at line 115 of file TimerQueue.hxx.

Referenced by resip::SipStack::dump(), and resip::TransactionController::getTimerQueueSize().

      {
         return (int)mTimers.size();
      }

Member Data Documentation

template<class T>
std::priority_queue<T, TimerVector, std::greater<T> > resip::TimerQueue< T >::mTimers [protected]

The documentation for this class was generated from the following file: