sipxmedialib  Version 3.3
Classes | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MpMMTimerPosix Class Reference

Posix implementation of periodic timer. More...

#include <MpMMTimerPosix.h>

Inheritance diagram for MpMMTimerPosix:
Inheritance graph
[legend]
Collaboration diagram for MpMMTimerPosix:
Collaboration graph
[legend]

Classes

class  PosixSignalReg
 Help class for signal registering. More...
 

Public Member Functions

Creators
 MpMMTimerPosix (MpMMTimer::MMTimerType type)
 
 ~MpMMTimerPosix ()
 
Manipulators
OsStatus setNotification (OsNotification *notification)
 Set notification for the OsNotification timer type. More...
 
OsStatus run (unsigned usecPeriodic)
 Start periodical firing. More...
 
OsStatus stop ()
 Stop periodical firing. More...
 
OsStatus waitForNextTick ()
 
Accessors
OsStatus getResolution (unsigned &resolution)
 Get resolution of timer in microseconds. More...
 
OsStatus getPeriodRange (unsigned *pMinUSecs, unsigned *pMaxUSecs=NULL)
 Get the range of timer periods that can be generated. More...
 
OsTime getAbsFireTime () const
 
- Public Member Functions inherited from MpMMTimer
MMTimerType getTimerType () const
 Get the type of timer fire. More...
 
virtual ~MpMMTimer ()
 Destructor. More...
 

Static Public Member Functions

static void signalHandler (int signum, siginfo_t *siginfo, void *context)
 Signal callback. More...
 
Inquiry
static PosixSignalReggetSignalDescriptor ()
 Returns signal descriptor for thread blocking/unblocking operations. More...
 
- Static Public Member Functions inherited from MpMMTimer
static MpMMTimercreate (MMTimerType type, const UtlString &name="")
 Factory method to create timer class instance of the given type. More...
 

Static Public Attributes

static const char *const TYPE = "POSIX Timer"
 

Protected Member Functions

void callback ()
 
- Protected Member Functions inherited from MpMMTimer
 MpMMTimer (MMTimerType type)
 protected constructor, as this is an abstract class. More...
 

Protected Attributes

OsNotification * mpNotification
 Notification object used to signal a tick of the timer. More...
 
UtlBoolean mbTimerStarted
 Is timer started. More...
 
timer_t mTimer
 Timer object. More...
 
sem_t mSyncSemaphore
 Synchronization semaphore for linear operation. More...
 
- Protected Attributes inherited from MpMMTimer
MMTimerType mTimerType
 

Static Private Member Functions

static void * threadIoWrapper (void *arg)
 

Private Attributes

pthread_t mThread
 Sync-signal wait thread. More...
 
sem_t mIoSem
 Startup initialization semaphore. More...
 
UtlBoolean mbTerminate
 Should the timer thread exit? More...
 

Static Private Attributes

static PosixSignalReg sPosixTimerReg
 

Additional Inherited Members

- Public Types inherited from MpMMTimer
enum  MMTimerType { Linear = 0, Notification = 1 }
 

Detailed Description

Posix implementation of periodic timer.

WARNING: You MUST be sure that exists only one object of this class. To support several MpMMTimer objects we need to circumvent sync sigwait() peculiarities, which will complicate the code a lot and is not necessary right now.

Constructor & Destructor Documentation

Member Function Documentation

OsStatus setNotification ( OsNotification *  notification)
virtual

Set notification for the OsNotification timer type.

Signals will be sent to this notification when the timer ticks. Pointer to this timer instance will be set in eventData member.

Parameters
[in]notification- object to notify when timer fires/ticks.
Return values
OS_SUCCESSReturned when notification is set.
OS_INVALID_STATEReturned when calling this function for non-Notification timer type.
OS_FAILEDReturned when mandatory initialization failed (maybe in the constructor) and later calls will fail for this instance also.

Reimplemented from MpMMTimer.

OsStatus run ( unsigned  usecPeriodic)
virtual

Start periodical firing.

Start periodical firing with given period and fire type.

Parameters
[in]usecPeriodictimer period in microseconds.
Return values
OS_SUCCESSReturns when timer has been created and ran.
OS_INVALID_ARGUMENTReturns when either value of uAlgorithm doesn't support in current realization or running OS couldn't create timer with specified usecPeriodic, but with another value of it, it could.
OS_INVALID_STATEReturns when timer has already been started or if the timer type is not supported.
OS_LIMIT_REACHEDReturns when timer couldn't run due the resource limitation.
OS_FAILEDReturns when mandatories initializations failed (maybe in constructor) and later calls will also fail for this instance.

Implements MpMMTimer.

OsStatus stop ( void  )
virtual

Stop periodical firing.

Stop periodical timer.

Return values
OS_SUCCESSReturns when timer has been stopped.
OS_FAILEDReturns when mandatory initialization failed (maybe in constructor) and later calls for this instance will fail.
OS_INVALID_STATEReturns when timer has not been started.

Implements MpMMTimer.

OsStatus waitForNextTick ( )
virtual

Block this thread until the next tick occurs

Return values
OS_SUCCESSReturns when next tick period occurs.
OS_INVALID_STATEReturns when calling this function for non-Linear timer type.
OS_FAILEDReturns when mandatory initialization failed (maybe in constructor) and later calls for this instance will fail too.

Reimplemented from MpMMTimer.

OsStatus getResolution ( unsigned &  resolution)
virtual

Get resolution of timer in microseconds.

Parameters
[out]resolution- set to the finest resolution timer we can generate.
Return values
OS_SUCCESS- the resolution was able to be retrieved.
OS_FAILED- the resolution wasn't able to be retrieved.

Reimplemented from MpMMTimer.

OsStatus getPeriodRange ( unsigned *  pMinUSecs,
unsigned *  pMaxUSecs = NULL 
)
virtual

Get the range of timer periods that can be generated.

Parameters
[out]pMinUSecs- set to the smallest period we can generate.
[out]pMaxUSecs- set to the largest period we can generate.
Return values
OS_SUCCESS- the min and max periods were able to be retrieved.
OS_FAILED- the min and max periods weren't able to be retrieved.

Reimplemented from MpMMTimer.

OsTime getAbsFireTime ( ) const

MpMMTimerPosix::PosixSignalReg * getSignalDescriptor ( )
static

Returns signal descriptor for thread blocking/unblocking operations.

void signalHandler ( int  signum,
siginfo_t *  siginfo,
void *  context 
)
static

Signal callback.

void callback ( )
protected
void * threadIoWrapper ( void *  arg)
staticprivate

Member Data Documentation

const char *const TYPE = "POSIX Timer"
static
OsNotification* mpNotification
protected

Notification object used to signal a tick of the timer.

UtlBoolean mbTimerStarted
protected

Is timer started.

timer_t mTimer
protected

Timer object.

sem_t mSyncSemaphore
protected

Synchronization semaphore for linear operation.

PosixSignalReg sPosixTimerReg
staticprivate
pthread_t mThread
private

Sync-signal wait thread.

sem_t mIoSem
private

Startup initialization semaphore.

UtlBoolean mbTerminate
private

Should the timer thread exit?