|
1 // ssyreferenceconfig.h |
|
2 |
|
3 /* |
|
4 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
5 * All rights reserved. |
|
6 * This component and the accompanying materials are made available |
|
7 * under the terms of "Eclipse Public License v1.0" |
|
8 * which accompanies this distribution, and is available |
|
9 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
10 * |
|
11 * Initial Contributors: |
|
12 * Nokia Corporation - initial contribution. |
|
13 * |
|
14 * Contributors: |
|
15 * |
|
16 * Description: |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalComponent |
|
26 */ |
|
27 |
|
28 |
|
29 #ifndef SSYREFERENCECONFIG_H |
|
30 #define SSYREFERENCECONFIG_H |
|
31 |
|
32 // INCLUDES |
|
33 #include <e32base.h> |
|
34 #include <sensors/sensrvtypes.h> |
|
35 #include <sensors/sensrvchannelinfo.h> |
|
36 #include <gmxmlparser.h> |
|
37 #include <sensors/channels/ssyreferenceaccelerometer.h> |
|
38 #include <sensors/channels/ssyreferencemagnetometer.h> |
|
39 #include <sensors/channels/ssyreferenceorientation.h> |
|
40 #include <sensors/channels/ssyreferenceproximity.h> |
|
41 |
|
42 // CONSTANTS |
|
43 // Data item sizes |
|
44 const TInt KSsyRefAxisDataItemSize = sizeof( TSensrvAccelerometerAxisData ); |
|
45 const TInt KSsyRefTappingDataItemSize = sizeof( TSensrvTappingData ); |
|
46 const TInt KSsyRefProximityDataItemSize = sizeof( TSensrvProximityData ); |
|
47 |
|
48 // ENUMS |
|
49 enum TSsyReferenceFunctions |
|
50 { |
|
51 ESsyReferenceOpenChannel, |
|
52 ESsyReferenceOpenChannelResp, |
|
53 ESsyReferenceDataItemReceived, |
|
54 ESsyReferenceCloseChannel, |
|
55 ESsyReferenceCloseChannelResp, |
|
56 ESsyReferenceStartChannelData, |
|
57 ESsyReferenceStopChannelData |
|
58 }; |
|
59 |
|
60 /** |
|
61 * Base class for Channel data types. Contains iChannelDataType which is set |
|
62 * by derived classes on construction. |
|
63 */ |
|
64 class TSsyRefChannelDataBase |
|
65 { |
|
66 public: |
|
67 /** |
|
68 * Enumeration for possible channel data types |
|
69 */ |
|
70 enum TSsyRefChannelDataType |
|
71 { |
|
72 ESsyRefChannelTypeTapping = 5000, |
|
73 ESsyRefChannelTypeAxis, |
|
74 ESsyRefChannelTypeProximity, |
|
75 ESsyRefChannelTypeAmbientLight |
|
76 }; |
|
77 |
|
78 TInt ChannelDataType() const { return iChannelDataType; } |
|
79 TInt Interval() const { return iInterval; } |
|
80 |
|
81 void SetTimestamp( const TTime aTimestamp ) { iTimestamp = aTimestamp; } |
|
82 TTime Timestamp() const { return iTimestamp; } |
|
83 |
|
84 TInt Size() const { return iSize; } |
|
85 |
|
86 protected: |
|
87 |
|
88 /** |
|
89 * Protected constructor as this class is not supposed to be instantiate |
|
90 * directly. |
|
91 */ |
|
92 TSsyRefChannelDataBase() {} |
|
93 |
|
94 protected: // data |
|
95 |
|
96 /** |
|
97 * Identifies the type of data type class derived from this base class |
|
98 */ |
|
99 TInt iChannelDataType; |
|
100 |
|
101 /** |
|
102 * Interval. Indicates time in ms from previous item until next item is produced |
|
103 */ |
|
104 TInt iInterval; |
|
105 |
|
106 /** |
|
107 * Timestamp. Time when this data item is generated. |
|
108 */ |
|
109 TTime iTimestamp; |
|
110 |
|
111 /** |
|
112 * Size of one data item. This is filled by derived class |
|
113 */ |
|
114 TInt iSize; |
|
115 |
|
116 /** |
|
117 * Axis data item values. |
|
118 * Accessible only from TSsyRefChannelDataAxis class |
|
119 */ |
|
120 TInt iXAxis; |
|
121 TInt iYAxis; |
|
122 TInt iZAxis; |
|
123 |
|
124 |
|
125 /** |
|
126 * Proximity data item values. |
|
127 * Accessible only from TSsyRefChannelProximity class |
|
128 */ |
|
129 TInt iProximityState; |
|
130 |
|
131 /** |
|
132 * AmbientLight data item values. |
|
133 * Accessible only from TSsyRefChannelAmbientLight class |
|
134 */ |
|
135 TInt iAmbientLightState; |
|
136 |
|
137 /** |
|
138 * Tapping data item values. Difrection of the tapping. |
|
139 * Accessible only from TSsyRefChannelDataTapping class |
|
140 */ |
|
141 TInt iDirection; |
|
142 }; |
|
143 |
|
144 // Type definition array for Data item base class |
|
145 typedef RArray<TSsyRefChannelDataBase> TSsyRefDataItemArray; |
|
146 |
|
147 /** |
|
148 * Message item for SSY <--> Sensor communications |
|
149 * Contains Channel ID for which the message belongs to, |
|
150 * Function ID that identifies the command and |
|
151 * error for error cases. |
|
152 */ |
|
153 class TSsyReferenceMsg |
|
154 { |
|
155 public: |
|
156 |
|
157 /** |
|
158 * Constructor of the TSsyReferenceMsg |
|
159 * |
|
160 * @param[in] aChannelId Channel identifier |
|
161 * @param[in] aFunction See TSsyReferenceFunctions |
|
162 */ |
|
163 TSsyReferenceMsg( TInt aChannelId, TInt aFunction ) : |
|
164 iChannelId( aChannelId ), |
|
165 iFunction( aFunction ), |
|
166 iError( KErrNone ) |
|
167 {} |
|
168 |
|
169 /** |
|
170 * Copy constructor of the TSsyReferenceMsg |
|
171 * |
|
172 * @param[in] aMsg Object to be copied to constructed object |
|
173 */ |
|
174 TSsyReferenceMsg( const TSsyReferenceMsg& aMsg ) : |
|
175 iChannelId( aMsg.iChannelId ), |
|
176 iFunction( aMsg.iFunction ), |
|
177 iError( aMsg.iError ) |
|
178 {} |
|
179 |
|
180 TInt ChannelId() { return iChannelId; } |
|
181 |
|
182 void SetFunction( TInt aFunction ) { iFunction = aFunction; } |
|
183 TInt Function() { return iFunction; } |
|
184 |
|
185 void SetError( TInt aError ) { iError = aError; } |
|
186 TInt Error() { return iError; } |
|
187 |
|
188 void SetDataItem( TSsyRefChannelDataBase* aDataItem ) { iDataItem = aDataItem; } |
|
189 TSsyRefChannelDataBase* DataItem() const { return iDataItem; } |
|
190 |
|
191 private: // data |
|
192 |
|
193 TInt iChannelId; // Identifies the channel |
|
194 TInt iFunction; // Identifies the command |
|
195 TInt iError; // Error is passed to response handler |
|
196 |
|
197 // Data item for received data. This is casted to correct data item |
|
198 // class implementation according to ChannelDataType |
|
199 TSsyRefChannelDataBase* iDataItem; |
|
200 }; |
|
201 |
|
202 /** |
|
203 * Tapping data type class implementation. |
|
204 */ |
|
205 class TSsyRefChannelDataTapping : public TSsyRefChannelDataBase |
|
206 { |
|
207 public: |
|
208 |
|
209 TSsyRefChannelDataTapping( TInt aDirection, TInt aInterval ) |
|
210 { |
|
211 iChannelDataType = ESsyRefChannelTypeTapping; |
|
212 iSize = KSsyRefTappingDataItemSize; |
|
213 iInterval = aInterval; |
|
214 iDirection = aDirection; |
|
215 } |
|
216 |
|
217 TInt Direction() const { return iDirection; } |
|
218 }; |
|
219 |
|
220 /** |
|
221 * XYZ Axis data type class implementation. |
|
222 */ |
|
223 class TSsyRefChannelDataAxis : public TSsyRefChannelDataBase |
|
224 { |
|
225 public: |
|
226 |
|
227 TSsyRefChannelDataAxis( TInt aXAxis, TInt aYAxis, TInt aZAxis, |
|
228 TInt aInterval ) |
|
229 { |
|
230 iChannelDataType = ESsyRefChannelTypeAxis; |
|
231 iSize = KSsyRefAxisDataItemSize; |
|
232 iInterval = aInterval; |
|
233 iXAxis = aXAxis; |
|
234 iYAxis = aYAxis; |
|
235 iZAxis = aZAxis; |
|
236 } |
|
237 |
|
238 TInt XAxis() const { return iXAxis; } |
|
239 TInt YAxis() const { return iYAxis; } |
|
240 TInt ZAxis() const { return iZAxis; } |
|
241 }; |
|
242 |
|
243 |
|
244 /** |
|
245 * Proximity data type class implementation. |
|
246 */ |
|
247 class TSsyRefChannelDataProximity : public TSsyRefChannelDataBase |
|
248 { |
|
249 public: |
|
250 |
|
251 TSsyRefChannelDataProximity( TInt aProximityState, TInt aInterval ) |
|
252 { |
|
253 iChannelDataType = ESsyRefChannelTypeProximity; |
|
254 iSize = KSsyRefProximityDataItemSize; |
|
255 iInterval = aInterval; |
|
256 iProximityState = aProximityState; |
|
257 } |
|
258 |
|
259 TInt ProximityState() const { return iProximityState; } |
|
260 }; |
|
261 |
|
262 /** |
|
263 * Channel ID pair class for pairing config file channel id and |
|
264 * Sensor Server generated channel ID. |
|
265 */ |
|
266 class TSsyRefChannelIdPair |
|
267 { |
|
268 public: |
|
269 /** |
|
270 * Constructor of the TSsyRefChannelIdPair |
|
271 * |
|
272 * @param[in] aConfigChannelId Channel identifier from config file |
|
273 */ |
|
274 TSsyRefChannelIdPair( TInt aConfigChannelId ) : |
|
275 iConfigChannelId( aConfigChannelId ) |
|
276 {} |
|
277 |
|
278 TInt ConfigId() const { return iConfigChannelId; } |
|
279 TInt ServerId() const { return iSrvChannelId; } |
|
280 |
|
281 void SetServerId( const TInt aSrvId ) { iSrvChannelId = aSrvId; } |
|
282 |
|
283 private: // data |
|
284 |
|
285 TInt iConfigChannelId; // Config file ID of the channel |
|
286 TInt iSrvChannelId; // Sensor server assigned ID of the channel |
|
287 }; |
|
288 |
|
289 typedef RArray<TSsyRefChannelIdPair> TSsyRefChannelIdArray; |
|
290 |
|
291 |
|
292 // CONSTANTS |
|
293 |
|
294 /** |
|
295 * Configuration class for SSY reference plugin. Generates configured SSY channel information. |
|
296 * This keeps reference SSY implementation independent from 'sensor' it uses. This class is fully |
|
297 * modifiable regarding to the needs of this SSY. It may be for example accelerometer sensor |
|
298 * without any changes in the SSY reference implementation. Only this class is modified. |
|
299 */ |
|
300 class CSsyReferenceConfig : public CActive, public MMDXMLParserObserver |
|
301 { |
|
302 |
|
303 public: |
|
304 |
|
305 /** |
|
306 * Two-phase constructor |
|
307 * |
|
308 * @return Pointer to created CSsyReferenceControl object |
|
309 */ |
|
310 static CSsyReferenceConfig* NewL(); |
|
311 |
|
312 /** |
|
313 * Virtual destructor |
|
314 */ |
|
315 virtual ~CSsyReferenceConfig(); |
|
316 |
|
317 /** |
|
318 * From CActive |
|
319 */ |
|
320 void RunL(); |
|
321 |
|
322 /** |
|
323 * From CActive |
|
324 */ |
|
325 void DoCancel(); |
|
326 |
|
327 /** |
|
328 * From CActive |
|
329 */ |
|
330 TInt RunError( TInt aError ); |
|
331 |
|
332 /** |
|
333 * From MMDXMLParserObserver |
|
334 * |
|
335 * Call back function used to inform a client of the Parser when a parsing operation completes. |
|
336 */ |
|
337 void ParseFileCompleteL(); |
|
338 |
|
339 /** |
|
340 * Starts parsing config file. This function blocks until file is parsed |
|
341 */ |
|
342 void InitConfigL(); |
|
343 |
|
344 /** |
|
345 * Total number of channels this SSY provides |
|
346 * |
|
347 * @return Count of channels this SSY is configured to provide |
|
348 */ |
|
349 TInt ChannelCount(); |
|
350 |
|
351 /** |
|
352 * Generates channels this SSY is configured to provide |
|
353 * |
|
354 * @param[in,out] aChannnelList Filled with generated channels by this configurator |
|
355 */ |
|
356 void GenerateChannels( RSensrvChannelInfoList& aChannelList ); |
|
357 |
|
358 /** |
|
359 * Updates Sensor server's generated channel Ids |
|
360 * |
|
361 * @param[in] aChannnelList Same list as GenerateChannels produces but |
|
362 * this contains channel identifiers |
|
363 */ |
|
364 void UpdateChannelIds( RSensrvChannelInfoList aChannelList ); |
|
365 |
|
366 /** |
|
367 * Reads all channel data information from config file and fills |
|
368 * parameters with information |
|
369 * |
|
370 * @param[in] aSrvChannelId Sensor server generated channel id of the target channel |
|
371 * @param[in,out] aDataItemList Contains data item objects defined in config file. Each |
|
372 * Data item is presented as Data Item class derived from TSsyRefChannelDataBase. |
|
373 * List can contain only one type of derived channel data items |
|
374 * @param[in,out] aStartInterval Contains start interval to start producing data items |
|
375 */ |
|
376 void GetChannelDataInformationL( const TInt aSrvChannelId, |
|
377 TSsyRefDataItemArray& aDataItemList, |
|
378 TInt& aStartInterval ); |
|
379 |
|
380 /** |
|
381 * Reads sensor properties from config file and adds them to list |
|
382 * |
|
383 * @param[out] aPropertyList List where to append properties |
|
384 */ |
|
385 void GetSensorPropertiesL( RSensrvPropertyList& aPropertyList ); |
|
386 |
|
387 /** |
|
388 * Reads channel properties from config file and adds them to list |
|
389 * |
|
390 * @param[in] aSenSrvChannelId Sensor server generated channel id |
|
391 * @param[out] aPropertyList List where to append properties |
|
392 */ |
|
393 void GetChannelPropertiesL( const TInt aSrvChannelId, |
|
394 RSensrvPropertyList& aPropertyList ); |
|
395 |
|
396 private: |
|
397 |
|
398 /** |
|
399 * C++ constructor. |
|
400 */ |
|
401 CSsyReferenceConfig(); |
|
402 |
|
403 /** |
|
404 * Symbian 2nd phase constructor. |
|
405 */ |
|
406 void ConstructL(); |
|
407 |
|
408 /** |
|
409 * Makes synchronous calls asynchronous |
|
410 */ |
|
411 void IssueRequest( TInt aError = KErrNone ); |
|
412 |
|
413 /** |
|
414 * Reads attribute value from element and casts it into TInt value |
|
415 * |
|
416 * @param[in] aElement Element from where to read attribute |
|
417 * @param[in] aAttrib Attribute name which to read |
|
418 * @return Integer value of read value |
|
419 */ |
|
420 TInt GetAttributeIntValue( CMDXMLElement& aElement, const TDesC& aAttrib ); |
|
421 |
|
422 /** |
|
423 * Reads attribute value from element and casts it into literal value |
|
424 * |
|
425 * @param[in] aElement Element from where to read attribute |
|
426 * @param[in] aAttrib Attribute name which to read |
|
427 * @param[in/out] aTarget Target descriptor where to copy read literal |
|
428 */ |
|
429 void GetAttributeStrValue( CMDXMLElement& aElement, const TDesC& aAttrib, TDes8& aTarget ); |
|
430 |
|
431 /** |
|
432 * Reads attribute value from element and casts it into TReal value |
|
433 * |
|
434 * @param[in] aElement Element from where to read attribute |
|
435 * @param[in] aAttrib Attribute name which to read |
|
436 * @return value of the attribute |
|
437 */ |
|
438 TReal GetAttributeRealValue( CMDXMLElement& aElement, const TDesC& aAttrib ); |
|
439 |
|
440 /** |
|
441 * Reads Hexadesimal attribute value from element and casts it into Integer value |
|
442 * |
|
443 * @param[in] aElement Element from where to read attribute |
|
444 * @param[in] aAttrib Attribute name which to read |
|
445 * @return Unsigned integer value of read Hexadesimal value |
|
446 */ |
|
447 TUint GetAttributeHexValue( CMDXMLElement& aElement, const TDesC& aAttrib ); |
|
448 |
|
449 /** |
|
450 * Compares Sensor server generated channel IDs and return corresponding |
|
451 * ConfigFile channel id |
|
452 * |
|
453 * @param[in] aSrvChannelId SenServer generated channel ID for which pair is needed |
|
454 * @return ConfigFile channel ID that is paired with aSrvChannelId |
|
455 */ |
|
456 TInt ConfigChannelId( const TInt aSrvChannelId ) const; |
|
457 |
|
458 /** |
|
459 * Searches channel element for given SensorServer generated channel ID |
|
460 * |
|
461 * @param[in] aSrvChannelId SenServer generated channel ID identifying wanted channel element |
|
462 * @return Pointer to found channel element or NULL if not found |
|
463 */ |
|
464 CMDXMLElement* ChannelElement( const TInt aSrvChannelId ); |
|
465 |
|
466 /** |
|
467 * Reads properties from given element and adds them to list. |
|
468 * Element can be either 'SsyGenealInformation' or 'ChannelItem' |
|
469 * |
|
470 * @param[in] aElement Element from where to read properties |
|
471 * @param[out] aPropertyList List where to append properties |
|
472 */ |
|
473 void GetElementPropertiesL( CMDXMLElement& aElement, RSensrvPropertyList& aPropertyList ); |
|
474 |
|
475 |
|
476 private: // data |
|
477 |
|
478 /** |
|
479 * Pointer of the config xml-file parser |
|
480 */ |
|
481 CMDXMLParser* iConfigParser; |
|
482 |
|
483 /** |
|
484 * Contains Ssy general information element and all of its childs |
|
485 */ |
|
486 CMDXMLElement* iGenralInfoElement; |
|
487 |
|
488 /** |
|
489 * Contains Ssy Channel information group element and all of its childs |
|
490 * including each channel information and channel data for testing purpose |
|
491 */ |
|
492 CMDXMLElement* iChannelGroupElement; |
|
493 |
|
494 /** |
|
495 * Number of channels defined in config file |
|
496 */ |
|
497 TInt iChannelCount; |
|
498 |
|
499 /** |
|
500 * Active scheduler wait for blocking construction until config file is parsed |
|
501 */ |
|
502 CActiveSchedulerWait iSchedulerWait; |
|
503 |
|
504 /** |
|
505 * Indicates is config file parsed |
|
506 */ |
|
507 TBool iConfigFileParsed; |
|
508 |
|
509 /** |
|
510 * Channel ID pair array |
|
511 */ |
|
512 TSsyRefChannelIdArray iChannelPairArray; |
|
513 |
|
514 /** |
|
515 * Elements of the config file. These needs to be stored |
|
516 */ |
|
517 CMDXMLDocument* iConfigFile; |
|
518 CMDXMLElement* iSsyReferenceConfig; // Root of the config |
|
519 }; |
|
520 |
|
521 #endif //SSYREFERENCECONFIG_H |
|
522 |