RTP Audio System
2.0.0
|
#include <multitimerthread.h>
Classes | |
struct | TimerParameters |
Public Member Functions | |
MultiTimerThread (const char *name="MultiTimerThread", const cardinal flags=TF_CancelDeferred) | |
~MultiTimerThread () | |
card64 | getInterval (const cardinal timer) |
void | setInterval (const cardinal timer, const card64 usec, const card64 callLimit=0) |
void | setNextAction (const cardinal timer, const card64 usec=0, const card64 callLimit=1) |
void | setNextActionAbs (const cardinal timer, const card64 timeStamp=0, const card64 callLimit=1) |
cardinal | getTimerCorrection (const cardinal timer) |
void | setTimerCorrection (const cardinal timer, const cardinal maxCorrection=0) |
void | leaveCorrectionLoop (const cardinal timer) |
void | setFastStart (const cardinal timer, const bool on) |
bool | getFastStart (const cardinal timer) const |
void | cancel () |
void * | stop () |
Protected Member Functions | |
virtual void | timerEvent (const cardinal timer)=0 |
Private Member Functions | |
void | run () |
bool | isShuttingDown () |
Private Attributes | |
TimerParameters | Parameters [Timers] |
bool | ParametersUpdated |
bool | Shutdown |
bool | LeaveCorrectionLoop [Timers] |
Static Private Attributes | |
static const card64 | UpdateResolution = 100000 |
Multi Timer Thread.
This abstract class realizes a timer thread with multiple timers, based on Thread. The user of this class has to implement timerEvent(). Inaccurate system timers are corrected by calling user's timerEvent() implementation multiple times if necessary. This feature can be modified by setTimerCorrection (Default is on at a maximum of 10 calls).
MultiTimerThread< Timers >::MultiTimerThread | ( | const char * | name = "MultiTimerThread< Timers >" , |
const cardinal | flags = TF_CancelDeferred |
||
) |
Constructor. A new multitimer thread with a given interval will be created but *not* started! To start the new thread, call start(). The interval gives the time for the interval in microseconds, the virtual function timerEvent() is called. The default timer correction is set to 10. See setTimerCorrection() for more information on timer correction. The first call of timerEvent() will be made immediately, if the fast start option is set (default). Otherwise it will be made after the given interval.
MultiTimerThread< Timers >::~MultiTimerThread | ( | ) |
Destructor.
void MultiTimerThread< Timers >::cancel | ( | ) | [virtual] |
bool MultiTimerThread< Timers >::getFastStart | ( | const cardinal | timer | ) | const [inline] |
Get fast start option: If false, the first call of timerEvent() will be made *after* the given interval; otherwise it will be made immediately.
timer | Timer number. |
card64 MultiTimerThread< Timers >::getInterval | ( | const cardinal | timer | ) | [inline] |
Get timer interval.
timer | Timer number. |
cardinal MultiTimerThread< Timers >::getTimerCorrection | ( | const cardinal | timer | ) | [inline] |
Get maximum correction value for inaccurate system timer.
timer | Timer number. |
bool MultiTimerThread< Timers >::isShuttingDown | ( | ) | [inline, private] |
void MultiTimerThread< Timers >::leaveCorrectionLoop | ( | const cardinal | timer | ) | [inline] |
Leave timer correction loop: If the thread is in a timer correction loop, the loop will be finished after the current timerEvent() call returns.
timer | Timer number. |
void MultiTimerThread< Timers >::run | ( | ) | [private, virtual] |
void MultiTimerThread< Timers >::setFastStart | ( | const cardinal | timer, |
const bool | on | ||
) | [inline] |
Set fast start option: If false, the first call of timerEvent() will be made *after* the given interval; otherwise it will be made immediately. The default is true.
timer | Timer number. |
on | true, to set option; false otherwise. |
void MultiTimerThread< Timers >::setInterval | ( | const cardinal | timer, |
const card64 | usec, | ||
const card64 | callLimit = 0 |
||
) | [inline] |
Set timer interval. Note, that the first timerEvent() call will be immediately, is FastStart mode is set, see also setFastStart(). For single shot timers, you probably have to call setFastStart(nr,0) first!
timer | Timer number. |
usec | Interval in microseconds (0 to deactivate timer). |
callLimit | Call count limit (0 for infinite). |
void MultiTimerThread< Timers >::setNextAction | ( | const cardinal | timer, |
const card64 | usec = 0 , |
||
const card64 | callLimit = 1 |
||
) | [inline] |
Like setInterval(), but disabling FastStart first. This method can be used e.g. for single shot timers.
timer | Timer number. |
usec | Time to next invokation (0 = immediately). |
callLimit | Call count limit (0 for infinite, default: 1). |
void MultiTimerThread< Timers >::setNextActionAbs | ( | const cardinal | timer, |
const card64 | timeStamp = 0 , |
||
const card64 | callLimit = 1 |
||
) | [inline] |
Like setNextAction(), but the time stamp of the next invokation is given as absolute time (microseconds since January 01, 1970).
timer | Timer number. |
usec | Time to next invokation (0 = immediately). |
callLimit | Call count limit (0 for infinite, default: 1). |
void MultiTimerThread< Timers >::setTimerCorrection | ( | const cardinal | timer, |
const cardinal | maxCorrection = 0 |
||
) | [inline] |
Set correction of inaccurate system timer to given value. This on will cause the timerEvent() function to be called a maximum of maxCorrection times, if the total number of calls is lower than the calculated number of times the function should have been called. If the number of correction calls is higher than maxCorrection, *no* correction will be done! Default is 0, which turns correction off.
timer | Timer number. |
of | true to activate correction; false to deactivate. |
void* MultiTimerThread< Timers >::stop | ( | ) | [virtual] |
Reimplementation of Thread's stop() method.
Reimplemented from Thread.
Reimplemented in AbstractMediaServer, and RTCPAbstractServer.
virtual void MultiTimerThread< Timers >::timerEvent | ( | const cardinal | timer | ) | [protected, pure virtual] |
The virtual timerEvent() method, which contains the multitimer thread's implementation. It has to be implemented by classes, which inherit MultiTimerThread. This method is called regularly with the given interval.
Implemented in TimedThread.
bool MultiTimerThread< Timers >::LeaveCorrectionLoop[Timers] [private] |
TimerParameters MultiTimerThread< Timers >::Parameters[Timers] [private] |
bool MultiTimerThread< Timers >::ParametersUpdated [private] |
bool MultiTimerThread< Timers >::Shutdown [private] |
const card64 MultiTimerThread< Timers >::UpdateResolution = 100000 [static, private] |