Chromium Code Reviews| 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/USBEndpoint.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ExceptionState.h" | |
| 9 #include "modules/webusb/USBAlternateInterface.h" | |
| 10 #include "public/platform/modules/webusb/WebUSBDevice.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 String convertDirection(const WebUSBDevice::TransferDirection& direction) | |
| 17 { | |
| 18 switch (direction) { | |
| 19 case WebUSBDevice::TransferDirection::In: | |
| 20 return "in"; | |
| 21 case WebUSBDevice::TransferDirection::Out: | |
| 22 return "out"; | |
| 23 default: | |
| 24 ASSERT_NOT_REACHED(); | |
| 25 return ""; | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 String convertType(const WebUSBDeviceInfo::Endpoint::Type& type) | |
| 30 { | |
| 31 switch (type) { | |
| 32 case WebUSBDeviceInfo::Endpoint::Type::Bulk: | |
| 33 return "bulk"; | |
| 34 case WebUSBDeviceInfo::Endpoint::Type::Interrupt: | |
| 35 return "interrupt"; | |
| 36 case WebUSBDeviceInfo::Endpoint::Type::Isochronous: | |
| 37 return "isochronous"; | |
| 38 default: | |
| 39 ASSERT_NOT_REACHED(); | |
| 40 return ""; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 USBEndpoint* USBEndpoint::create(const USBAlternateInterface* alternate, size_t endpointIndex) | |
| 47 { | |
| 48 return new USBEndpoint(alternate, endpointIndex); | |
| 49 } | |
| 50 | |
| 51 USBEndpoint* USBEndpoint::create(const USBAlternateInterface* alternate, size_t endpointNumber, ExceptionState& exceptionState) | |
|
Reilly Grant (use Gerrit)
2015/08/04 19:18:09
endpointNumber needs endpointDirection to be uniqu
Ken Rockot(use gerrit already)
2015/08/04 19:29:14
Done.
| |
| 52 { | |
| 53 for (size_t i = 0; i < alternate->info().endpoints.size(); ++i) { | |
| 54 if (alternate->info().endpoints[i].endpointNumber == endpointNumber) | |
| 55 return USBEndpoint::create(alternate, i); | |
| 56 } | |
| 57 exceptionState.throwRangeError("Invalid endpoint index."); | |
|
Reilly Grant (use Gerrit)
2015/08/04 19:18:09
"Invalid endpoint number."
Ken Rockot(use gerrit already)
2015/08/04 19:29:14
Done.
| |
| 58 return nullptr; | |
| 59 } | |
| 60 | |
| 61 USBEndpoint::USBEndpoint(const USBAlternateInterface* alternate, size_t endpoint Index) | |
| 62 : m_alternate(alternate) | |
| 63 , m_endpointIndex(endpointIndex) | |
| 64 { | |
| 65 ASSERT(m_alternate); | |
| 66 ASSERT(m_endpointIndex < m_alternate->info().endpoints.size()); | |
| 67 } | |
| 68 | |
| 69 const WebUSBDeviceInfo::Endpoint& USBEndpoint::info() const | |
| 70 { | |
| 71 const WebUSBDeviceInfo::AlternateInterface& alternateInfo = m_alternate->inf o(); | |
| 72 ASSERT(m_endpointIndex < alternateInfo.endpoints.size()); | |
| 73 return alternateInfo.endpoints[m_endpointIndex]; | |
| 74 } | |
| 75 | |
| 76 uint8_t USBEndpoint::endpointNumber() const | |
| 77 { | |
| 78 return info().endpointNumber; | |
| 79 } | |
| 80 | |
| 81 String USBEndpoint::direction() const | |
| 82 { | |
| 83 return convertDirection(info().direction); | |
| 84 } | |
| 85 | |
| 86 String USBEndpoint::type() const | |
| 87 { | |
| 88 return convertType(info().type); | |
| 89 } | |
| 90 | |
| 91 unsigned USBEndpoint::packetSize() const | |
| 92 { | |
| 93 return info().packetSize; | |
| 94 } | |
| 95 | |
| 96 DEFINE_TRACE(USBEndpoint) | |
| 97 { | |
| 98 visitor->trace(m_alternate); | |
| 99 } | |
| 100 | |
| 101 } // namespace blink | |
| OLD | NEW |