sipXcallLib home page


PsHookswTask.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2006 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 #ifndef _PsHookswTask_h_
15 #define _PsHookswTask_h_
16 
17 // SYSTEM INCLUDES
18 
19 // APPLICATION INCLUDES
20 #include "os/OsMsgQ.h"
21 #include "os/OsRWMutex.h"
22 #include "os/OsServerTask.h"
23 #include "os/OsTime.h"
24 #include "ps/PsMsg.h"
25 #include "ps/PsHookswDev.h"
26 
27 // DEFINES
28 // MACROS
29 // EXTERNAL FUNCTIONS
30 // EXTERNAL VARIABLES
31 // CONSTANTS
32 // STRUCTS
33 // TYPEDEFS
34 
35 // FORWARD DECLARATIONS
36 class OsEventMsg;
37 class OsQueuedEvent;
38 class OsTimer;
39 
40 //:Task responsible for managing the phone hookswitch
41 class PsHookswTask : public OsServerTask
42 {
43 /* //////////////////////////// PUBLIC //////////////////////////////////// */
44 public:
45 
47  {
48  ON_HOOK, // The handset is on hook
49  OFF_HOOK // The handset is off hook
50  };
51 
52 /* ============================ CREATORS ================================== */
53 
54  static PsHookswTask* getHookswTask(void);
55  //:Return a pointer to the Hooksw task, creating it if necessary
56 
57  virtual
58  ~PsHookswTask();
59  //:Destructor
60 
61 /* ============================ MANIPULATORS ============================== */
62 
63  virtual OsStatus postEvent(const int msg, void* source,
64  const int hookswState,
65  const OsTime& rTimeout=OsTime::OS_INFINITY);
66  //:Create a hookswitch message and post it to the Hookswitch task
67  // Return the result of the message send operation.
68 
69 /* ============================ ACCESSORS ================================= */
70 
71  virtual const int getHookswitchState(void);
72  //:Return the hookswitch state
73 
74 /* ============================ INQUIRY =================================== */
75 
76 /* //////////////////////////// PROTECTED ///////////////////////////////// */
77 protected:
78 
79  PsHookswTask();
80  //:Constructor (called only indirectly via getHookswTask())
81  // We identify this as a protected (rather than a private) method so
82  // that gcc doesn't complain that the class only defines a private
83  // constructor and has no friends.
84 
85 /* //////////////////////////// PRIVATE /////////////////////////////////// */
86 private:
87 
89  {
93  };
94 
95  virtual UtlBoolean handleMessage(OsMsg& rMsg);
96  //:Handle an incoming message
97  // Return TRUE if the message was handled, otherwise FALSE.
98 
99  virtual UtlBoolean handleEventMessage(const OsEventMsg& rMsg);
100  //:Handle an incoming event message (timer expiration)
101  // Return TRUE if the message was handled, otherwise FALSE.
102  // A write lock should be acquired before calling this method.
103 
104  virtual UtlBoolean handlePhoneMessage(const PsMsg& rMsg);
105  //:Handle an incoming phone message (HOOKSW_OFF or HOOKSW_ON)
106  // Return TRUE if the message was handled, otherwise FALSE.
107  // A write lock should be acquired before calling this method.
108 
109  virtual void startDebounceTimer(void);
110  //:Start the debounce timer for the hookswitch
111 
112  virtual int readHwHookswState(void);
113  //:Read the hookswitch state from the hardware
114 
115  OsRWMutex mMutex; // mutex for synchonizing access to data
116  int mHookswState; // hookswitch state
117  PsHookswDev* mpHookswDev; // hookswitch device
121  OsTimer* mpTimer; // timer used to debounce the hookswitch
122  OsQueuedEvent* mpTimerEvent; // event signaled when the timer expires
123 
124  // Static data members used to enforce Singleton behavior
125  static PsHookswTask* spInstance; // pointer to the single instance of
126  // the PsHookswTask class
127  static OsBSem sLock; // semaphore used to ensure that there
128  // is only one instance of this class
129 
130  PsHookswTask(const PsHookswTask& rPsHookswTask);
131  //:Copy constructor (not implemented for this task)
132 
133  PsHookswTask& operator=(const PsHookswTask& rhs);
134  //:Assignment operator (not implemented for this class)
135 
136 };
137 
138 /* ============================ INLINE METHODS ============================ */
139 
140 #endif // _PsHookswTask_h_
Definition: PsHookswTask.h:49
OsTimer * mpTimer
Definition: PsHookswTask.h:121
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Definition: PsHookswTask.cpp:145
virtual int readHwHookswState(void)
Definition: PsHookswTask.cpp:470
virtual UtlBoolean handlePhoneMessage(const PsMsg &rMsg)
Definition: PsHookswTask.cpp:283
Definition: PsHookswTask.h:48
PsHookswTask & operator=(const PsHookswTask &rhs)
Definition: PsHookswTask.h:90
Definition: PsHookswTask.h:91
Definition: PsHookswDev.h:34
static PsHookswTask * spInstance
Definition: PsHookswTask.h:125
OsRWMutex mMutex
Definition: PsHookswTask.h:115
static OsBSem sLock
Definition: PsHookswTask.h:127
virtual ~PsHookswTask()
Definition: PsHookswTask.cpp:81
Definition: PsMsg.h:33
Definition: PsHookswTask.h:92
virtual UtlBoolean handleEventMessage(const OsEventMsg &rMsg)
Definition: PsHookswTask.cpp:170
OsQueuedEvent * mpTimerEvent
Definition: PsHookswTask.h:122
int mHookswState
Definition: PsHookswTask.h:116
static PsHookswTask * getHookswTask(void)
Definition: PsHookswTask.cpp:54
virtual void startDebounceTimer(void)
Definition: PsHookswTask.cpp:449
int mDebounceState
Definition: PsHookswTask.h:118
PsHookswTask()
Definition: PsHookswTask.cpp:119
Definition: PsHookswTask.h:41
HookswitchState
Definition: PsHookswTask.h:46
int mDebounceHookswState
Definition: PsHookswTask.h:120
virtual OsStatus postEvent(const int msg, void *source, const int hookswState, const OsTime &rTimeout=OsTime::OS_INFINITY)
Definition: PsHookswTask.cpp:93
int mDebounceTicks
Definition: PsHookswTask.h:119
virtual const int getHookswitchState(void)
Definition: PsHookswTask.cpp:107
DebounceState
Definition: PsHookswTask.h:88
PsHookswDev * mpHookswDev
Definition: PsHookswTask.h:117