sipxmedialib  Version 3.3
MpMMTimerPosix.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2009 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2009 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // $$
10 
11 // Author: Sergey Kostanbaev <sergey DOT kostanbaev AT SIPez DOT com>
12 
13 #ifndef _MpMMTimerPosix_h_
14 #define _MpMMTimerPosix_h_
15 
16 // SYSTEM INCLUDES
17 #include <time.h>
18 #include <signal.h>
19 #include <semaphore.h>
20 #include <pthread.h>
21 
22 
23 // APPLICATION INCLUDES
24 #include <utl/UtlDefs.h>
25 #include "mp/MpMMTimer.h"
26 #include <os/OsMutex.h>
27 
28 #ifdef __APPLE__
29 #warning PosixTimer is not implimented in MacOS X
30 #define timer_t int
31 #endif
32 
41 class MpMMTimerPosix : public MpMMTimer
42 {
43 /* //////////////////////////////// PUBLIC //////////////////////////////// */
44 public:
45  class PosixSignalReg; // Forward declaration
46 
47  static const char * const TYPE;
48 
49 /* =============================== CREATORS =============================== */
51 
52 
54 
56 
58 
59 /* ============================= MANIPULATORS ============================= */
61 
62 
64  OsStatus setNotification(OsNotification* notification);
65 
67  OsStatus run(unsigned usecPeriodic);
68 
70  OsStatus stop();
71 
73  OsStatus waitForNextTick();
74 
76 
77 /* ============================== ACCESSORS =============================== */
79 
80 
82  OsStatus getResolution(unsigned& resolution);
83 
85  OsStatus getPeriodRange(unsigned* pMinUSecs, unsigned* pMaxUSecs = NULL);
86 
88  OsTime getAbsFireTime() const;
89 
91 
92 /* =============================== INQUIRY ================================ */
94 
95 
98 
100 
101 
104  {
105  public:
106  PosixSignalReg(int sigNum, void (*)(int, siginfo_t *, void *));
107  ~PosixSignalReg();
108 
110  int getSignalNum() const;
111 
112  int blockThreadSig();
113  int unblockThreadSig();
114 
115  private:
116  struct sigaction mOldAction;
117  int mSigNum;
118  sigset_t mBlockSigMask;
119  };
120 
122  static
123  void signalHandler(int signum, siginfo_t *siginfo, void *context);
124 
125 /* ////////////////////////////// PROTECTED /////////////////////////////// */
126 protected:
127  OsNotification* mpNotification;
128  UtlBoolean mbTimerStarted;
129  timer_t mTimer;
131 
132  void callback();
133 
134 
135 /* /////////////////////////////// PRIVATE //////////////////////////////// */
136 private:
138  pthread_t mThread;
139  sem_t mIoSem;
140  UtlBoolean mbTerminate;
141 
142  static void* threadIoWrapper(void* arg);
143 };
144 
145 /* ============================ INLINE METHODS ============================ */
146 #endif //_MpMMTimerPosix_h_
High-precision periodic timer (MultiMedia timer) base class.
Definition: MpMMTimer.h:44
static PosixSignalReg sPosixTimerReg
Definition: MpMMTimerPosix.h:137
MMTimerType
Definition: MpMMTimer.h:48
int getSignalNum() const
Get number of the signaling signal.
Definition: MpMMTimerPosix.cpp:323
~MpMMTimerPosix()
Definition: MpMMTimerPosix.cpp:81
OsTime getAbsFireTime() const
Definition: MpMMTimerPosix.cpp:216
void callback()
Definition: MpMMTimerPosix.cpp:227
UtlBoolean mbTimerStarted
Is timer started.
Definition: MpMMTimerPosix.h:128
OsStatus getPeriodRange(unsigned *pMinUSecs, unsigned *pMaxUSecs=NULL)
Get the range of timer periods that can be generated.
Definition: MpMMTimerPosix.cpp:166
OsStatus waitForNextTick()
Definition: MpMMTimerPosix.cpp:192
OsStatus setNotification(OsNotification *notification)
Set notification for the OsNotification timer type.
Definition: MpMMTimerPosix.cpp:221
Posix implementation of periodic timer.
Definition: MpMMTimerPosix.h:41
int blockThreadSig()
Definition: MpMMTimerPosix.cpp:328
static void signalHandler(int signum, siginfo_t *siginfo, void *context)
Signal callback.
Definition: MpMMTimerPosix.cpp:299
PosixSignalReg(int sigNum, void(*)(int, siginfo_t *, void *))
Definition: MpMMTimerPosix.cpp:312
static void * threadIoWrapper(void *arg)
Definition: MpMMTimerPosix.cpp:250
struct sigaction mOldAction
Old signal action.
Definition: MpMMTimerPosix.h:116
OsStatus getResolution(unsigned &resolution)
Get resolution of timer in microseconds.
Definition: MpMMTimerPosix.cpp:178
pthread_t mThread
Sync-signal wait thread.
Definition: MpMMTimerPosix.h:138
OsStatus stop()
Stop periodical firing.
Definition: MpMMTimerPosix.cpp:143
Help class for signal registering.
Definition: MpMMTimerPosix.h:103
~PosixSignalReg()
Definition: MpMMTimerPosix.cpp:338
timer_t mTimer
Timer object.
Definition: MpMMTimerPosix.h:129
OsNotification * mpNotification
Notification object used to signal a tick of the timer.
Definition: MpMMTimerPosix.h:127
int mSigNum
Signal number.
Definition: MpMMTimerPosix.h:117
MpMMTimerPosix(MpMMTimer::MMTimerType type)
Definition: MpMMTimerPosix.cpp:62
sem_t mSyncSemaphore
Synchronization semaphore for linear operation.
Definition: MpMMTimerPosix.h:130
static const char *const TYPE
Definition: MpMMTimerPosix.h:45
int unblockThreadSig()
Definition: MpMMTimerPosix.cpp:333
sem_t mIoSem
Startup initialization semaphore.
Definition: MpMMTimerPosix.h:139
sigset_t mBlockSigMask
Block mask for only this signal.
Definition: MpMMTimerPosix.h:118
UtlBoolean mbTerminate
Should the timer thread exit?
Definition: MpMMTimerPosix.h:140
static PosixSignalReg * getSignalDescriptor()
Returns signal descriptor for thread blocking/unblocking operations.
Definition: MpMMTimerPosix.cpp:307
OsStatus run(unsigned usecPeriodic)
Start periodical firing.
Definition: MpMMTimerPosix.cpp:98