PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PAdaptiveDelay Class Reference

Class for implementing an "adaptive" delay. More...

#include <delaychan.h>

Inheritance diagram for PAdaptiveDelay:
Collaboration diagram for PAdaptiveDelay:

Public Member Functions

Construction
 PAdaptiveDelay (const PTimeInterval &maximumSlip=0, const PTimeInterval &minimumDelay=0)
 Create a new adaptive delay with the specified parameters. More...
 
Operating Parameters
void SetMaximumSlip (const PTimeInterval &maximumSlip)
 Set the number of milliseconds that the delay may "catch up" by using zero delays. More...
 
PTimeInterval GetMaximumSlip () const
 Get the current slip time. More...
 
const PTimeIntervalGetActualDelay () const
 Get the actual sleep time of the last call to the delay function. More...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Attributes

PTimeInterval m_maximumSlip
 
PTimeInterval m_minimumDelay
 
PTimeInterval m_actualDelay
 
PTime m_targetTime
 
bool m_firstTime
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Functionality

enum  DelayResult {
  eOnTime, eOverSlept, eLate, eSlipped,
  eBadDelta
}
 < Result of call to Delay() or DelayInterval() function call More...
 
DelayResult Delay (int deltaMS)
 Wait until the specified number of milliseconds have elapsed from the previous call (on average). More...
 
DelayResult DelayInterval (const PTimeInterval &delta)
 As for Delay() but for more accurate timing. More...
 
void Restart ()
 Invalidate the timer. More...
 

Additional Inherited Members

- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PObject
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Detailed Description

Class for implementing an "adaptive" delay.

This class will cause the the caller to, on average, delay the specified number of milliseconds between calls. This can be used to simulate hardware timing for a sofwtare only device

Member Enumeration Documentation

< Result of call to Delay() or DelayInterval() function call

Enumerator
eOnTime 

The function was called within the delta time of the expected time and a possible sleep was performed.

A sleep may be skipped if below m_minimumDelay, as very short sleeps are not performed very well by many operating systems.

eOverSlept 

The function was called in time, and a sleep was performed, but the operating system did not return control within two delta time intervals of the expected delay.

The next two calls to the delay function will not pause at all.

eLate 

The function was called greater than delta time intervals late, no sleep was made.

eSlipped 

The function was called more than the m_maximumSlip time late, the adaptation is reset, no sleep is performed.

eBadDelta 

The delta time interval was zero or negative.

Constructor & Destructor Documentation

PAdaptiveDelay::PAdaptiveDelay ( const PTimeInterval maximumSlip = 0,
const PTimeInterval minimumDelay = 0 
)

Create a new adaptive delay with the specified parameters.

The maximum slip time can also be set later using SetMaximumSlip.

Parameters
maximumSlipMaximum slip time in milliseconds
minimumDelayMinimum delay (usually OS time slice)

Member Function Documentation

DelayResult PAdaptiveDelay::Delay ( int  deltaMS)
inline

Wait until the specified number of milliseconds have elapsed from the previous call (on average).

The first time the function is called, no delay occurs. If the maximum slip time is set and the caller is "too late", the timer is restarted automatically and no delay occurs.

If the calculated delay is less than the OS timer resolution specified on costruction, no delay occurs now ("better sooner than later" strategy).

Returns
true if we are "too late" of time milliseconds (unrelated to the maximum slip time).

References DelayInterval().

DelayResult PAdaptiveDelay::DelayInterval ( const PTimeInterval delta)

As for Delay() but for more accurate timing.

Referenced by Delay().

const PTimeInterval& PAdaptiveDelay::GetActualDelay ( ) const
inline

Get the actual sleep time of the last call to the delay function.

References m_actualDelay.

PTimeInterval PAdaptiveDelay::GetMaximumSlip ( ) const
inline

Get the current slip time.

References m_maximumSlip.

void PAdaptiveDelay::Restart ( )

Invalidate the timer.

The timing of this function call is not important, the timer will restart at the next call to Delay().

void PAdaptiveDelay::SetMaximumSlip ( const PTimeInterval maximumSlip)
inline

Set the number of milliseconds that the delay may "catch up" by using zero delays.

This is caused by the Delay() function not being called for a time by external factors.

If maximumSlip is 0, this feature is disabled.

References m_maximumSlip.

Member Data Documentation

PTimeInterval PAdaptiveDelay::m_actualDelay
protected

Referenced by GetActualDelay().

bool PAdaptiveDelay::m_firstTime
protected
PTimeInterval PAdaptiveDelay::m_maximumSlip
protected

Referenced by GetMaximumSlip(), and SetMaximumSlip().

PTimeInterval PAdaptiveDelay::m_minimumDelay
protected
PTime PAdaptiveDelay::m_targetTime
protected

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