reSIProcate/rutil  9694
Public Types | Public Member Functions | Private Member Functions | Private Attributes
resip::TimeLimitFifo< Msg > Class Template Reference

#include <TimeLimitFifo.hxx>

Inheritance diagram for resip::TimeLimitFifo< Msg >:
Inheritance graph
[legend]
Collaboration diagram for resip::TimeLimitFifo< Msg >:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DepthUsage { EnforceTimeDepth, IgnoreTimeDepth, InternalElement }

Public Member Functions

 TimeLimitFifo (unsigned int maxDurationSecs, unsigned int maxSize)
 After it runs out of the lesser of these limits it will start to refuse messages.
virtual ~TimeLimitFifo ()
bool add (Msg *msg, DepthUsage usage)
 Add a message to the fifo.
Msg * getNext ()
 Returns the first message available.
Msg * getNext (int ms)
 Returns the first message available within a time limit.
virtual time_t timeDepth () const
 Return the time depth of the queue.
bool wouldAccept (DepthUsage usage) const
 would an add called now work?
void clear ()
 removes all items from the FIFO
virtual size_t getCountDepth () const
 gets the depth of the FIFO
virtual time_t getTimeDepth () const
 Return the time depth of the queue.
virtual size_t getCountDepthTolerance () const
 returns the FIFO count depth tolerance
virtual time_t getTimeDepthTolerance () const
 returns the FIFO time depth tolerance
virtual void setCountDepthTolerance (unsigned int max)
 set the count depth tolerance of the FIFO
virtual void setTimeDepthTolerance (unsigned int maxSecs)
 set the time depth tolerance of the FIFO

Private Member Functions

time_t timeDepthInternal () const
bool wouldAcceptInteral (DepthUsage usage) const
 TimeLimitFifo (const TimeLimitFifo &rhs)
TimeLimitFifooperator= (const TimeLimitFifo &rhs)

Private Attributes

time_t mMaxDurationSecs
unsigned int mMaxSize
unsigned int mUnreservedMaxSize

Detailed Description

template<class Msg>
class resip::TimeLimitFifo< Msg >

Definition at line 91 of file TimeLimitFifo.hxx.


Member Enumeration Documentation

template<class Msg>
enum resip::TimeLimitFifo::DepthUsage
Enumerator:
EnforceTimeDepth 
IgnoreTimeDepth 
InternalElement 

Definition at line 94 of file TimeLimitFifo.hxx.


Constructor & Destructor Documentation

template<class Msg >
resip::TimeLimitFifo< Msg >::TimeLimitFifo ( unsigned int  maxDurationSecs,
unsigned int  maxSize 
)

After it runs out of the lesser of these limits it will start to refuse messages.

Definition at line 221 of file TimeLimitFifo.hxx.

   : AbstractFifo< Timestamped<Msg*> >(),
     mMaxDurationSecs(maxDurationSecs),
     mMaxSize(maxSize),
     mUnreservedMaxSize((int)((maxSize*8)/10)) // !dlb! random guess
{}
template<class Msg >
resip::TimeLimitFifo< Msg >::~TimeLimitFifo ( ) [virtual]

Definition at line 230 of file TimeLimitFifo.hxx.

{
   clear();
   assert(empty());
}
template<class Msg>
resip::TimeLimitFifo< Msg >::TimeLimitFifo ( const TimeLimitFifo< Msg > &  rhs) [private]

Member Function Documentation

template<class Msg>
bool resip::TimeLimitFifo< Msg >::add ( Msg *  msg,
DepthUsage  usage 
)

Add a message to the fifo.

return true iff succeeds

Parameters:
Msg*'Message pointer'
DepthUsage: (Needs work...) EnforceTimeDepth -- external (non ACK) requests IgnoreTimeDepth -- external reponse and ACK InternalElement -- internal messages (timers, application postbacks..); use reserved queue space +------------------------------------------------------+ | | | | +------------------------------------------------------+ <-----enforce-------------------> <---------------ignoreTimeDepth------------> <--------------------- internalElement---------------->

