OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "config.h" |
| 6 #include "modules/webusb/USBInterface.h" |
| 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "modules/webusb/USBConfiguration.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t
interfaceIndex) |
| 14 { |
| 15 return new USBInterface(configuration, interfaceIndex); |
| 16 } |
| 17 |
| 18 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t
interfaceNumber, ExceptionState& exceptionState) |
| 19 { |
| 20 for (size_t i = 0; i < configuration->info().interfaces.size(); ++i) { |
| 21 if (configuration->info().interfaces[i].interfaceNumber == interfaceNumb
er) |
| 22 return new USBInterface(configuration, i); |
| 23 } |
| 24 exceptionState.throwRangeError("Invalid interface index."); |
| 25 return nullptr; |
| 26 } |
| 27 |
| 28 USBInterface::USBInterface(const USBConfiguration* configuration, size_t interfa
ceIndex) |
| 29 : m_configuration(configuration) |
| 30 , m_interfaceIndex(interfaceIndex) |
| 31 { |
| 32 ASSERT(m_configuration); |
| 33 ASSERT(m_interfaceIndex < m_configuration->info().interfaces.size()); |
| 34 } |
| 35 |
| 36 const WebUSBDeviceInfo::Interface& USBInterface::info() const |
| 37 { |
| 38 return m_configuration->info().interfaces[m_interfaceIndex]; |
| 39 } |
| 40 |
| 41 uint8_t USBInterface::interfaceNumber() const |
| 42 { |
| 43 return info().interfaceNumber; |
| 44 } |
| 45 |
| 46 DEFINE_TRACE(USBInterface) |
| 47 { |
| 48 visitor->trace(m_configuration); |
| 49 } |
| 50 |
| 51 } // namespace blink |
OLD | NEW |