sipXcallLib home page


PsPhoneTask.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _PsPhoneTask_h_
12 #define _PsPhoneTask_h_
13 
14 // SYSTEM INCLUDES
15 
16 // APPLICATION INCLUDES
17 // #include "os/OsEventMsg.h"
18 // #include "os/OsMsg.h"
19 // #include "os/OsMsgQ.h"
20 // #include "os/OsQueuedEvent.h"
21 #include "os/OsRWMutex.h"
22 #include "os/OsServerTask.h"
23 // #include "os/OsTimer.h"
24 #include "ps/PsMsg.h"
25 #include "tao/TaoReference.h"
26 
27 // DEFINES
28 // MACROS
29 // EXTERNAL FUNCTIONS
30 // EXTERNAL VARIABLES
31 // CONSTANTS
32 // STRUCTS
33 // TYPEDEFS
34 
35 // FORWARD DECLARATIONS
36 class PsButtonTask;
37 class PsHookswTask;
38 class PsLampTask;
39 class PsTaoButton;
40 class PsTaoHookswitch;
41 class PsTaoLamp;
42 class PsTaoMicrophone;
43 class PsTaoRinger;
44 class PsTaoSpeaker;
45 class PsTaoDisplay;
47 class TaoObjectMap;
48 
49 //:Task responsible for managing the phone set.
50 class PsPhoneTask : public OsServerTask
51 {
52 /* //////////////////////////// PUBLIC //////////////////////////////////// */
53 public:
54  enum SpkrMode
55  {
58  RINGER_ENABLED = 0x4, // Logical ringer use of speaker
59  SOUND_ENABLED = 0x8, // logigical speaker used for non-call sound
62  };
63 
64 /* ============================ CREATORS ================================== */
65 
66  static PsPhoneTask* getPhoneTask(void);
67  //:Return a pointer to the Phone task, creating it if necessary
68 
69  virtual
70  ~PsPhoneTask();
71  //:Destructor
72 
73 /* ============================ MANIPULATORS ============================== */
74 
75  virtual OsStatus addListener(OsServerTask* pListener);
76  //:Register as a listener for phone messages.
77  // For now, the phone task allows at most one listener and forwards
78  // all keypad and hookswitch messages to that listener.
79 
80  virtual OsStatus postEvent(const int msg, void* source,
81  const int param1, const int param2,
82  const OsTime& rTimeout=OsTime::OS_INFINITY);
83  //:Create a phone message and post it to the Phone task
84  // Return the result of the message send operation.
85 
86  virtual OsStatus setGain(int level);
87  //:Set the microphone gain to a level between 0 (low) and 100 (high)
88 
89  virtual void speakerModeEnable(int mode);
90  //: Add the speaker devices to what is already enabled
91 
92  virtual void speakerModeDisable(int mode);
93  //: Remove the speaker devices to what is already enabled
94 
95  virtual void setSpeakerMode(int mode);
96  //:Sets the speaker mode for the phone (which speakers are enabled).
97 
98  virtual OsStatus setVolume(int level);
99  //:Set the speaker volume to a level between 0 (low) and 100 (high)
100 
101  void taoSetVolume(int volume, int type);
102 
103  OsStatus taoSetMicGain(int group, int level);
104 
105  void extSpeakerConnect(UtlBoolean connected);
106 
107 /* ============================ ACCESSORS ================================= */
108 
109  UtlBoolean getComponent(PsMsg& rMsg);
110 
111  UtlBoolean numComponents(PsMsg& rMsg);
112 
113  UtlBoolean getComponents(PsMsg& rMsg);
114 
115  UtlBoolean getComponentGroups(PsMsg& rMsg);
116 
117  int activateGroup(PsMsg& rMsg);
118  int activateGroup(int type);
119 
120  UtlBoolean deactivateGroup(PsMsg& rMsg);
121  UtlBoolean deactivateGroup(int type);
122 
123  virtual int getGain(void) const;
124  //:Return the current microphone gain setting (a value from 0..100)
125 
126  virtual int getSpeakerMode(void);
127  //:Returns the speaker mode for the phone (which speakers are enabled).
128 
129  virtual int getVolume(void);
130  //:Return the current speaker volume setting (a value from 0..100)
131 
132  void taoGetVolume(int& volume, int type);
133 
134  void taoGetNominalVolume(int& volume, int type);
135 
136  int taoGetMicGain(int group);
137 
138 /* ============================ INQUIRY =================================== */
139 
140 /* //////////////////////////// PROTECTED ///////////////////////////////// */
141 protected:
142 
143  PsPhoneTask();
144  //:Constructor (called only indirectly via getPhoneTask())
145  // We identify this as a protected (rather than a private) method so
146  // that gcc doesn't complain that the class only defines a private
147  // constructor and has no friends.
148 
149 /* //////////////////////////// PRIVATE /////////////////////////////////// */
150 private:
151 
152  virtual UtlBoolean handleMessage(OsMsg& rMsg);
153  //:Handle an incoming message
154  // Return TRUE if the message was handled, otherwise FALSE.
155 
156  virtual UtlBoolean handlePhoneMessage(const PsMsg& rMsg);
157  //:Handle an incoming phone message (class PsMsg or descendants)
158  // Return TRUE if the message was handled, otherwise FALSE.
159  // A write lock should be acquired before calling this method.
160 
161  void initComponentGroups();
162  //:Initialize the platform-specific component group settings
163 
164  void initPlatformButtonSettings(PsButtonTask* pButtonTask);
165  //:Initialize the platform-specific settings for the keyboard buttons
166 
167  void setGainValue(int value);
168 
169  OsRWMutex mMutex; // mutex for synchonizing access to data
173  int mSpkrMode; // current speaker mode
174 
178 
179  // Variables related to the interface between the phone task and the
180  // TAO (Telephony Application Objects) layer.
181  PsTaoHookswitch* mpTaoHooksw; // hookswitch object
182  PsTaoButton* mpTaoButton; // button object
183  PsTaoLamp* mpTaoLamp; // lamp object
184  PsTaoRinger* mpTaoRinger; // ringer object
185  PsTaoDisplay* mpTaoDisplay; // display object
186 
187  PsTaoComponentGroup* mpHeadSetGroup; // HEAD_SET component group
188  PsTaoMicrophone* mpTaoHeadsetMic; // headset microphone object
189  PsTaoSpeaker* mpTaoHeadsetSpeaker; // headset speaker object
190 
191  PsTaoComponentGroup* mpHandSetGroup; // HAND_SET component group
192  PsTaoMicrophone* mpTaoHandsetMic; // handset microphone object
193  PsTaoSpeaker* mpTaoHandsetSpeaker; // handset speaker object
194 
195  PsTaoComponentGroup* mpExtSpeakerGroup; // EXTSPEAKER_PHONE component group
196  PsTaoComponentGroup* mpSpeakerPhoneGroup; // SPEAKER_PHONE component group
197  PsTaoComponentGroup* mpPhoneSetGroup; // PHONE_SET component group
198  PsTaoMicrophone* mpTaoBaseMic; // base microphone object
199  PsTaoSpeaker* mpTaoBaseSpeaker; // handset speaker object
200  PsTaoSpeaker* mpTaoExtSpeaker; // external speaker object
201 
202  PsTaoComponentGroup* mpOtherGroup; // OTHER component group
203  int mStepSize; // speaker volume adjust step size
204  int mHigh; // speaker volume adjust high volume
205  int mLow; // speaker volume adjust low volume
206  int mNominal; // speaker volume nominal value
207  int mSplash; // speaker volume for splash tone
208 
209  // Static data members used to enforce Singleton behavior
210  static PsPhoneTask* spInstance; // pointer to the single instance of
211  // the PsPhoneTask class
212  static OsBSem sLock; // semaphore used to ensure that there
213  // is only one instance of this class
214 
215  void postListenerMessage(const PsMsg& rMsg);
216 
217  PsPhoneTask(const PsPhoneTask& rPsPhoneTask);
218  //:Copy constructor (not implemented for this task)
219 
220  PsPhoneTask& operator=(const PsPhoneTask& rhs);
221  //:Assignment operator (not implemented for this class)
222 
223 };
224 
225 /* ============================ INLINE METHODS ============================ */
226 
227 #endif // _PsPhoneTask_h_
Definition: TaoReference.h:35
virtual void speakerModeDisable(int mode)
Definition: PsPhoneTask.cpp:385
void initComponentGroups()
Definition: PsPhoneTask.cpp:1455
Definition: PsTaoComponentGroup.h:36
SpkrMode
Definition: PsPhoneTask.h:54
Definition: TaoObjectMap.h:56
PsPhoneTask & operator=(const PsPhoneTask &rhs)
int mSpkrMode
Definition: PsPhoneTask.h:173
Definition: PsPhoneTask.h:57
Definition: PsTaoRinger.h:29
UtlBoolean getComponent(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:965
int mNominal
Definition: PsPhoneTask.h:206
virtual OsStatus setGain(int level)
Definition: PsPhoneTask.cpp:245
OsRWMutex mMutex
Definition: PsPhoneTask.h:169
PsButtonTask * mpButtonTask
Definition: PsPhoneTask.h:170
int activateGroup(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1118
Definition: PsTaoButton.h:30
PsPhoneTask()
Definition: PsPhoneTask.cpp:689
TaoReference * mpListenerCnt
Definition: PsPhoneTask.h:176
Definition: PsTaoSpeaker.h:29
Definition: PsPhoneTask.h:56
PsTaoLamp * mpTaoLamp
Definition: PsPhoneTask.h:183
int mSplash
Definition: PsPhoneTask.h:207
Definition: PsTaoDisplay.h:29
PsTaoDisplay * mpTaoDisplay
Definition: PsPhoneTask.h:185
void taoSetVolume(int volume, int type)
Definition: PsPhoneTask.cpp:573
PsTaoHookswitch * mpTaoHooksw
Definition: PsPhoneTask.h:181
Definition: PsMsg.h:33
Definition: PsButtonTask.h:40
static PsPhoneTask * spInstance
Definition: PsPhoneTask.h:210
Definition: PsPhoneTask.h:61
Definition: PsTaoLamp.h:30
static OsBSem sLock
Definition: PsPhoneTask.h:212
void taoGetNominalVolume(int &volume, int type)
Definition: PsPhoneTask.cpp:483
UtlBoolean deactivateGroup(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1214
void postListenerMessage(const PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1280
int mStepSize
Definition: PsPhoneTask.h:203
virtual OsStatus postEvent(const int msg, void *source, const int param1, const int param2, const OsTime &rTimeout=OsTime::OS_INFINITY)
Definition: PsPhoneTask.cpp:164
UtlBoolean numComponents(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1055
PsTaoComponentGroup * mpSpeakerPhoneGroup
Definition: PsPhoneTask.h:196
PsTaoMicrophone * mpTaoHeadsetMic
Definition: PsPhoneTask.h:188
Definition: PsTaoHookswitch.h:29
void setGainValue(int value)
Definition: PsPhoneTask.cpp:1205
int mLow
Definition: PsPhoneTask.h:205
PsTaoMicrophone * mpTaoHandsetMic
Definition: PsPhoneTask.h:192
virtual int getVolume(void)
Definition: PsPhoneTask.cpp:636
Definition: PsHookswTask.h:41
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Definition: PsPhoneTask.cpp:744
virtual void speakerModeEnable(int mode)
Definition: PsPhoneTask.cpp:379
Definition: PsLampTask.h:33
PsTaoSpeaker * mpTaoBaseSpeaker
Definition: PsPhoneTask.h:199
virtual int getGain(void) const
Definition: PsPhoneTask.cpp:432
virtual int getSpeakerMode(void)
Definition: PsPhoneTask.cpp:478
UtlBoolean getComponents(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1003
void initPlatformButtonSettings(PsButtonTask *pButtonTask)
Definition: PsPhoneTask.cpp:1291
Definition: PsPhoneTask.h:58
PsTaoComponentGroup * mpHandSetGroup
Definition: PsPhoneTask.h:191
Definition: PsTaoMicrophone.h:29
PsLampTask * mpLampTask
Definition: PsPhoneTask.h:172
Definition: PsPhoneTask.h:59
virtual UtlBoolean handlePhoneMessage(const PsMsg &rMsg)
Definition: PsPhoneTask.cpp:766
virtual OsStatus addListener(OsServerTask *pListener)
Definition: PsPhoneTask.cpp:143
PsTaoComponentGroup * mpHeadSetGroup
Definition: PsPhoneTask.h:187
int mHigh
Definition: PsPhoneTask.h:204
UtlBoolean getComponentGroups(PsMsg &rMsg)
Definition: PsPhoneTask.cpp:1081
PsTaoSpeaker * mpTaoHeadsetSpeaker
Definition: PsPhoneTask.h:189
static PsPhoneTask * getPhoneTask(void)
Definition: PsPhoneTask.cpp:83
virtual OsStatus setVolume(int level)
Definition: PsPhoneTask.cpp:403
virtual void setSpeakerMode(int mode)
Definition: PsPhoneTask.cpp:314
PsTaoButton * mpTaoButton
Definition: PsPhoneTask.h:182
PsTaoSpeaker * mpTaoHandsetSpeaker
Definition: PsPhoneTask.h:193
PsTaoMicrophone * mpTaoBaseMic
Definition: PsPhoneTask.h:198
PsTaoComponentGroup * mpPhoneSetGroup
Definition: PsPhoneTask.h:197
PsHookswTask * mpHookswTask
Definition: PsPhoneTask.h:171
uintptr_t TaoObjHandle
Definition: TaoDefs.h:32
void taoGetVolume(int &volume, int type)
Definition: PsPhoneTask.cpp:529
virtual ~PsPhoneTask()
Definition: PsPhoneTask.cpp:110
Definition: PsPhoneTask.h:50
PsTaoSpeaker * mpTaoExtSpeaker
Definition: PsPhoneTask.h:200
int taoGetMicGain(int group)
Definition: PsPhoneTask.cpp:175
PsTaoRinger * mpTaoRinger
Definition: PsPhoneTask.h:184
void extSpeakerConnect(UtlBoolean connected)
Definition: PsPhoneTask.cpp:418
Definition: PsPhoneTask.h:60
PsTaoComponentGroup * mpExtSpeakerGroup
Definition: PsPhoneTask.h:195
TaoObjectMap * mpListeners
Definition: PsPhoneTask.h:175
TaoObjHandle * mpActiveListeners
Definition: PsPhoneTask.h:177
PsTaoComponentGroup * mpOtherGroup
Definition: PsPhoneTask.h:202
OsStatus taoSetMicGain(int group, int level)
Definition: PsPhoneTask.cpp:210