| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/usb_descriptors.h" | 5 #include "device/usb/usb_descriptors.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 base::Bind(callback, base::Passed(&index_map))); | 79 base::Bind(callback, base::Passed(&index_map))); |
| 80 for (const auto& map_entry : iterator_map) { | 80 for (const auto& map_entry : iterator_map) { |
| 81 ReadStringDescriptor( | 81 ReadStringDescriptor( |
| 82 device_handle, map_entry.first, language_id, | 82 device_handle, map_entry.first, language_id, |
| 83 base::Bind(&StoreStringDescriptor, map_entry.second, barrier)); | 83 base::Bind(&StoreStringDescriptor, map_entry.second, barrier)); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 UsbEndpointDescriptor::UsbEndpointDescriptor() | 89 UsbEndpointDescriptor::UsbEndpointDescriptor( |
| 90 : address(0), | 90 uint8_t address, |
| 91 direction(USB_DIRECTION_INBOUND), | 91 UsbEndpointDirection direction, |
| 92 maximum_packet_size(0), | 92 uint16_t maximum_packet_size, |
| 93 synchronization_type(USB_SYNCHRONIZATION_NONE), | 93 UsbSynchronizationType synchronization_type, |
| 94 transfer_type(USB_TRANSFER_CONTROL), | 94 UsbTransferType transfer_type, |
| 95 usage_type(USB_USAGE_DATA), | 95 UsbUsageType usage_type, |
| 96 polling_interval(0) { | 96 uint16_t polling_interval) |
| 97 } | 97 : address(address), |
| 98 direction(direction), |
| 99 maximum_packet_size(maximum_packet_size), |
| 100 synchronization_type(synchronization_type), |
| 101 transfer_type(transfer_type), |
| 102 usage_type(usage_type), |
| 103 polling_interval(polling_interval) {} |
| 98 | 104 |
| 99 UsbEndpointDescriptor::~UsbEndpointDescriptor() { | 105 UsbEndpointDescriptor::~UsbEndpointDescriptor() = default; |
| 100 } | |
| 101 | 106 |
| 102 UsbInterfaceDescriptor::UsbInterfaceDescriptor() | 107 UsbInterfaceDescriptor::UsbInterfaceDescriptor(uint8_t interface_number, |
| 103 : interface_number(0), | 108 uint8_t alternate_setting, |
| 104 alternate_setting(0), | 109 uint8_t interface_class, |
| 105 interface_class(0), | 110 uint8_t interface_subclass, |
| 106 interface_subclass(0), | 111 uint8_t interface_protocol) |
| 107 interface_protocol(0) { | 112 : interface_number(interface_number), |
| 108 } | 113 alternate_setting(alternate_setting), |
| 114 interface_class(interface_class), |
| 115 interface_subclass(interface_subclass), |
| 116 interface_protocol(interface_protocol) {} |
| 109 | 117 |
| 110 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() { | 118 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() = default; |
| 111 } | |
| 112 | 119 |
| 113 UsbConfigDescriptor::UsbConfigDescriptor() | 120 UsbConfigDescriptor::UsbConfigDescriptor(uint8_t configuration_value, |
| 114 : configuration_value(0), | 121 bool self_powered, |
| 115 self_powered(false), | 122 bool remote_wakeup, |
| 116 remote_wakeup(false), | 123 uint16_t maximum_power) |
| 117 maximum_power(0) { | 124 : configuration_value(configuration_value), |
| 118 } | 125 self_powered(self_powered), |
| 126 remote_wakeup(remote_wakeup), |
| 127 maximum_power(maximum_power) {} |
| 119 | 128 |
| 120 UsbConfigDescriptor::~UsbConfigDescriptor() { | 129 UsbConfigDescriptor::~UsbConfigDescriptor() = default; |
| 121 } | |
| 122 | 130 |
| 123 bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor, | 131 bool ParseUsbStringDescriptor(const std::vector<uint8_t>& descriptor, |
| 124 base::string16* output) { | 132 base::string16* output) { |
| 125 if (descriptor.size() < 2 || descriptor[1] != kStringDescriptorType) | 133 if (descriptor.size() < 2 || descriptor[1] != kStringDescriptorType) |
| 126 return false; | 134 return false; |
| 127 | 135 |
| 128 // Let the device return a buffer larger than the actual string but prefer the | 136 // Let the device return a buffer larger than the actual string but prefer the |
| 129 // length reported inside the descriptor. | 137 // length reported inside the descriptor. |
| 130 size_t length = descriptor[0]; | 138 size_t length = descriptor[0]; |
| 131 length = std::min(length, descriptor.size()); | 139 length = std::min(length, descriptor.size()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 149 callback.Run(std::move(index_map)); | 157 callback.Run(std::move(index_map)); |
| 150 return; | 158 return; |
| 151 } | 159 } |
| 152 | 160 |
| 153 ReadStringDescriptor(device_handle, 0, 0, | 161 ReadStringDescriptor(device_handle, 0, 0, |
| 154 base::Bind(&OnReadLanguageIds, device_handle, | 162 base::Bind(&OnReadLanguageIds, device_handle, |
| 155 base::Passed(&index_map), callback)); | 163 base::Passed(&index_map), callback)); |
| 156 } | 164 } |
| 157 | 165 |
| 158 } // namespace device | 166 } // namespace device |
| OLD | NEW |