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