sipXcallLib home page


PsButtonTask.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 
12 #ifndef _PsButtonTask_h_
13 #define _PsButtonTask_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include "os/OsBSem.h"
19 #include "os/OsMsgQ.h"
20 #include "os/OsRWMutex.h"
21 #include "os/OsServerTask.h"
22 #include "os/OsTime.h"
23 #include "ps/PsKeybdDev.h"
24 #include "ps/PsMsg.h"
25 
26 // DEFINES
27 // MACROS
28 // EXTERNAL FUNCTIONS
29 // EXTERNAL VARIABLES
30 // CONSTANTS
31 // STRUCTS
32 // TYPEDEFS
33 
34 // FORWARD DECLARATIONS
35 class OsEventMsg;
36 class OsTimer;
37 class PsButtonInfo;
38 
39 //:Task responsible for managing the phone set buttons
40 class PsButtonTask : public OsServerTask
41 {
42 /* //////////////////////////// PUBLIC //////////////////////////////////// */
43 public:
44 
45 /* ============================ CREATORS ================================== */
46 
47  static PsButtonTask* getButtonTask(void);
48  //:Return a pointer to the Button task, creating it if necessary
49 
50  virtual
51  ~PsButtonTask();
52  //:Destructor
53 
54 /* ============================ MANIPULATORS ============================== */
55 
56  virtual OsStatus init(const int maxButtonIndex);
57  //:Cause the Button task to (re)initialize itself
58  // The task will allocate an array [0..maxButtonIndex] of PsButtonInfo
59  // objects to hold button state.
60 
61  virtual OsStatus postEvent(const int msg, void* source,
62  const int buttonIndex,
63  const OsTime& rTimeout=OsTime::OS_INFINITY);
64  //:Create a button message and post it to the Button task
65  // Return the result of the message send operation.
66 
67  virtual OsStatus setButtonInfo(const int index,
68  const int buttonId,
69  const char* buttonName,
70  const int eventMask,
71  const OsTime& repInterval=OsTime::OS_INFINITY);
72  //:Set the button information for the button designated by "index"
73 
74 /* ============================ ACCESSORS ================================= */
75 
76  virtual const PsButtonInfo& getButtonInfo(const int index);
77  //:Return the button information for the button designated by "index"
78 
79  virtual int getButtonIndex(int buttonId);
80  //:Return the button index for the given button ID value
81  // Returns -1 if the key was not found.
82 
83  virtual int getButtonIndex(const char* buttonName);
84  //:Return the button index for the given button name value
85  // Returns -1 if the key was not found.
86 
87  virtual int getMaxButtonIndex();
88  //:Return the bmax utton index
89 
90 /* ============================ INQUIRY =================================== */
91 
92 /* //////////////////////////// PROTECTED ///////////////////////////////// */
93 protected:
94 
95  PsButtonTask();
96  //:Constructor (called only indirectly via getButtonTask())
97  // We identify this as a protected (rather than a private) method so
98  // that gcc doesn't complain that the class only defines a private
99  // constructor and has no friends.
100 
101 /* //////////////////////////// PRIVATE /////////////////////////////////// */
102 private:
103 
104  virtual UtlBoolean handleMessage(OsMsg& rMsg);
105  //:Handle an incoming message
106  // Return TRUE if the message was handled, otherwise FALSE.
107 
108  virtual UtlBoolean handleEventMessage(const OsEventMsg& rMsg);
109  //:Handle an incoming event message (timer expiration)
110  // Return TRUE if the message was handled, otherwise FALSE.
111 
112  virtual UtlBoolean handlePhoneMessage(PsMsg& rMsg);
113  //:Handle an incoming message from the keyboard controller.
114  // Return TRUE if the message was handled, otherwise FALSE.
115 
116  virtual void disableTimer(int index);
117  //:Disable the repeat timer for the designated button
118  // Do nothing if there is no repeat timer in effect for the button.
119  // A write lock should be acquired before calling this method.
120 
121  virtual void enableTimer(int index);
122  //:Enable the repeat timer for the designated button
123  // A write lock should be acquired before calling this method.
124 
125  virtual void doCleanup(void);
126  //:Release dynamically allocated storage
127  // A write lock should be acquired before calling this method.
128 
129  int mMaxBtnIdx; // max button index
130  OsRWMutex mMutex; // mutex for synchonizing access to data
131  PsButtonInfo* mpButtonInfo; // ptr to an array of PsButtonInfo objects
132  PsKeybdDev* mpKeybdDev; // ptr to keyboard device
133  OsTimer** mpRepTimers; // ptr to an array of button repeat timers
134 
135  // Static data members used to enforce Singleton behavior
136  static PsButtonTask* spInstance; // pointer to the single instance of
137  // the PsButtonTask class
138  static OsBSem sLock; // semaphore used to ensure that there
139  // is only one instance of this class
140 
141  PsButtonTask(const PsButtonTask& rPsButtonTask);
142  //:Copy constructor (not implemented for this task)
143 
144  PsButtonTask& operator=(const PsButtonTask& rhs);
145  //:Assignment operator (not implemented for this class)
146 
147 };
148 
149 /* ============================ INLINE METHODS ============================ */
150 
151 #endif // _PsButtonTask_h_
virtual int getMaxButtonIndex()
Definition: PsButtonTask.cpp:195
virtual const PsButtonInfo & getButtonInfo(const int index)
Definition: PsButtonTask.cpp:127
static PsButtonTask * getButtonTask(void)
Definition: PsButtonTask.cpp:38
static PsButtonTask * spInstance
Definition: PsButtonTask.h:136
PsKeybdDev * mpKeybdDev
Definition: PsButtonTask.h:132
virtual OsStatus setButtonInfo(const int index, const int buttonId, const char *buttonName, const int eventMask, const OsTime &repInterval=OsTime::OS_INFINITY)
Definition: PsButtonTask.cpp:111
virtual OsStatus init(const int maxButtonIndex)
Definition: PsButtonTask.cpp:79
virtual UtlBoolean handleEventMessage(const OsEventMsg &rMsg)
Definition: PsButtonTask.cpp:244
virtual void disableTimer(int index)
Definition: PsButtonTask.cpp:407
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Definition: PsButtonTask.cpp:221
static OsBSem sLock
Definition: PsButtonTask.h:138
Definition: PsMsg.h:33
Definition: PsButtonTask.h:40
Definition: PsButtonInfo.h:30
int mMaxBtnIdx
Definition: PsButtonTask.h:129
virtual UtlBoolean handlePhoneMessage(PsMsg &rMsg)
Definition: PsButtonTask.cpp:297
PsButtonTask & operator=(const PsButtonTask &rhs)
OsTimer ** mpRepTimers
Definition: PsButtonTask.h:133
virtual OsStatus postEvent(const int msg, void *source, const int buttonIndex, const OsTime &rTimeout=OsTime::OS_INFINITY)
Definition: PsButtonTask.cpp:98
OsRWMutex mMutex
Definition: PsButtonTask.h:130
PsButtonTask()
Definition: PsButtonTask.cpp:205
virtual ~PsButtonTask()
Definition: PsButtonTask.cpp:65
PsButtonInfo * mpButtonInfo
Definition: PsButtonTask.h:131
virtual int getButtonIndex(int buttonId)
Definition: PsButtonTask.cpp:136
Definition: PsKeybdDev.h:33
virtual void doCleanup(void)
Definition: PsButtonTask.cpp:442
virtual void enableTimer(int index)
Definition: PsButtonTask.cpp:422