enforce will drop things that exceed the queue ignore will go past that limit to the extent of the queue (eg. internal will basically not drop anything

Definition at line 238 of file TimeLimitFifo.hxx.

Referenced by main(), and Producer::thread().

{
   Lock lock(mMutex); (void)lock;

   if (wouldAcceptInteral(usage))
   {
      time_t n = time(0);
      mFifo.push_back(Timestamped<Msg*>(msg, n));
      onMessagePushed(1);
      mCondition.signal();
      return true;
   }
   else
   {
      return false;
   }
}
template<class Msg >
void resip::TimeLimitFifo< Msg >::clear ( void  ) [virtual]

removes all items from the FIFO

Reimplemented from resip::AbstractFifo< Timestamped< Msg * > >.

Definition at line 346 of file TimeLimitFifo.hxx.

{
   Lock lock(mMutex); (void)lock;

   while (!mFifo.empty())
   {
      delete mFifo.front().getMsg();
      mFifo.pop_front();
   }
}
template<class Msg >
size_t resip::TimeLimitFifo< Msg >::getCountDepth ( ) const [virtual]

gets the depth of the FIFO

Returns:
the depth of the FIFO

Reimplemented from resip::AbstractFifo< Timestamped< Msg * > >.

Definition at line 359 of file TimeLimitFifo.hxx.

{
   return size();
}
template<class Msg >
size_t resip::TimeLimitFifo< Msg >::getCountDepthTolerance ( ) const [virtual]

returns the FIFO count depth tolerance

Returns:
the FIFO count depth tolerance

Definition at line 366 of file TimeLimitFifo.hxx.

{
   return mUnreservedMaxSize;
}
template<class Msg >
Msg * resip::TimeLimitFifo< Msg >::getNext ( )

Returns the first message available.

Note:
It will wait if no messages are available. If a signal interrupts the wait, it will retry the wait. Signals can therefore not be caught via getNext. If you need to detect a signal, use block prior to calling getNext.
Returns:
the next message in the queue

Reimplemented from resip::AbstractFifo< Timestamped< Msg * > >.

Definition at line 268 of file TimeLimitFifo.hxx.

References resip::Timestamped< Payload >::getMsg().

Referenced by main(), and Consumer::thread().

{
   Timestamped<Msg*> tm(AbstractFifo< Timestamped<Msg*> >::getNext());
   return tm.getMsg();
}

Here is the call graph for this function:

template<class Msg >
Msg * resip::TimeLimitFifo< Msg >::getNext ( int  ms)

Returns the first message available within a time limit.

Parameters:
msthe maximum amount of time to wait in milliseconds for a message
Note:
It will wait if no messages are available. If a signal interrupts the wait, it will retry the wait. Signals can therefore not be caught via getNext. If you need to detect a signal, use block prior to calling getNext.
Returns:
the next message in the queue, or NULL if the time limit elapses

Definition at line 276 of file TimeLimitFifo.hxx.

References resip::Timestamped< Payload >::getMsg().

{
   Timestamped<Msg*> tm(0,0);
   if(AbstractFifo< Timestamped<Msg*> >::getNext(ms, tm))
   {
      return tm.getMsg();
   }
   return 0;
}

Here is the call graph for this function:

template<class Msg >
time_t resip::TimeLimitFifo< Msg >::getTimeDepth ( ) const [virtual]

Return the time depth of the queue.

Returns:
the time delta between the youngest and oldest queue members
Note:
equivalent to timeDepth()

Reimplemented from resip::AbstractFifo< Timestamped< Msg * > >.

Definition at line 373 of file TimeLimitFifo.hxx.

{
   return timeDepth();
}
template<class Msg >
time_t resip::TimeLimitFifo< Msg >::getTimeDepthTolerance ( ) const [virtual]

returns the FIFO time depth tolerance

Returns:
the FIFO time depth tolerance

Definition at line 380 of file TimeLimitFifo.hxx.

{
   return mMaxDurationSecs;
}
template<class Msg>
TimeLimitFifo& resip::TimeLimitFifo< Msg >::operator= ( const TimeLimitFifo< Msg > &  rhs) [private]
template<class Msg >
void resip::TimeLimitFifo< Msg >::setCountDepthTolerance ( unsigned int  max) [virtual]

set the count depth tolerance of the FIFO

Todo:
getCountDepthTolerance returns a size_t and this takes an unsigned int, f.setCountDepthTolerance(f.getCountDepthTolerance()) will fail to compile on many systems [!]
Parameters:
maxthe new count depth tolerance of the FIFO

Definition at line 387 of file TimeLimitFifo.hxx.

{
   Lock lock(mMutex); (void)lock;
   mUnreservedMaxSize=int(maxCount * 0.8);
}
template<class Msg >
void resip::TimeLimitFifo< Msg >::setTimeDepthTolerance ( unsigned int  maxSecs) [virtual]

set the time depth tolerance of the FIFO

Parameters:
maxSecthe maximum time depth tolerance
Todo:
examine parallelism in units [!]

Definition at line 395 of file TimeLimitFifo.hxx.

{
   Lock lock(mMutex); (void)lock;

   mMaxDurationSecs=maxSecs;
}
template<class Msg >
time_t resip::TimeLimitFifo< Msg >::timeDepth ( ) const [virtual]

Return the time depth of the queue.

Returns:
the time delta between the youngest and oldest queue members

Definition at line 338 of file TimeLimitFifo.hxx.

Referenced by main().

{
   Lock lock(mMutex); (void)lock;
   return timeDepthInternal();
}
template<class Msg >
time_t resip::TimeLimitFifo< Msg >::timeDepthInternal ( ) const [private]

Definition at line 288 of file TimeLimitFifo.hxx.

{
   if(mFifo.empty())
   {
      return 0;
   }

   return time(0) - mFifo.front().getTime();
}
template<class Msg >
bool resip::TimeLimitFifo< Msg >::wouldAccept ( DepthUsage  usage) const

would an add called now work?

Parameters:
usagewhat depth policy should be used to determine if the call would work
Returns:
true if an add called now would work
See also:
DepthUsage

Definition at line 259 of file TimeLimitFifo.hxx.

Referenced by Producer::thread().

{
   Lock lock(mMutex); (void)lock;

   return wouldAcceptInteral(usage);
}
template<class Msg >
bool resip::TimeLimitFifo< Msg >::wouldAcceptInteral ( DepthUsage  usage) const [inline, private]

Definition at line 300 of file TimeLimitFifo.hxx.

{
   if ((mMaxSize != 0 &&
        mFifo.size() >= mMaxSize))
   {
      return false;
   }

   if (usage == InternalElement)
   {
      return true;
   }

   if (mUnreservedMaxSize != 0 &&
       mFifo.size() >= mUnreservedMaxSize)
   {
      return false;
   }

   if (usage == IgnoreTimeDepth)
   {
      return true;
   }

   assert(usage == EnforceTimeDepth);

   if (mFifo.size() == 0 ||
       mMaxDurationSecs == 0 ||
       timeDepthInternal() < mMaxDurationSecs)
   {
      return true;
   }

   return false;
}

Member Data Documentation

template<class Msg>
time_t resip::TimeLimitFifo< Msg >::mMaxDurationSecs [private]

Definition at line 215 of file TimeLimitFifo.hxx.

template<class Msg>
unsigned int resip::TimeLimitFifo< Msg >::mMaxSize [private]

Definition at line 216 of file TimeLimitFifo.hxx.

template<class Msg>
unsigned int resip::TimeLimitFifo< Msg >::mUnreservedMaxSize [private]

Definition at line 217 of file TimeLimitFifo.hxx.


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