reSIProcate/rutil  9694
Classes | Public Member Functions | Protected Attributes
resip::GenericTimerQueue< T > Class Template Reference

#include <GenericTimerQueue.hxx>

List of all members.

Classes

class  TimerEntry

Public Member Functions

virtual ~GenericTimerQueue ()
 deletes the message associated with the timer as well.
virtual void process ()
virtual void processTimer (T *)=0
void add (T *event, unsigned long msOffset)
int size () const
bool empty () const
unsigned int msTillNextTimer ()

Protected Attributes

std::multiset< TimerEntry< T > > mTimers

Detailed Description

template<class T>
class resip::GenericTimerQueue< T >

Definition at line 12 of file GenericTimerQueue.hxx.


Constructor & Destructor Documentation

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

deletes the message associated with the timer as well.

Definition at line 41 of file GenericTimerQueue.hxx.

References resip::GenericTimerQueue< T >::mTimers.

      {
         for (typename std::multiset<TimerEntry<T> >::iterator i = mTimers.begin(); i !=  mTimers.end(); ++i)
         {
            delete i->mEvent;            
         }
      }

Member Function Documentation

template<class T >
void resip::GenericTimerQueue< T >::add ( T *  event,
unsigned long  msOffset 
) [inline]

Definition at line 86 of file GenericTimerQueue.hxx.

References resip::GenericTimerQueue< T >::mTimers.

          {
              TimerEntry<T> t(msOffset, event);
                  mTimers.insert(t);
          }
template<class T >
bool resip::GenericTimerQueue< T >::empty ( ) const [inline]

Definition at line 97 of file GenericTimerQueue.hxx.

References resip::GenericTimerQueue< T >::mTimers.

      {
         return mTimers.empty();
      }
template<class T >
unsigned int resip::GenericTimerQueue< T >::msTillNextTimer ( ) [inline]

Definition at line 102 of file GenericTimerQueue.hxx.

References resip::Timer::getTimeMs(), and resip::GenericTimerQueue< T >::mTimers.

Referenced by resip::GenericTimerQueue< T >::process().

      {
         if (!mTimers.empty())
         {
            UInt64 next = mTimers.begin()->mWhen;
            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;
         }
      }

Here is the call graph for this function:

template<class T >
virtual void resip::GenericTimerQueue< T >::process ( ) [inline, virtual]

dcm! -- erasing the range didn't work...upper bound was prob. end()

Definition at line 49 of file GenericTimerQueue.hxx.

References resip::GenericTimerQueue< T >::msTillNextTimer(), resip::GenericTimerQueue< T >::mTimers, and resip::GenericTimerQueue< T >::processTimer().

      {
         if (!mTimers.empty() && msTillNextTimer() == 0)
         {
            TimerEntry<T> now(0, 0);

            // hacky solution, needs work, insertion from processTimer
            // caused bizarre infinite loop issues in previous revision;
            // this code is in desperate need of help
            typedef typename std::multiset<TimerEntry<T> > TimerSet;
            typedef std::vector<typename TimerSet::iterator> ItVector;
            ItVector iterators;

            typename TimerSet::iterator end = mTimers.upper_bound(now);
            typename TimerSet::iterator begin = mTimers.begin();

            for (typename TimerSet::iterator i = begin; i != end; ++i)
            {
               iterators.push_back(i);
            }

            for (typename ItVector::iterator i = iterators.begin(); i != iterators.end(); ++i)
            {
               assert((*i)->getEvent());
               processTimer((*i)->getEvent());               
            }

            for (typename ItVector::iterator i = iterators.begin(); i != iterators.end(); ++i)
            {
               mTimers.erase(*i);
            }
         }
      }

Here is the call graph for this function:

template<class T >
virtual void resip::GenericTimerQueue< T >::processTimer ( T *  ) [pure virtual]
template<class T >
int resip::GenericTimerQueue< T >::size ( ) const [inline]

Definition at line 92 of file GenericTimerQueue.hxx.

References resip::GenericTimerQueue< T >::mTimers.

      {
         return mTimers.size();
      }

Member Data Documentation

template<class T >
std::multiset<TimerEntry<T> > resip::GenericTimerQueue< T >::mTimers [protected]

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