|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Base class for Sensors |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CSENSORBASE_H |
|
20 #define CSENSORBASE_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "sensor.h" |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class SensorListener; |
|
30 class CSensorConditionBase; |
|
31 |
|
32 // CONSTANTS |
|
33 const TInt KMaxSensorDescriptionLength = 4096; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 /** |
|
37 * CSensorBase |
|
38 * |
|
39 */ |
|
40 class CSensorBase : public Sensor, public CActive |
|
41 { |
|
42 class TMethod |
|
43 { |
|
44 public: // Enumerations |
|
45 enum TMethodType |
|
46 { |
|
47 ENone, |
|
48 EStartDataListening, |
|
49 ECancelDataListening, |
|
50 EStartConditionListening, |
|
51 EStopConditionListening, |
|
52 ECloseChannel, |
|
53 EStopServer, |
|
54 ERemoveCondition |
|
55 }; |
|
56 public: // Constructor & Destructor |
|
57 TMethod(TMethodType aMethodType) |
|
58 { |
|
59 iMethodType = aMethodType; |
|
60 }; |
|
61 ~TMethod() {}; |
|
62 |
|
63 public: // New methods |
|
64 inline void SetSensorData(SensorData** aData) |
|
65 { |
|
66 iData = aData; |
|
67 }; |
|
68 inline void SetBufferSize(TInt aBufferSize) |
|
69 { |
|
70 iBufferSize = aBufferSize; |
|
71 }; |
|
72 inline void SetBufferingPeriod(TInt64 aBufferingPeriod) |
|
73 { |
|
74 iBufferingPeriod = aBufferingPeriod; |
|
75 }; |
|
76 inline void SetTimestampsIncluded(TBool aTimestampsIncluded) |
|
77 { |
|
78 iTimestampsIncluded = aTimestampsIncluded; |
|
79 }; |
|
80 inline void SetValiditiesIncluded(TBool aValiditiesIncluded) |
|
81 { |
|
82 iValiditiesIncluded = aValiditiesIncluded; |
|
83 }; |
|
84 inline void SetIsOneShot(TBool aIsOneShot) |
|
85 { |
|
86 iIsOneShot = aIsOneShot; |
|
87 }; |
|
88 inline void SetJavaConditionEval(TBool aJavaConditionEval) |
|
89 { |
|
90 iJavaConditionEval = aJavaConditionEval; |
|
91 }; |
|
92 inline void SetConditionToRemove(void* aCondition) |
|
93 { |
|
94 iConditionToRemove = aCondition; |
|
95 }; |
|
96 |
|
97 inline SensorData** GetSensorData() |
|
98 { |
|
99 return iData; |
|
100 }; |
|
101 inline TInt GetBufferSize() |
|
102 { |
|
103 return iBufferSize; |
|
104 }; |
|
105 inline TInt64 GetBufferingPeriod() |
|
106 { |
|
107 return iBufferingPeriod; |
|
108 }; |
|
109 inline TBool GetTimestampsIncluded() |
|
110 { |
|
111 return iTimestampsIncluded; |
|
112 }; |
|
113 inline TBool GetValiditiesIncluded() |
|
114 { |
|
115 return iValiditiesIncluded; |
|
116 }; |
|
117 inline TBool GetIsOneShot() |
|
118 { |
|
119 return iIsOneShot; |
|
120 }; |
|
121 inline TInt GetJavaConditionEval() |
|
122 { |
|
123 return iJavaConditionEval; |
|
124 }; |
|
125 inline void* GetConditionToRemove() |
|
126 { |
|
127 return iConditionToRemove; |
|
128 }; |
|
129 inline TMethodType GetMethodType() |
|
130 { |
|
131 return iMethodType; |
|
132 }; |
|
133 |
|
134 public: // Member data |
|
135 SensorData** iData; |
|
136 TInt iBufferSize; |
|
137 TInt64 iBufferingPeriod; |
|
138 TBool iTimestampsIncluded; |
|
139 TBool iValiditiesIncluded; |
|
140 TBool iIsOneShot; |
|
141 TInt iJavaConditionEval; |
|
142 void* iConditionToRemove; |
|
143 TMethodType iMethodType; |
|
144 }; |
|
145 |
|
146 public: |
|
147 /** |
|
148 * Destructor |
|
149 */ |
|
150 virtual ~CSensorBase(); |
|
151 |
|
152 /** |
|
153 * Constructor |
|
154 */ |
|
155 CSensorBase(); |
|
156 |
|
157 public: // From Sensor |
|
158 virtual void StartServer(); |
|
159 virtual void StopServer(); |
|
160 virtual int AddCondition( |
|
161 void** aHandle, |
|
162 int aChannelId, |
|
163 double aLowerLimit, |
|
164 double aUpperLimit, |
|
165 int aLowerOp, |
|
166 int aUpperOp); |
|
167 |
|
168 virtual int RemoveCondition( |
|
169 void* aHandle); |
|
170 |
|
171 virtual int StartDataListening(SensorData** aData, |
|
172 int aBufferSize, |
|
173 long aBufferingPeriod, |
|
174 bool aTimestampsIncluded, |
|
175 bool aValiditiesIncluded, |
|
176 bool aIsOneShot); |
|
177 virtual int CancelDataListening(); |
|
178 |
|
179 virtual int StartConditionListening(int aListeningType); |
|
180 |
|
181 virtual int StopConditionListening(); |
|
182 |
|
183 virtual void CloseChannel(); |
|
184 |
|
185 |
|
186 public: // From CActive |
|
187 void RunL(); |
|
188 void DoCancel(); |
|
189 |
|
190 public: // New methods |
|
191 /** |
|
192 * Creates description string for this sensor |
|
193 * @return new description buffer |
|
194 */ |
|
195 virtual HBufC* CreateDescriptionLC() = 0; |
|
196 |
|
197 /** |
|
198 * Creates duplicate of this class |
|
199 * This method is used when new instance of specified sensor is needed |
|
200 */ |
|
201 virtual CSensorBase* DuplicateL() = 0; |
|
202 |
|
203 /** |
|
204 * Start data listening |
|
205 */ |
|
206 virtual void StartDataListeningL() = 0; |
|
207 |
|
208 /** |
|
209 * Cancel data listening |
|
210 */ |
|
211 virtual void CancelDataListeningL() = 0; |
|
212 |
|
213 /** |
|
214 * Start condition listening |
|
215 */ |
|
216 virtual void StartConditionListeningL() = 0; |
|
217 |
|
218 /** |
|
219 * Stop condition listening |
|
220 */ |
|
221 virtual void StopConditionListeningL() = 0; |
|
222 |
|
223 /** |
|
224 * Close the channel |
|
225 */ |
|
226 virtual void CloseChannelL() = 0; |
|
227 |
|
228 protected: // Second phase construction |
|
229 |
|
230 virtual void ConstructL(); |
|
231 |
|
232 protected: // New methods |
|
233 /** |
|
234 * Creates timestamp for specified time |
|
235 * @param Time to convert |
|
236 * @return new timestamp value pointing for specified time |
|
237 */ |
|
238 TInt64 TimeStamp(const TTime& aTime); |
|
239 |
|
240 /* |
|
241 * Interpret the value obtained from native source in terms |
|
242 * Java Sensor API |
|
243 * @param aValue value obtained from native source |
|
244 * @return int value in terms of this specific sensor for Java |
|
245 */ |
|
246 virtual TReal InterpretValue(TReal aValue) = 0; |
|
247 |
|
248 /** |
|
249 * Evaluate currently set conditions |
|
250 * @param aValue sensor value which is evaluated against |
|
251 * conditions |
|
252 * @param aChannelId ID number of the channel the value |
|
253 * comes from |
|
254 * @return true if one or more conditions matched, |
|
255 * false if none matched |
|
256 */ |
|
257 TBool EvaluateConditions(TReal aValue, TInt aChannelId); |
|
258 |
|
259 /** |
|
260 * Add native condition |
|
261 * @param aHandle Native handle to created condition object. |
|
262 * Filled by this method. |
|
263 * @param aChannelId Number of the channel this condition |
|
264 * is interested in |
|
265 * @param aLowerLimit Lower limit of range condition or limit |
|
266 * of limit condition |
|
267 * @param aUpperLimit Upper limit of range condition or -1 |
|
268 * for limit condition |
|
269 * @param aLowerOp Lower operand of range condition or operand |
|
270 * of limit condition |
|
271 * @param aUpperOp Upper operand of range condition or -1 |
|
272 * for limit condition |
|
273 */ |
|
274 void AddConditionL( |
|
275 void** aHandle, |
|
276 int aChannelId, |
|
277 double aLowerLimit, |
|
278 double aUpperLimit, |
|
279 int aLowerOp, |
|
280 int aUpperOp); |
|
281 |
|
282 /** |
|
283 * Remove native condition |
|
284 * @param aHandle Handle of the native condition object |
|
285 */ |
|
286 void RemoveConditionL( |
|
287 void* aHandle); |
|
288 |
|
289 private: // New methods |
|
290 /** |
|
291 * Make context switch to running thread |
|
292 */ |
|
293 void AsyncCallback(TMethod aMethod); |
|
294 |
|
295 protected: // Data |
|
296 |
|
297 /** |
|
298 * Listener, not owned |
|
299 */ |
|
300 SensorListener* iSensorListener; |
|
301 |
|
302 RPointerArray< CSensorConditionBase > iConditions; |
|
303 |
|
304 // active scheduler for this thread |
|
305 CActiveScheduler* iActiveScheduler; |
|
306 |
|
307 // Data to be filled |
|
308 SensorData** iData; |
|
309 |
|
310 TInt iBufferSize; |
|
311 // Buffering period in microseconds |
|
312 TInt64 iBufferingPeriod; |
|
313 // Flag indicating oneshot getData call |
|
314 TBool iIsOneShot; |
|
315 |
|
316 TBool iTimestampsIncluded; |
|
317 TBool iValiditiesIncluded; |
|
318 |
|
319 TInt iListeningType; |
|
320 TInt iJavaConditionEval; |
|
321 |
|
322 RThread iRunnerThread; |
|
323 |
|
324 RArray< TMethod > iMethodArray; |
|
325 |
|
326 }; |
|
327 |
|
328 #endif // CSENSORBASE_H |