|
1 /* |
|
2 * Copyright (c) 2005-2007 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: BTHid item |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef C_PARSER_H |
|
19 #define C_PARSER_H |
|
20 |
|
21 #include "hidreportroot.h" |
|
22 |
|
23 class TItem; |
|
24 |
|
25 /** |
|
26 * HID Parser error codes. For a description of the error code |
|
27 * format, see "HID Parser Error Codes", Revision 1.2, USB |
|
28 * Implementers' Forum, February 2000. |
|
29 */ |
|
30 enum THidParserError |
|
31 { |
|
32 // General: |
|
33 // |
|
34 EUnknownItem = 0xbf00, |
|
35 ELongItemDefined = 0x3e00, |
|
36 // |
|
37 // Global: |
|
38 // |
|
39 EZeroUsagePage = 0x8004, |
|
40 EUsagePageOutOfRange = 0x8104, |
|
41 ELogicalMinInvalidForArray = 0x8214, |
|
42 ELogicalMaxInvalidForArray = 0x8224, |
|
43 ELonelyPhysicalMin = 0x8034, |
|
44 ELonelyPhysicalMax = 0x8044, |
|
45 EZeroReportId = 0x8084, |
|
46 EReportIdTooBig = 0x8184, |
|
47 ELateReportId = 0x8284, |
|
48 EReportIdOutsideTopLevel = 0x8484, |
|
49 EZeroReportCount = 0x8094, |
|
50 EPushWithoutPop = 0x80a4, |
|
51 EPushHasData = 0x81a4, |
|
52 EPopWithoutPush = 0x80b4, |
|
53 EPopHasData = 0x81b4, |
|
54 ERedundantGlobalItem = 0x80f4, |
|
55 EReservedUsagePage = 0x0004, |
|
56 ELogicalMinExceedsMax = 0x0014, |
|
57 EPhysicalMinExceedsMax = 0x0034, |
|
58 EExponentReservedBitsNonZero = 0x0054, |
|
59 EUnitReservedBitsNonZero = 0x0064, |
|
60 // |
|
61 // Local: |
|
62 // |
|
63 ELonelyUsageMin = 0x8018, |
|
64 EUsageMinExceedsMax = 0x8118, |
|
65 EUsagePageMismatchMin = 0x8318, |
|
66 ELonelyUsageMax = 0x8028, |
|
67 EUsagePageMismatchMax = 0x8228, |
|
68 ELonelyDesignatorMin = 0x8048, |
|
69 EDesignatorMinExceedsMax = 0x8148, |
|
70 ELonelyDesignatorMax = 0x8058, |
|
71 ELonelyStringMin = 0x8088, |
|
72 EStringMinExceedsMax = 0x8188, |
|
73 ELonelyStringMax = 0x8098, |
|
74 EUnknownDelimiter = 0x80a8, |
|
75 ENestedDelimiter = 0x81a8, |
|
76 ELonelyDelimiter = 0x82a8, |
|
77 EInvalidItemWithinDelimiter = 0x83a8, |
|
78 EDelimiterAtTopLevel = 0x84a8, |
|
79 EZeroUsage = 0x0008, |
|
80 // |
|
81 // Main: |
|
82 // |
|
83 EInputMissingItems = 0x8080, |
|
84 EInputItemWithinDelimiter = 0x8180, |
|
85 EInputReportSize = 0x8280, |
|
86 EInputMinExceedsMax = 0x8380, |
|
87 EOutputMissingItems = 0x8090, |
|
88 EOutputItemWithinDelimiter = 0x8190, |
|
89 EOutputReportSize = 0x8290, |
|
90 EOutputMinExceedsMax = 0x8390, |
|
91 EFeatureMissingItems = 0x80b0, |
|
92 EFeatureItemWithinDelimiter = 0x81b0, |
|
93 EFeatureReportSize = 0x82b0, |
|
94 EFeatureMinExceedsMax = 0x83b0, |
|
95 ENoMatchingBeginCollection = 0x80c0, |
|
96 EEndCollectionWithinDelimiter = 0x81c0, |
|
97 EReportMustBeEightBitMultiple = 0x82c0, |
|
98 ENoMatchingEndCollection = 0x80a0, |
|
99 EBeginCollectionWithinDelimiter = 0x81a0, |
|
100 EApplicationCollectionLevel = 0x82a0, |
|
101 EInputReservedBitsNonZero = 0x0080, |
|
102 EInputLocalMultipleUse = 0x0280, |
|
103 EOutputReservedBitsNonZero = 0x0090, |
|
104 EOutputLocalMultipleUse = 0x0290, |
|
105 EFeatureReservedBitsNonZero = 0x00b0, |
|
106 EFeatureLocalMultipleUse = 0x02b0, |
|
107 ECollectionLocalUnused = 0x00a0, |
|
108 ECollectionTypeUnknownReserved = 0x01a0, |
|
109 EEndCollectionLocalUnused = 0x00c0, |
|
110 EEndCollectionHasData = 0x01c0, |
|
111 // |
|
112 // Our ("vendor specific") codes: |
|
113 // |
|
114 EInvalidItemLength = 0xC000, |
|
115 EApplicationHasDelimiter = 0x40a0, |
|
116 EDelimiterWithinNamedArray = 0x40a8, |
|
117 ECollectionHasNoUsage = 0x40c0, |
|
118 ECollectionHasNoUsagePage = 0x41c0 |
|
119 }; |
|
120 |
|
121 /** |
|
122 * HID parser panics |
|
123 */ |
|
124 enum THidParsingError |
|
125 { |
|
126 // ASSERT_ALWAYS: |
|
127 // |
|
128 EZeroLengthItem = 1, //!< Zero descriptor length in TItem constructor |
|
129 ENoReportRoot = 2, //!< iReportRoot is 0 in CreateFieldL() |
|
130 ENoCurrentCollection = 3, //!< No current collection in Collection() |
|
131 // |
|
132 // ASSERT_DEBUG: |
|
133 // |
|
134 ENoCollectionToCheck = 10, //!< No collection in CheckForCollectionErrors() |
|
135 EPopFailed = 11, //!< Empty collection stack in PopCollection() |
|
136 EIndexOutOfRange = 12, //!< Index out of range in TItem::operator[] |
|
137 EItemTooLong = 13 //!< Data() called for item with size > 4 |
|
138 }; |
|
139 |
|
140 |
|
141 /** |
|
142 * Parser global states |
|
143 * |
|
144 * CParser uses TParserGlobalState objects to store the global item |
|
145 * state during parsing. The global state can be saved and restored |
|
146 * using the HID descriptor POP and PUSH tags, therefore CParser |
|
147 * incorporates a stack of TParserGlobalState objects. |
|
148 * |
|
149 * |
|
150 * @lib generichid.lib |
|
151 * @since S60 v5.0 |
|
152 */ |
|
153 class TParserGlobalState |
|
154 { |
|
155 friend class CParser; |
|
156 |
|
157 public: |
|
158 |
|
159 TParserGlobalState(); |
|
160 |
|
161 /** |
|
162 * Copies all data members into a CField object. The other |
|
163 * members of the CField object (those corresponding to local |
|
164 * HID descriptor tags) are unaffected. |
|
165 * |
|
166 * @since S60 v5.0 |
|
167 * @param aField Pointer to the field object to populate. |
|
168 * @return None. |
|
169 */ |
|
170 void Populate(CField *aField) const; |
|
171 |
|
172 private: |
|
173 /** |
|
174 * Usage page |
|
175 */ |
|
176 TInt iUsagePage; |
|
177 |
|
178 /** |
|
179 * Logical minimum |
|
180 */ |
|
181 TInt iLogicalMin; |
|
182 |
|
183 /** |
|
184 * Logical maximum |
|
185 */ |
|
186 TInt iLogicalMax; |
|
187 |
|
188 /** |
|
189 * Physical minimum |
|
190 */ |
|
191 TInt iPhysicalMin; |
|
192 |
|
193 /** |
|
194 * Physical maximum |
|
195 */ |
|
196 TInt iPhysicalMax; |
|
197 |
|
198 /** |
|
199 * Unit type |
|
200 */ |
|
201 TInt iUnit; |
|
202 |
|
203 /** |
|
204 * Unit exponent |
|
205 */ |
|
206 TInt iUnitExponent; |
|
207 |
|
208 /** |
|
209 * Associated report ID |
|
210 */ |
|
211 TInt iReportId; |
|
212 |
|
213 /** |
|
214 * Report size |
|
215 */ |
|
216 TInt iSize; |
|
217 |
|
218 /** |
|
219 * Report count |
|
220 */ |
|
221 TInt iCount; |
|
222 }; |
|
223 |
|
224 |
|
225 /** |
|
226 * |
|
227 * HID parser |
|
228 * CParser parses a HID report descriptor. It outputs a CReportRoot |
|
229 * containing a tree of CCollection and CField objects representing |
|
230 * the descriptor information. A HID device driver can then use this, |
|
231 * in conjunction with TReportTranslator and CReportGenerator objects, |
|
232 * to facilitate communication with a HID device. |
|
233 * |
|
234 * The parsing process conforms to the HID class specification |
|
235 * document: "USB Device Class Definition for Human Interface Devices |
|
236 * (HID)", Firmware Specification, Version 1.11, USB Implementers' Forum, |
|
237 * June 2001. |
|
238 * |
|
239 * |
|
240 * @lib generichid.lib |
|
241 * @since S60 v5.0 |
|
242 */ |
|
243 class CParser : public CBase |
|
244 { |
|
245 public: |
|
246 IMPORT_C static CParser* NewL(); |
|
247 IMPORT_C static CParser* NewLC(); |
|
248 |
|
249 virtual ~CParser(); |
|
250 |
|
251 /** |
|
252 * ParseL() parses a string of bytes representing a HID report |
|
253 * descriptor. It returns a tree of collection and field objects (a |
|
254 * CReportRoot). Ownership of the CReportRoot is transferred to the |
|
255 * caller. |
|
256 * |
|
257 * Warning messages produced during the parse process are added to |
|
258 * a list which the driver can retrieve using the Warnings() |
|
259 * function. Note that the list will be overwritten by the next |
|
260 * ParseL() operation. |
|
261 * |
|
262 * Errors and warnings are represented using the format described |
|
263 * in "HID Parser Error Codes", Revision 1.2, USB Implementers' |
|
264 * Forum, February 2000. |
|
265 * |
|
266 * @since S60 v5.0 |
|
267 * @param aRawData The report descriptor data to be processed |
|
268 * @return The root collection, a tree of CCollection and CField objects |
|
269 */ |
|
270 IMPORT_C CReportRoot* ParseL(const TDesC8& aRawData); |
|
271 |
|
272 /** |
|
273 * Return field count |
|
274 * |
|
275 * @since S60 v5.0 |
|
276 * @return field count |
|
277 */ |
|
278 TInt FieldCount(); |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 private: |
|
285 CParser(); |
|
286 void ConstructL(); |
|
287 |
|
288 /** |
|
289 * Handle a HID descriptor main item. This includes the creation |
|
290 * of new field objects in the current collection and management of |
|
291 * the global item state stack. |
|
292 * |
|
293 * @since S60 v5.0 |
|
294 * @param aItem The current report descriptor tag and its associated data |
|
295 * @return KErrNone (0) on success, otherwise a critical error code in |
|
296 * the standard HID format. |
|
297 */ |
|
298 TInt MainItemL(const TItem& aItem); |
|
299 |
|
300 /** |
|
301 * Handle a HID descriptor local item. Stores the data in the |
|
302 * appropriate member of the local state object, *iLocal. |
|
303 * |
|
304 * @since S60 v5.0 |
|
305 * @param aItem The current report descriptor tag and its associated data |
|
306 * @return KErrNone (0) on success, otherwise a critical error code in |
|
307 * the standard HID format. |
|
308 */ |
|
309 TInt LocalItemL(const TItem& aItem); |
|
310 |
|
311 /** |
|
312 * Handle a HID descriptor global item. Stores the data in the |
|
313 * appropriate member of the current global state object, iGlobal. |
|
314 * |
|
315 * @since S60 v5.0 |
|
316 * @param aItem The current report descriptor tag and its associated data |
|
317 * @return KErrNone (0) on success, otherwise a critical error code in |
|
318 * the standard HID format. |
|
319 */ |
|
320 TInt GlobalItemL(const TItem& aItem); |
|
321 |
|
322 /** |
|
323 * Used to access the current collection object, i.e. the object |
|
324 * at the top of the collection stack (iCollectionStack). |
|
325 * |
|
326 * |
|
327 * @since S60 v5.0 |
|
328 * @return A pointer to the current collection object. |
|
329 * |
|
330 */ |
|
331 CCollection* Collection(); |
|
332 |
|
333 /** |
|
334 * Pushes a pointer to the current collection object on to the |
|
335 * collection stack. |
|
336 * |
|
337 * Note that the collection stack is used to create the tree of |
|
338 * collections. It should not be confused with the global state |
|
339 * stack, iGlobalStack. |
|
340 * |
|
341 * @since S60 v5.0 |
|
342 * @param aCollection The collection to be pushed onto the stack |
|
343 * @return None. |
|
344 * |
|
345 */ |
|
346 void PushCollectionL(const CCollection* aCollection); |
|
347 |
|
348 /** |
|
349 * Pushes a pointer to the current collection object on to the |
|
350 * collection stack. |
|
351 * |
|
352 * Note that the collection stack is used to create the tree of |
|
353 * collections. It should not be confused with the global state |
|
354 * stack, iGlobalStack. |
|
355 * |
|
356 * @since S60 v5.0 |
|
357 * @return None. |
|
358 * |
|
359 */ |
|
360 void PopCollection(); |
|
361 |
|
362 /** |
|
363 * CreateFieldL() is called to instantiate a new CField object |
|
364 * when an input, output or feature item is encountered in the |
|
365 * report descriptor. |
|
366 * |
|
367 * The current local and global states extracted from the report |
|
368 * descriptor are copied to the CField, which is placed into the |
|
369 * current CCollection. |
|
370 * |
|
371 * @since S60 v5.0 |
|
372 * @param aType The type of field: input, output or feature |
|
373 * @param aAttributes The attributes for the field (e.g. Data, Array, |
|
374 * Absolute.) |
|
375 * @return KErrNone (0) on success, otherwise a critical error code |
|
376 * in the standard HID format. |
|
377 * |
|
378 */ |
|
379 TInt CreateFieldL(CField::TType aType, TUint32 aAttributes); |
|
380 |
|
381 /** |
|
382 * ClearLocalState() clears the appropriate fields in the CField |
|
383 * object that represents the current local item state. |
|
384 * |
|
385 * @since S60 v5.0 |
|
386 * @return None |
|
387 * |
|
388 */ |
|
389 void ClearLocalState(); |
|
390 |
|
391 /** |
|
392 * DumpStateTableL() copies the current local and global item state |
|
393 * into a CField object. |
|
394 * |
|
395 * @since S60 v5.0 |
|
396 * @param aField The field object to receive the data |
|
397 * @return None |
|
398 * |
|
399 */ |
|
400 void DumpStateTableL(CField *aField) const; |
|
401 |
|
402 /** |
|
403 * CreateCollectionL() is called to instantiate a new CCollection |
|
404 * object when a "begin collection" item is encountered in the |
|
405 * report descriptor. |
|
406 * |
|
407 * @since S60 v5.0 |
|
408 * @param aType The type of the collection. This can be one of the |
|
409 * seven standard types defined in CCollection::TType, |
|
410 * or a vendor defined value. |
|
411 * @return KErrNone (0) on success, otherwise a critical error code in |
|
412 * the standard HID format. |
|
413 */ |
|
414 TInt CreateCollectionL(TUint32 aType); |
|
415 |
|
416 /** |
|
417 * CheckForCollectionErrors() validates the current collection |
|
418 * object. It adds non-critical errors to the warnings list. It |
|
419 * returns an error code if a critical error is encountered. |
|
420 * |
|
421 * @since S60 v5.0 |
|
422 * @param aType The type of the collection (one of the CCollection::TType |
|
423 * values, or vendor defined). |
|
424 * @return KErrNone (0) if there was no error, otherwise a critical |
|
425 * error code in the standard HID format. |
|
426 */ |
|
427 TInt CheckForCollectionErrors(TUint32 aType); |
|
428 |
|
429 /** |
|
430 * CheckForFieldErrors() validates the current global and local |
|
431 * item state in preparation for creating a CField object. It adds |
|
432 * non-critical errors to the warnings list. It returns an error |
|
433 * code if a critical error is encountered. |
|
434 * |
|
435 * @since S60 v5.0 |
|
436 * @param @param aType The type of the field (input, output or feature). |
|
437 * @param aAttributes The attributes for the field (e.g. Data, Array, |
|
438 * Absolute.) |
|
439 * @return KErrNone (0) if there was no error, otherwise a critical |
|
440 * error code in the standard HID format. |
|
441 */ |
|
442 TInt CheckForFieldErrors(CField::TType aType, TUint32 aAttributes); |
|
443 |
|
444 /** |
|
445 * CheckForMainErrors() performs error checking common to |
|
446 * CheckForCollectionErrors() and CheckForFieldErrors(). It adds |
|
447 * non-critical errors to the warnings list. It returns an error |
|
448 * code if a critical error is encountered. |
|
449 * |
|
450 * @since S60 v5.0 |
|
451 * @return KErrNone (0) if there was no error, otherwise a critical |
|
452 * error code in the standard HID format. |
|
453 */ |
|
454 TInt CheckForMainErrors(); |
|
455 |
|
456 /** |
|
457 * CheckAllReportSizes() checks if all report sizes are integral |
|
458 * multiples of 8 bits. |
|
459 * |
|
460 * @since S60 v5.0 |
|
461 * @return ETrue if all report sizes are integral multiples of |
|
462 * 8 bits. |
|
463 */ |
|
464 TBool CheckAllReportSizes() const; |
|
465 |
|
466 /** |
|
467 * BitsToRepresentRange() returns the number of bits required to |
|
468 * represent all values in a given range. It is used to check |
|
469 * that the report field size is appropriate for the given |
|
470 * logical minimum and maximum. |
|
471 * |
|
472 * If the range is all positive then it is assumed that there is no |
|
473 * sign bit, otherwise twos complement format is assumed, as per |
|
474 * the HID class specification, v1.11, Section 6.2.2.7. |
|
475 * |
|
476 * @since S60 v5.0 |
|
477 * @param aMin Logical minimum |
|
478 * @param aMax Logical maximum |
|
479 * @return The number of bits required to represent the range aMin |
|
480 * to aMax (inclusive). |
|
481 */ |
|
482 static TInt BitsToRepresentRange(TInt aMin, TInt aMax); |
|
483 |
|
484 /** |
|
485 * NumberOfLeadingZeros() is used by BitsToRepresentRange(). It |
|
486 * returns the number of leading zeros in the binary representation |
|
487 * of a number, effectively performing a log_2 operation. |
|
488 * |
|
489 * @since S60 v5.0 |
|
490 * @param aValue Unsigned 32-bit value |
|
491 * @return Number of leading zeros in the binary representation of aValue |
|
492 */ |
|
493 static TInt NumberOfLeadingZeros(TUint32 aValue); |
|
494 |
|
495 /** |
|
496 * IssueWarning() adds a TParserWarning to the warning list. |
|
497 * |
|
498 * @since S60 v5.0 |
|
499 * @param aHidWarningCode The error or warning code, which should |
|
500 * be in the standard HID format. |
|
501 * @return None |
|
502 */ |
|
503 void IssueWarning(TInt aHidWarningCode); |
|
504 |
|
505 /** |
|
506 * IsReservedUsagePage() checks if the given HID usage page is |
|
507 * listed as reserved according to the HID clas specification, |
|
508 * v1.11. |
|
509 * |
|
510 * @since S60 v5.0 |
|
511 * @param aUsagePage The usage page to check. |
|
512 * @result ETrue if the usage page is listed as reserved. |
|
513 */ |
|
514 static TBool IsReservedUsagePage(TInt aUsagePage); |
|
515 |
|
516 |
|
517 /** |
|
518 * HandleMainInputTagL |
|
519 * |
|
520 * @since S60 v5.0 |
|
521 * @param aItem a Hid field item |
|
522 * @result error code |
|
523 */ |
|
524 TInt HandleMainInputTagL(const TItem& aItem); |
|
525 |
|
526 |
|
527 /** |
|
528 * HandleMainOutputTag |
|
529 * |
|
530 * @since S60 v5.0 |
|
531 * @param aItem a Hid field item |
|
532 * @result error code |
|
533 */ |
|
534 TInt HandleMainOutputTagL(const TItem& aItem); |
|
535 |
|
536 /** |
|
537 * HandleMainFeature |
|
538 * |
|
539 * @since S60 v5.0 |
|
540 * @param aItem a Hid field item |
|
541 * @result error code |
|
542 */ |
|
543 TInt HandleMainFeatureL( const TItem& aItem ); |
|
544 |
|
545 /** |
|
546 * HandleMainCollection |
|
547 * |
|
548 * @since S60 v5.0 |
|
549 * @param aItem a Hid field item |
|
550 * @result error code |
|
551 */ |
|
552 TInt HandleMainCollectionL( const TItem& aItem ); |
|
553 |
|
554 |
|
555 /** |
|
556 * MainEndCollection |
|
557 * |
|
558 * @since S60 v5.0 |
|
559 * @param aItem a Hid field item |
|
560 * @result error code |
|
561 */ |
|
562 TInt HandleMainEndCollection( const TItem& aItem); |
|
563 |
|
564 /** |
|
565 * HandleGlobalReportId |
|
566 * |
|
567 * @since S60 v5.0 |
|
568 * @param aItem a Hid field item |
|
569 * @result error code |
|
570 */ |
|
571 TInt HandleGlobalReportId( const TItem& aItem ); |
|
572 |
|
573 /** |
|
574 * HandleGlobalUsagePage |
|
575 * |
|
576 * @since S60 v5.0 |
|
577 * @param aItem a Hid field item |
|
578 * @result error code |
|
579 */ |
|
580 TInt HandleGlobalUsagePage( const TItem& aItem ); |
|
581 |
|
582 /** |
|
583 * HandleGlobalLogicalMinimum |
|
584 * |
|
585 * @since S60 v5.0 |
|
586 * @param aItem a Hid field item |
|
587 * @result error code |
|
588 */ |
|
589 TInt HandleGlobalLogicalMinimum( const TItem& aItem ); |
|
590 |
|
591 /** |
|
592 * HandleGlobalLogicalMaximum |
|
593 * |
|
594 * @since S60 ?S60_version *** for example, S60 v3.0 |
|
595 * @param aItem a Hid field item |
|
596 * @result error code |
|
597 */ |
|
598 TInt HandleGlobalLogicalMaximum( const TItem& aItem ); |
|
599 |
|
600 /** |
|
601 * HandleGlobalPhysicalMinimum |
|
602 * |
|
603 * @since S60 v5.0 |
|
604 * @param aItem a Hid field item |
|
605 * @result error code |
|
606 */ |
|
607 TInt HandleGlobalPhysicalMinimum( const TItem& aItem ); |
|
608 |
|
609 /** |
|
610 * HandleGlobalPhysicalMinimum |
|
611 * |
|
612 * @since S60 v5.0 |
|
613 * @param aItem a Hid field item |
|
614 * @result error code |
|
615 */ |
|
616 TInt HandleGlobalPhysicalMaximum( const TItem& aItem ); |
|
617 |
|
618 /** |
|
619 * HandleGlobalUnit |
|
620 * |
|
621 * @since S60 v5.0 |
|
622 * @param aItem a Hid field item |
|
623 * @result error code |
|
624 */ |
|
625 TInt HandleGlobalUnit( const TItem& aItem ); |
|
626 |
|
627 /** |
|
628 * HandleGlobalUnitExponent |
|
629 * |
|
630 * @since S60 v5.0 |
|
631 * @param aItem a Hid field item |
|
632 * @result error code |
|
633 */ |
|
634 TInt HandleGlobalUnitExponent( const TItem& aItem ); |
|
635 |
|
636 /** |
|
637 * HandleGlobalReportSize |
|
638 * |
|
639 * @since S60 v5.0 |
|
640 * @param aItem a Hid field item |
|
641 * @result error code |
|
642 */ |
|
643 TInt HandleGlobalReportSize( const TItem& aItem ); |
|
644 |
|
645 /** |
|
646 * HandleGlobalReportSize |
|
647 * |
|
648 * @since S60 v5.0 |
|
649 * @param aItem a Hid field item |
|
650 * @result error code |
|
651 */ |
|
652 TInt HandleGlobalReportCount( const TItem& aItem ); |
|
653 |
|
654 /** |
|
655 * HandleGlobalPush |
|
656 * |
|
657 * @since S60 v5.0 |
|
658 * @param aItem a Hid field item |
|
659 * @result error code |
|
660 */ |
|
661 TInt HandleGlobalPushL( const TItem& aItem ); |
|
662 |
|
663 /** |
|
664 * HandleGlobalPop |
|
665 * |
|
666 * @since S60 v5.0 |
|
667 * @param aItem a Hid field item |
|
668 * @result error code |
|
669 */ |
|
670 TInt HandleGlobalPop( const TItem& aItem ); |
|
671 |
|
672 /** |
|
673 * HandleLocalUsage |
|
674 * |
|
675 * @since S60 v5.0 |
|
676 * @param aItem a Hid field item |
|
677 * @result error code |
|
678 */ |
|
679 TInt HandleLocalUsageL( const TItem& aItem ); |
|
680 |
|
681 /** |
|
682 * HandleLocalUsageMinimum |
|
683 * |
|
684 * @since S60 v5.0 |
|
685 * @param aItem a Hid field item |
|
686 * @result error code |
|
687 */ |
|
688 TInt HandleLocalUsageMinimum( const TItem& aItem ); |
|
689 |
|
690 /** |
|
691 * HandleLocalUsageMinimum |
|
692 * |
|
693 * @since S60 v5.0 |
|
694 * @param aItem a Hid field item |
|
695 * @result error code |
|
696 */ |
|
697 TInt HandleLocalUsageMaximum( const TItem& aItem ); |
|
698 |
|
699 /** |
|
700 * HandleLocalDesignatorIndex |
|
701 * |
|
702 * @since S60 v5.0 |
|
703 * @param aItem a Hid field item |
|
704 * @result error code |
|
705 */ |
|
706 TInt HandleLocalDesignatorIndex( const TItem& aItem ); |
|
707 |
|
708 /** |
|
709 * HandleLocalDesignatorMinimum |
|
710 * |
|
711 * @since S60 v5.0 |
|
712 * @param aItem a Hid field item |
|
713 * @result error code |
|
714 */ |
|
715 TInt HandleLocalDesignatorMinimum( const TItem& aItem ); |
|
716 |
|
717 /** |
|
718 * HandleLocalDesignatorMaximum |
|
719 * |
|
720 * @since S60 v5.0 |
|
721 * @param aItem a Hid field item |
|
722 * @result error code |
|
723 */ |
|
724 TInt HandleLocalDesignatorMaximum( const TItem& aItem ); |
|
725 |
|
726 /** |
|
727 * HandleLocalStringIndex |
|
728 * |
|
729 * @since S60 v5.0 |
|
730 * @param aItem a Hid field item |
|
731 * @result error code |
|
732 */ |
|
733 TInt HandleLocalStringIndex( const TItem& aItem ); |
|
734 |
|
735 /** |
|
736 * HandleLocalStringMinimum |
|
737 * |
|
738 * @since S60 v5.0 |
|
739 * @param aItem a Hid field item |
|
740 * @result error code |
|
741 */ |
|
742 TInt HandleLocalStringMinimum( const TItem& aItem ); |
|
743 |
|
744 /** |
|
745 * HandleLocalStringMaximum |
|
746 * |
|
747 * @since S60 v5.0 |
|
748 * @param aItem a Hid field item |
|
749 * @result error code |
|
750 */ |
|
751 TInt HandleLocalStringMaximum( const TItem& aItem ); |
|
752 |
|
753 /** |
|
754 * HandleLocalDelimiter |
|
755 * |
|
756 * @since S60 v5.0 |
|
757 * @param aItem a Hid field item |
|
758 * @result error code |
|
759 */ |
|
760 TInt HandleLocalDelimiter( const TItem& aItem ); |
|
761 |
|
762 /** |
|
763 * CheckMandatoryFieldError |
|
764 * |
|
765 * @since S60 v5.0 |
|
766 * @param aType a field type |
|
767 * @param aAttributes attributes |
|
768 * @result error code |
|
769 */ |
|
770 TInt CheckMandatoryFieldExistence( CField::TType aType, TUint32 aAttributes ); |
|
771 |
|
772 /** |
|
773 * CheckUsageMinAndMaxErrors |
|
774 * |
|
775 * @since S60 v5.0 |
|
776 * @result error code |
|
777 */ |
|
778 TInt CheckUsageMinAndMaxErrors(); |
|
779 |
|
780 /** |
|
781 * CheckDesignatorMinAndMaxErrors |
|
782 * |
|
783 * @since S60 v5.0 |
|
784 * @result error code |
|
785 */ |
|
786 TInt CheckDesignatorMinAndMaxErrors(); |
|
787 |
|
788 /** |
|
789 * CheckStringMinAndMaxErrors |
|
790 * |
|
791 * @since S60 v5.0 |
|
792 * @result error code |
|
793 */ |
|
794 TInt CheckStringMinAndMaxErrors(); |
|
795 |
|
796 /** |
|
797 * CheckMandatoryFieldError |
|
798 * |
|
799 * @since S60 v5.0 |
|
800 * @param aType a field type |
|
801 * @param aAttributes attributes |
|
802 * @result error code |
|
803 */ |
|
804 TInt CheckMandatoryFieldErrors( CField::TType aType, TUint32 aAttributes ); |
|
805 |
|
806 /** |
|
807 * CheckLogicalMinAndMax |
|
808 * Check if logical minimum and maximum must match the number of usage |
|
809 * values |
|
810 * |
|
811 * @since S60 v5.0 |
|
812 * @param aAttributes attributes |
|
813 * @result error code |
|
814 */ |
|
815 void CheckLogicalMinAndMax( TUint32 aAttributes ); |
|
816 |
|
817 /** |
|
818 * CheckMandatoryFieldError |
|
819 * |
|
820 * @since S60 v5.0 |
|
821 * @param aType a field type |
|
822 * @param aAttributes attributes |
|
823 * @result error code |
|
824 */ |
|
825 void CheckFieldBitNeeded( CField::TType aType, TUint32 aAttributes ); |
|
826 |
|
827 /** |
|
828 * HandleItem |
|
829 * |
|
830 * @since S60 v5.0 |
|
831 * @result error code |
|
832 */ |
|
833 void HandleItemL(TItem& aItem); |
|
834 |
|
835 /** |
|
836 * CheckParseErrors |
|
837 * |
|
838 * @since S60 v5.0 |
|
839 * @result error code |
|
840 */ |
|
841 void CheckParseErrors(); |
|
842 |
|
843 /** |
|
844 * ResetParser |
|
845 * |
|
846 * @since S60 v5.0 |
|
847 * @result error code |
|
848 */ |
|
849 void ResetParserL(); |
|
850 |
|
851 private: |
|
852 /** |
|
853 * A bitmask containing the THidItem flags which represent local |
|
854 * (as opposed to main or global) items. |
|
855 */ |
|
856 static const TUint32 KLocalItemMask; |
|
857 |
|
858 /** |
|
859 * A bitmask containing the THidItem flags which represent local |
|
860 * unused items. |
|
861 */ |
|
862 static const TUint32 KUnusedLocalItemsMask; |
|
863 |
|
864 /** |
|
865 * A bitmask containing the THidItem flags which represent mandatory |
|
866 * items. |
|
867 */ |
|
868 static const TUint32 KMandatoryItemMask; |
|
869 |
|
870 /** |
|
871 * A bitmask containing the THidItem flags which represent report |
|
872 * items. |
|
873 */ |
|
874 static const TUint32 KReportItemMask; |
|
875 |
|
876 private: |
|
877 |
|
878 /** |
|
879 * THidItem defineds a set of flags used for keeping track of |
|
880 * which items have been encountered in the report descriptor for |
|
881 * the current report field. The flags are used with the |
|
882 * iItemsDefined and iGlobalItemsDefined data members. |
|
883 */ |
|
884 enum THidItem |
|
885 { |
|
886 EUsagePage = 1<<0, |
|
887 ELogicalMin = 1<<1, |
|
888 ELogicalMax = 1<<2, |
|
889 EReportSize = 1<<3, |
|
890 EReportCount = 1<<4, |
|
891 EReportId = 1<<5, |
|
892 EUsageMin = 1<<6, |
|
893 EUsageMax = 1<<7, |
|
894 EPhysicalMin = 1<<8, |
|
895 EPhysicalMax = 1<<9, |
|
896 EUnit = 1<<10, |
|
897 EUnitExponent = 1<<11, |
|
898 EDesignatorIndex = 1<<12, |
|
899 EDesignatorMin = 1<<13, |
|
900 EDesignatorMax = 1<<14, |
|
901 EStringIndex = 1<<15, |
|
902 EStringMin = 1<<16, |
|
903 EStringMax = 1<<17, |
|
904 EInputReport = 1<<18, |
|
905 EOutputReport = 1<<19, |
|
906 EFeatureReport = 1<<20, |
|
907 EDelimiter = 1<<21, |
|
908 EUsageId = 1<<22 |
|
909 }; |
|
910 |
|
911 /** |
|
912 * HID local tags |
|
913 */ |
|
914 enum THidLocalTags |
|
915 { |
|
916 ELocalUsage = 0x00, |
|
917 ELocalUsageMinimum = 0x01, |
|
918 ELocalUsageMaximum = 0x02, |
|
919 ELocalDesignatorIndex = 0x03, |
|
920 ELocalDesignatorMinimum = 0x04, |
|
921 ELocalDesignatorMaximum = 0x05, |
|
922 ELocalStringIndex = 0x07, |
|
923 ELocalStringMinimum = 0x08, |
|
924 ELocalStringMaximum = 0x09, |
|
925 ELocalDelimiter = 0x0a |
|
926 }; |
|
927 |
|
928 /** |
|
929 * HID global tags |
|
930 */ |
|
931 enum THidGlobalTags |
|
932 { |
|
933 EGlobalUsagePage = 0x00, |
|
934 EGlobalLogicalMinimum = 0x01, |
|
935 EGlobalLogicalMaximum = 0x02, |
|
936 EGlobalPhysicalMinimum = 0x03, |
|
937 EGlobalPhysicalMaximum = 0x04, |
|
938 EGlobalUnitExponent = 0x05, |
|
939 EGlobalUnit = 0x06, |
|
940 EGlobalReportSize = 0x07, |
|
941 EGlobalReportId = 0x08, |
|
942 EGlobalReportCount = 0x09, |
|
943 EGlobalPush = 0x0a, |
|
944 EGlobalPop = 0x0b |
|
945 }; |
|
946 |
|
947 /** |
|
948 * HID main tags |
|
949 */ |
|
950 enum THidMainTags |
|
951 { |
|
952 EMainInput = 0x08, |
|
953 EMainOutput = 0x09, |
|
954 EMainFeature = 0x0b, |
|
955 EMainCollection = 0x0a, |
|
956 EMainEndCollection = 0x0c |
|
957 }; |
|
958 |
|
959 /** |
|
960 * The local state, cleared after each "Main" item |
|
961 * Own. |
|
962 */ |
|
963 CField* iLocal; |
|
964 |
|
965 /** |
|
966 * Current global state |
|
967 */ |
|
968 TParserGlobalState iGlobal; |
|
969 |
|
970 /** |
|
971 * Global state stack, to allow HID descriptor PUSH and POP commands |
|
972 */ |
|
973 RArray<TParserGlobalState> iGlobalStack; |
|
974 |
|
975 // For delimiter handling: |
|
976 // |
|
977 /** |
|
978 * ETrue if currently within a delimiter pair |
|
979 */ |
|
980 TBool iWithinDelimiter; |
|
981 |
|
982 /** |
|
983 * Count of alternate USAGE declarations so far |
|
984 */ |
|
985 TInt iAliasCount; |
|
986 |
|
987 /** |
|
988 * Count of alternate USAGE_MIN declarations |
|
989 */ |
|
990 TInt iAliasCountMin; |
|
991 |
|
992 /** |
|
993 * Count of alternate USAGE_MAX declarations |
|
994 */ |
|
995 TInt iAliasCountMax; |
|
996 |
|
997 /** |
|
998 * The root node of the collection tree |
|
999 * Own. |
|
1000 */ |
|
1001 CReportRoot* iReportRoot; |
|
1002 |
|
1003 /** |
|
1004 * Stack used to create the collection tree |
|
1005 */ |
|
1006 RPointerArray<CCollection> iCollectionStack; |
|
1007 |
|
1008 // Keep track of which items have been seen in the descriptor: |
|
1009 // |
|
1010 /** |
|
1011 * All items forming the current item state |
|
1012 */ |
|
1013 TUint32 iItemsDefined; |
|
1014 |
|
1015 /** |
|
1016 * Global items seen since the last main tag |
|
1017 */ |
|
1018 TUint32 iGlobalItemsDefined; |
|
1019 |
|
1020 /** |
|
1021 * ETrue if a redundant local item is seen |
|
1022 */ |
|
1023 TBool iLocalMultipleUse; |
|
1024 |
|
1025 /** |
|
1026 * Number of the item we're currently processing |
|
1027 */ |
|
1028 TInt iItemNumber; |
|
1029 |
|
1030 /** |
|
1031 * Record of any critical error encountered |
|
1032 */ |
|
1033 TInt iErrorCode; |
|
1034 |
|
1035 /** |
|
1036 * Field count |
|
1037 */ |
|
1038 TInt iFieldCount; |
|
1039 }; |
|
1040 |
|
1041 #endif |