sipXcallLib home page


PsLampTask.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 _PsLampTask_h_
12 #define _PsLampTask_h_
13 
14 // SYSTEM INCLUDES
15 
16 // APPLICATION INCLUDES
17 #include "os/OsBSem.h"
18 #include "os/OsRWMutex.h"
19 #include "os/OsTask.h"
20 #include "ps/PsLampDev.h"
21 #include "ps/PsLampInfo.h"
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 
32 //:Task responsible for managing the phone set lamps
33 class PsLampTask : public OsTask
34 {
35 
36 /* //////////////////////////// PUBLIC //////////////////////////////////// */
37 public:
38 
39 /* ============================ CREATORS ================================== */
40 
41  static PsLampTask* getLampTask(void);
42  //:Return a pointer to the Lamp task, creating it if necessary
43 
44  virtual
45  ~PsLampTask();
46  //:Destructor
47 
48 /* ============================ MANIPULATORS ============================== */
49 
50  OsStatus init(const int maxLampIndex);
51  //:Cause the Lamp task to (re)initialize itself
52  // The task will allocate an array [0..maxLampIndex] of PsLampInfo
53  // objects to hold lamp state.
54 
55  OsStatus setLampInfo(int index,
56  int lampId,
57  const char* lampName,
58  PsLampInfo::LampMode lampMode);
59  //:Set the lamp information for the lamp designated by "index"
60  // Returns OS_NOT_FOUND if the index is out of range.
61 
62  OsStatus setMode(int lampId, PsLampInfo::LampMode lampMode);
63  //:Set the mode for the lamp indicated by lampId
64  // Returns OS_NOT_FOUND if there is no lamp with that lampId.
65 
66  OsStatus setMode(const char* pLampName, PsLampInfo::LampMode lampMode);
67  //:Set the mode for the lamp indicated by pLampName
68  // Returns OS_NOT_FOUND if there is no lamp with that name.
69 
70 /* ============================ ACCESSORS ================================= */
71 
72  const PsLampInfo& getLampInfo(const int index);
73  //:Return the lamp information for the lamp designated by "index"
74 
75  int getMaxLampIndex(void) const;
76  //:Returns the max index for the array of PsLampInfo objects
77 
78  OsStatus getMode(int lampId, PsLampInfo::LampMode& rMode);
79  //:Get the current mode for the lamp designated by lampId
80  // The mode is returned in the "rMode" variable.
81  // Returns OS_NOT_FOUND if there is no lamp with that lampId.
82 
83  OsStatus getMode(const char* pLampName, PsLampInfo::LampMode& rMode);
84  //:Get the current mode for the lamp designated by pLampName
85  // The mode is returned in the "rMode" variable.
86  // Returns OS_NOT_FOUND if there is no lamp with that name.
87 
88  OsStatus getName(int lampId, const char*& rpName);
89  //:Returns the name for the lamp designated by lampId
90  // The name is returned in the "rpName" variable.
91  // Returns OS_NOT_FOUND if there is no lamp with that lampId.
92 
93 /* ============================ INQUIRY =================================== */
94 
95 /* //////////////////////////// PROTECTED ///////////////////////////////// */
96 protected:
97 
98  PsLampTask();
99  //:Constructor (called only indirectly via getLampTask())
100  // We identify this as a protected (rather than a private) method so
101  // that gcc doesn't complain that the class only defines a private
102  // constructor and has no friends.
103 
104  int run(void* pArg);
105  //:The body of the task.
106  // Responsible for updating the lamps as needed.
107 
108 /* //////////////////////////// PRIVATE /////////////////////////////////// */
109 private:
110 
112  {
120  };
121 
122  void calculateLampModeAggregates(void);
123  //:Calculate the lamp mode aggregates (the lamp IDs that are turned on
124  //:for each mode)
125 
126  void doCleanup(void);
127  //:Release dynamically allocated storage
128  // A write lock should be acquired before calling this method.
129 
130  int mMaxLampIdx; // max lamp index
131  int mModeTickMultiple; // common multiple for all tick modes
132  OsRWMutex mMutex; // mutex for synchonizing access to data
133  int mTickCnt; // current lamp tick count
134  PsLampInfo* mpLampInfo; // ptr to an array of PsLampInfo objects
135  PsLampDev* mpLampDev; // ptr to lamp device
136 
137  // Logical OR of lamps in various modes
138  unsigned long mModeBrokenFlutterLamps; // Broken flutter mode lamps
139  unsigned long mModeFlashLamps; // Flash mode lamps
140  unsigned long mModeFlutterLamps; // Flutter mode lamps
141  unsigned long mModeSteadyLamps; // Steady mode lamps
142  unsigned long mModeWinkLamps; // Wink mode lamps
143 
144  unsigned long mOnLamps; // Lamps that are turned on
145 
146  // Static data members used to enforce Singleton behavior
147  static PsLampTask* spInstance; // pointer to the single instance of
148  // the PsLampTask class
149  static OsBSem sLock; // semaphore used to ensure that there
150  // is only one instance of this class
151 
152  PsLampTask(const PsLampTask& rPsLampTask);
153  //:Copy constructor (not implemented for this task)
154 
155  PsLampTask& operator=(const PsLampTask& rhs);
156  //:Assignment operator (not implemented for this class)
157 
158 };
159 
160 /* ============================ INLINE METHODS ============================ */
161 
162 #endif // _PsLampTask_h_
unsigned long mModeFlutterLamps
Definition: PsLampTask.h:140
Definition: PsLampTask.h:119
Definition: PsLampTask.h:113
unsigned long mModeSteadyLamps
Definition: PsLampTask.h:141
static OsBSem sLock
Definition: PsLampTask.h:149
unsigned long mOnLamps
Definition: PsLampTask.h:144
static PsLampTask * spInstance
Definition: PsLampTask.h:147
Definition: PsLampInfo.h:30
int mTickCnt
Definition: PsLampTask.h:133
Definition: PsLampDev.h:33
unsigned long mModeBrokenFlutterLamps
Definition: PsLampTask.h:138
PsLampTask()
Definition: PsLampTask.cpp:269
Definition: PsLampTask.h:114
unsigned long mModeFlashLamps
Definition: PsLampTask.h:139
const PsLampInfo & getLampInfo(const int index)
Definition: PsLampTask.cpp:177
Definition: PsLampTask.h:117
int getMaxLampIndex(void) const
Definition: PsLampTask.cpp:186
OsStatus setMode(int lampId, PsLampInfo::LampMode lampMode)
Definition: PsLampTask.cpp:125
virtual ~PsLampTask()
Definition: PsLampTask.cpp:61
void doCleanup(void)
Definition: PsLampTask.cpp:382
Definition: PsLampTask.h:115
LampTaskConstants
Definition: PsLampTask.h:111
Definition: PsLampTask.h:33
void calculateLampModeAggregates(void)
Definition: PsLampTask.cpp:338
LampMode
Definition: PsLampInfo.h:38
static PsLampTask * getLampTask(void)
Definition: PsLampTask.cpp:34
OsRWMutex mMutex
Definition: PsLampTask.h:132
OsStatus getMode(int lampId, PsLampInfo::LampMode &rMode)
Definition: PsLampTask.cpp:194
PsLampDev * mpLampDev
Definition: PsLampTask.h:135
int run(void *pArg)
Definition: PsLampTask.cpp:280
unsigned long mModeWinkLamps
Definition: PsLampTask.h:142
PsLampInfo * mpLampInfo
Definition: PsLampTask.h:134
int mMaxLampIdx
Definition: PsLampTask.h:130
OsStatus getName(int lampId, const char *&rpName)
Definition: PsLampTask.cpp:243
OsStatus init(const int maxLampIndex)
Definition: PsLampTask.cpp:75
int mModeTickMultiple
Definition: PsLampTask.h:131
Definition: PsLampTask.h:116
OsStatus setLampInfo(int index, int lampId, const char *lampName, PsLampInfo::LampMode lampMode)
Definition: PsLampTask.cpp:104
PsLampTask & operator=(const PsLampTask &rhs)
Definition: PsLampTask.h:118