Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef DEVICE_HID_HID_REPORT_DESCRIPTOR_ITEM_H_ | |
| 6 #define DEVICE_HID_HID_REPORT_DESCRIPTOR_ITEM_H_ | |
| 7 | |
| 8 #include <ostream> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 | |
| 12 namespace device { | |
| 13 | |
| 14 // An element of a HID report descriptor. | |
| 15 class HidReportDescriptorItem { | |
|
Ken Rockot(use gerrit already)
2014/04/21 21:53:53
Use a "private:" specifier please, just for clarit
jracle (use Gerrit)
2014/04/23 07:48:32
Got it
| |
| 16 friend class HidReportDescriptor; | |
| 17 | |
| 18 enum Type { | |
| 19 kTypeMain = 0, | |
| 20 kTypeGlobal = 1, | |
| 21 kTypeLocal = 2, | |
| 22 kTypeReserved = 3 | |
| 23 }; | |
| 24 | |
| 25 enum MainTag { | |
| 26 kMainTagDefault = 0x00, // 0000 | |
| 27 kMainTagInput = 0x08, // 1000 | |
| 28 kMainTagOutput = 0x09, // 1001 | |
| 29 kMainTagFeature = 0x0B, // 1011 | |
| 30 kMainTagCollection = 0x0A, // 1010 | |
| 31 kMainTagEndCollection = 0x0C // 1100 | |
| 32 }; | |
| 33 | |
| 34 enum GlobalTag { | |
| 35 kGlobalTagUsagePage = 0x00, // 0000 | |
| 36 kGlobalTagLogicalMinimum = 0x01, // 0001 | |
| 37 kGlobalTagLogicalMaximum = 0x02, // 0010 | |
| 38 kGlobalTagPhysicalMinimum = 0x03, // 0011 | |
| 39 kGlobalTagPhysicalMaximum = 0x04, // 0100 | |
| 40 kGlobalTagUnitExponent = 0x05, // 0101 | |
| 41 kGlobalTagUnit = 0x06, // 0110 | |
| 42 kGlobalTagReportSize = 0x07, // 0111 | |
| 43 kGlobalTagReportId = 0x08, // 1000 | |
| 44 kGlobalTagReportCount = 0x09, // 1001 | |
| 45 kGlobalTagPush = 0x0A, // 1010 | |
| 46 kGlobalTagPop = 0x0B // 1011 | |
| 47 }; | |
| 48 | |
| 49 enum LocalTag { | |
| 50 kLocalTagUsage = 0x00, // 0000 | |
| 51 kLocalTagUsageMinimum = 0x01, // 0001 | |
| 52 kLocalTagUsageMaximum = 0x02, // 0010 | |
| 53 kLocalTagDesignatorIndex = 0x03, // 0011 | |
| 54 kLocalTagDesignatorMinimum = 0x04, // 0100 | |
| 55 kLocalTagDesignatorMaximum = 0x05, // 0101 | |
| 56 kLocalTagStringIndex = 0x07, // 0111 | |
| 57 kLocalTagStringMinimum = 0x08, // 1000 | |
| 58 kLocalTagStringMaximum = 0x09, // 1001 | |
| 59 kLocalTagDelimiter = 0x0A // 1010 | |
| 60 }; | |
| 61 | |
| 62 enum ReservedTag { | |
| 63 kReservedTagLong = 0xF // 1111 | |
| 64 }; | |
| 65 | |
| 66 public: | |
| 67 enum Tag { | |
| 68 kTagDefault = kMainTagDefault << 2 | kTypeMain, | |
| 69 kTagInput = kMainTagInput << 2 | kTypeMain, | |
| 70 kTagOutput = kMainTagOutput << 2 | kTypeMain, | |
| 71 kTagFeature = kMainTagFeature << 2 | kTypeMain, | |
| 72 kTagCollection = kMainTagCollection << 2 | kTypeMain, | |
| 73 kTagEndCollection = kMainTagEndCollection << 2 | kTypeMain, | |
| 74 kTagUsagePage = kGlobalTagUsagePage << 2 | kTypeGlobal, | |
| 75 kTagLogicalMinimum = kGlobalTagLogicalMinimum << 2 | kTypeGlobal, | |
| 76 kTagLogicalMaximum = kGlobalTagLogicalMaximum << 2 | kTypeGlobal, | |
| 77 kTagPhysicalMinimum = kGlobalTagPhysicalMinimum << 2 | kTypeGlobal, | |
| 78 kTagPhysicalMaximum = kGlobalTagPhysicalMaximum << 2 | kTypeGlobal, | |
| 79 kTagUnitExponent = kGlobalTagUnitExponent << 2 | kTypeGlobal, | |
| 80 kTagUnit = kGlobalTagUnit << 2 | kTypeGlobal, | |
| 81 kTagReportSize = kGlobalTagReportSize << 2 | kTypeGlobal, | |
| 82 kTagReportId = kGlobalTagReportId << 2 | kTypeGlobal, | |
| 83 kTagReportCount = kGlobalTagReportCount << 2 | kTypeGlobal, | |
| 84 kTagPush = kGlobalTagPush << 2 | kTypeGlobal, | |
| 85 kTagPop = kGlobalTagPop << 2 | kTypeGlobal, | |
| 86 kTagUsage = kLocalTagUsage << 2 | kTypeLocal, | |
| 87 kTagUsageMinimum = kLocalTagUsageMinimum << 2 | kTypeLocal, | |
| 88 kTagUsageMaximum = kLocalTagUsageMaximum << 2 | kTypeLocal, | |
| 89 kTagDesignatorIndex = kLocalTagDesignatorIndex << 2 | kTypeLocal, | |
| 90 kTagDesignatorMinimum = kLocalTagDesignatorMinimum << 2 | kTypeLocal, | |
| 91 kTagDesignatorMaximum = kLocalTagDesignatorMaximum << 2 | kTypeLocal, | |
| 92 kTagStringIndex = kLocalTagStringIndex << 2 | kTypeLocal, | |
| 93 kTagStringMinimum = kLocalTagStringMinimum << 2 | kTypeLocal, | |
| 94 kTagStringMaximum = kLocalTagStringMaximum << 2 | kTypeLocal, | |
| 95 kTagDelimiter = kLocalTagDelimiter << 2 | kTypeLocal, | |
| 96 kTagLong = kReservedTagLong << 2 | kTypeReserved | |
| 97 }; | |
| 98 | |
| 99 // HID Input/Output/Feature report information. | |
| 100 // Can be retrieved from GetShortData() | |
| 101 // when item.tag() == HidReportDescriptorItem::kTagInput | |
| 102 // or HidReportDescriptorItem::kTagOutput | |
| 103 // or HidReportDescriptorItem::kTagFeature | |
| 104 struct ReportInfo { | |
| 105 uint8_t data_or_constant : 1; | |
| 106 uint8_t array_or_variable : 1; | |
| 107 uint8_t absolute_or_relative : 1; | |
| 108 uint8_t wrap : 1; | |
| 109 uint8_t linear : 1; | |
| 110 uint8_t preferred : 1; | |
| 111 uint8_t null : 1; | |
| 112 uint8_t reserved_1 : 1; | |
| 113 uint8_t bit_field_or_buffer : 1; | |
| 114 uint8_t reserved_2 : 1; | |
| 115 }; | |
| 116 | |
| 117 // HID collection type. | |
| 118 // Can be retrieved from GetShortData() | |
| 119 // when item.tag() == HidReportDescriptorItem::kTagCollection | |
| 120 enum CollectionType { | |
| 121 kCollectionTypePhysical, | |
| 122 kCollectionTypeApplication, | |
| 123 kCollectionTypeLogical, | |
| 124 kCollectionTypeReport, | |
| 125 kCollectionTypeNamedArray, | |
| 126 kCollectionTypeUsageSwitch, | |
| 127 kCollectionTypeUsageModifier, | |
| 128 kCollectionTypeReserved, | |
| 129 kCollectionTypeVendor | |
| 130 }; | |
| 131 | |
| 132 private: | |
| 133 HidReportDescriptorItem(const uint8_t* bytes, | |
| 134 HidReportDescriptorItem* previous); | |
| 135 | |
| 136 public: | |
| 137 ~HidReportDescriptorItem() {} | |
| 138 | |
| 139 // Previous element in report descriptor. | |
| 140 // Owned by descriptor instance. | |
| 141 HidReportDescriptorItem* previous() const { | |
| 142 return previous_; | |
| 143 }; | |
| 144 // Next element in report descriptor. | |
| 145 // Owned by descriptor instance. | |
| 146 HidReportDescriptorItem* next() const { | |
| 147 return next_; | |
| 148 }; | |
| 149 // Parent element in report descriptor. | |
| 150 // Owned by descriptor instance. | |
| 151 // Can be NULL. | |
| 152 HidReportDescriptorItem* parent() const { | |
| 153 return parent_; | |
| 154 }; | |
| 155 // Level in Parent-Children relationship tree. | |
| 156 // 0 for top-level items (parent()==NULL). | |
| 157 // 1 if parent() is top-level. | |
| 158 // 2 if parent() has a top-level parent. Etc. | |
| 159 size_t GetDepth() const; | |
| 160 Tag tag() const { return tag_; } | |
| 161 // Returns true for a long item, false otherwise. | |
| 162 bool IsLong() const; | |
| 163 // Raw data of a short item. | |
| 164 // Not valid for a long item. | |
| 165 uint32_t GetShortData() const; | |
| 166 | |
| 167 static CollectionType GetCollectionTypeFromValue(uint32_t value); | |
| 168 | |
| 169 private: | |
| 170 size_t GetHeaderSize() const; | |
| 171 size_t payloadSize() const { return payload_size_; } | |
|
Ken Rockot(use gerrit already)
2014/04/21 21:53:53
payload_size() please.
jracle (use Gerrit)
2014/04/23 07:48:32
Sorry OK
| |
| 172 size_t GetSize() const; | |
| 173 | |
| 174 HidReportDescriptorItem* previous_; | |
| 175 HidReportDescriptorItem* next_; | |
| 176 HidReportDescriptorItem* parent_; | |
| 177 Tag tag_; | |
| 178 uint32_t shortData_; | |
| 179 size_t payload_size_; | |
| 180 }; | |
| 181 | |
| 182 std::ostream& operator<<(std::ostream& os, const HidReportDescriptorItem& item); | |
| 183 | |
| 184 } // namespace device | |
| 185 | |
| 186 #endif // DEVICE_HID_HID_REPORT_DESCRIPTOR_ITEM_H_ | |
| OLD | NEW |