|
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 |
|
19 #ifndef T_ITEM_H |
|
20 #define T_ITEM_H |
|
21 |
|
22 #include <e32std.h> |
|
23 |
|
24 /** |
|
25 * HID item class |
|
26 * A HID report descriptor is comprised of a sequence of "items" |
|
27 * that provide information about the device. Items consist of a |
|
28 * header and zero or more bytes of data. The header contains the item |
|
29 * type (main/global/local), an item "tag" (subtype) and the item size. |
|
30 * Items can be "short" (containing a maximum of 4 bytes of data) or |
|
31 * "long" (a maximum of 255 bytes of data). |
|
32 |
|
33 * A TItem represents a single HID report descriptor item. It is |
|
34 * constructed from an eight bit non-modifiable (Symbian-) descriptor, |
|
35 * which is assumed to contain report (HID-) descriptor data. |
|
36 * |
|
37 * @lib generichid.lib |
|
38 * @since S60 v5.0 |
|
39 */ |
|
40 class TItem |
|
41 { |
|
42 public: |
|
43 /** |
|
44 * The possible item types: main, global or local. Item type is |
|
45 * a two-bit field -- the 11b value is reserved for "long items", which |
|
46 * are only used for vendor-specific commands. |
|
47 */ |
|
48 enum TItemType |
|
49 { |
|
50 EMain = 0, //!< Input, output, feature and begin or end collection |
|
51 EGlobal = 1, //!< Global item items affect all subsequent fields |
|
52 ELocal = 2, //!< Local items only persist until the next main item |
|
53 EReserved = 3 //!< No defined use in the current HID standard (v1.11) |
|
54 }; |
|
55 |
|
56 public: |
|
57 |
|
58 /** |
|
59 * The constructor takes a an eight bit non-modifiable (Symbian-) |
|
60 * descriptor containing report (HID-) descriptor data. |
|
61 * The item tag, type, data size and offset are calculated here. |
|
62 * |
|
63 * @since S60 v5.0 |
|
64 * @param aRawData The raw item data, represented as a Symbian |
|
65 * descriptor. The item data is assumed to be at the beginning of the |
|
66 * descriptor. The size of the TDesC8 may be greater than the size |
|
67 * of the item, as the item size will be calculated from the raw HID |
|
68 * descriptor data. Of course, the TDesC8 should be at least as |
|
69 * long as the raw item data. |
|
70 */ |
|
71 TItem(const TDesC8& aRawData); |
|
72 |
|
73 /** |
|
74 * DataSize() returns the size of the item data in bytes. This |
|
75 * is the total item size minus the size of any header information. |
|
76 * (A short item header is a single byte, a long item header is |
|
77 * three bytes long.) |
|
78 * |
|
79 * @since S60 v5.0 |
|
80 * @return The size, in bytes, of the item data. Range 0-255. |
|
81 */ |
|
82 TInt DataSize() const; |
|
83 |
|
84 /** |
|
85 * Tag() returns the tag (subtype) value for this item. |
|
86 * |
|
87 * @since S60 v5.0 |
|
88 * @return The item tag. |
|
89 */ |
|
90 TInt Tag() const; |
|
91 |
|
92 /** |
|
93 * Data() returns the data associated with the item, represented as a |
|
94 * 32-bit unsigned integer. This is only meaningful if the data length |
|
95 * is less than 4 bytes. |
|
96 * |
|
97 * @since S60 v5.0 |
|
98 * @return The item data as a 32-bit unsigned integer. |
|
99 */ |
|
100 TUint32 Data() const; |
|
101 |
|
102 /** |
|
103 * SignedData() returns the data associated with the item, |
|
104 * represented as a 32-bit signed integer. This is only |
|
105 * meaningful if the data length is less than 4 bytes. |
|
106 * |
|
107 * @since S60 v5.0 |
|
108 * @return The item data as a 32-bit signed integer. |
|
109 */ |
|
110 TInt32 SignedData() const; |
|
111 |
|
112 /** |
|
113 * Returns the byte at the given offset within the item data block. |
|
114 * |
|
115 * @since S60 v5.0 |
|
116 * @param aIndex The index within the data block for the current tag. |
|
117 * @return The data at the specified index. |
|
118 */ |
|
119 TUint8 operator[](TInt aIndex) const; |
|
120 |
|
121 /** |
|
122 * Type() returns the item type (e.g. "global"). |
|
123 * |
|
124 * @since S60 v5.0 |
|
125 * @return The item type. |
|
126 */ |
|
127 TItemType Type() const; |
|
128 |
|
129 /** |
|
130 * Check if item is main |
|
131 * |
|
132 * @since S60 v5.0 |
|
133 * @return ETrue if item type is "main" |
|
134 */ |
|
135 TBool IsMain() const; |
|
136 |
|
137 /** |
|
138 * Check if item is local |
|
139 * |
|
140 * @since S60 v5.0 |
|
141 * @return ETrue if item type is "local" |
|
142 */ |
|
143 TBool IsLocal() const; |
|
144 |
|
145 /** |
|
146 * Check if item is global |
|
147 * |
|
148 * @since S60 v5.0 |
|
149 * @return ETrue if item type is "global" |
|
150 */ |
|
151 TBool IsGlobal() const; |
|
152 |
|
153 /** |
|
154 * Check if item is global |
|
155 * |
|
156 * @since S60 v5.0 |
|
157 * @return ETrue if this is a long item |
|
158 */ |
|
159 TBool IsLong() const; |
|
160 |
|
161 /** |
|
162 * ItemSize() returns the total size of this item, including the |
|
163 * header data. |
|
164 * |
|
165 * @since S60 v5.0 |
|
166 * @return The total size of this item, in bytes. |
|
167 */ |
|
168 TInt ItemSize() const; |
|
169 |
|
170 private: |
|
171 /** |
|
172 * Pointer to the raw report descriptor data |
|
173 */ |
|
174 TPtrC8 iRawData; |
|
175 |
|
176 /** |
|
177 * Item data size |
|
178 */ |
|
179 |
|
180 TInt iSize; |
|
181 /** |
|
182 * Item tag value |
|
183 */ |
|
184 TInt iTag; |
|
185 |
|
186 /** |
|
187 * Offset in bytes of the data block |
|
188 */ |
|
189 TInt iDataOffset; |
|
190 |
|
191 /** |
|
192 * Item type |
|
193 */ |
|
194 TItemType iType; |
|
195 }; |
|
196 |
|
197 #endif |
|
198 |