OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "modules/webusb/USBEndpoint.h" | 5 #include "modules/webusb/USBEndpoint.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
9 #include "device/usb/public/interfaces/device.mojom-blink.h" | 9 #include "device/usb/public/interfaces/device.mojom-blink.h" |
10 #include "modules/webusb/USBAlternateInterface.h" | 10 #include "modules/webusb/USBAlternateInterface.h" |
11 | 11 |
12 using device::usb::blink::EndpointType; | 12 using device::mojom::blink::UsbEndpointType; |
13 using device::usb::blink::TransferDirection; | 13 using device::mojom::blink::UsbTransferDirection; |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 String ConvertDirectionToEnum(const TransferDirection& direction) { | 19 String ConvertDirectionToEnum(const UsbTransferDirection& direction) { |
20 switch (direction) { | 20 switch (direction) { |
21 case TransferDirection::INBOUND: | 21 case UsbTransferDirection::INBOUND: |
22 return "in"; | 22 return "in"; |
23 case TransferDirection::OUTBOUND: | 23 case UsbTransferDirection::OUTBOUND: |
24 return "out"; | 24 return "out"; |
25 default: | 25 default: |
26 ASSERT_NOT_REACHED(); | 26 ASSERT_NOT_REACHED(); |
27 return ""; | 27 return ""; |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 String ConvertTypeToEnum(const EndpointType& type) { | 31 String ConvertTypeToEnum(const UsbEndpointType& type) { |
32 switch (type) { | 32 switch (type) { |
33 case EndpointType::BULK: | 33 case UsbEndpointType::BULK: |
34 return "bulk"; | 34 return "bulk"; |
35 case EndpointType::INTERRUPT: | 35 case UsbEndpointType::INTERRUPT: |
36 return "interrupt"; | 36 return "interrupt"; |
37 case EndpointType::ISOCHRONOUS: | 37 case UsbEndpointType::ISOCHRONOUS: |
38 return "isochronous"; | 38 return "isochronous"; |
39 default: | 39 default: |
40 ASSERT_NOT_REACHED(); | 40 ASSERT_NOT_REACHED(); |
41 return ""; | 41 return ""; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 USBEndpoint* USBEndpoint::Create(const USBAlternateInterface* alternate, | 47 USBEndpoint* USBEndpoint::Create(const USBAlternateInterface* alternate, |
48 size_t endpoint_index) { | 48 size_t endpoint_index) { |
49 return new USBEndpoint(alternate, endpoint_index); | 49 return new USBEndpoint(alternate, endpoint_index); |
50 } | 50 } |
51 | 51 |
52 USBEndpoint* USBEndpoint::Create(const USBAlternateInterface* alternate, | 52 USBEndpoint* USBEndpoint::Create(const USBAlternateInterface* alternate, |
53 size_t endpoint_number, | 53 size_t endpoint_number, |
54 const String& direction, | 54 const String& direction, |
55 ExceptionState& exception_state) { | 55 ExceptionState& exception_state) { |
56 TransferDirection mojo_direction = direction == "in" | 56 UsbTransferDirection mojo_direction = direction == "in" |
57 ? TransferDirection::INBOUND | 57 ? UsbTransferDirection::INBOUND |
58 : TransferDirection::OUTBOUND; | 58 : UsbTransferDirection::OUTBOUND; |
59 const auto& endpoints = alternate->Info().endpoints; | 59 const auto& endpoints = alternate->Info().endpoints; |
60 for (size_t i = 0; i < endpoints.size(); ++i) { | 60 for (size_t i = 0; i < endpoints.size(); ++i) { |
61 const auto& endpoint = endpoints[i]; | 61 const auto& endpoint = endpoints[i]; |
62 if (endpoint->endpoint_number == endpoint_number && | 62 if (endpoint->endpoint_number == endpoint_number && |
63 endpoint->direction == mojo_direction) | 63 endpoint->direction == mojo_direction) |
64 return USBEndpoint::Create(alternate, i); | 64 return USBEndpoint::Create(alternate, i); |
65 } | 65 } |
66 exception_state.ThrowRangeError( | 66 exception_state.ThrowRangeError( |
67 "No such endpoint exists in the given alternate interface."); | 67 "No such endpoint exists in the given alternate interface."); |
68 return nullptr; | 68 return nullptr; |
69 } | 69 } |
70 | 70 |
71 USBEndpoint::USBEndpoint(const USBAlternateInterface* alternate, | 71 USBEndpoint::USBEndpoint(const USBAlternateInterface* alternate, |
72 size_t endpoint_index) | 72 size_t endpoint_index) |
73 : alternate_(alternate), endpoint_index_(endpoint_index) { | 73 : alternate_(alternate), endpoint_index_(endpoint_index) { |
74 ASSERT(alternate_); | 74 ASSERT(alternate_); |
75 ASSERT(endpoint_index_ < alternate_->Info().endpoints.size()); | 75 ASSERT(endpoint_index_ < alternate_->Info().endpoints.size()); |
76 } | 76 } |
77 | 77 |
78 const device::usb::blink::EndpointInfo& USBEndpoint::Info() const { | 78 const device::mojom::blink::UsbEndpointInfo& USBEndpoint::Info() const { |
79 const device::usb::blink::AlternateInterfaceInfo& alternate_info = | 79 const device::mojom::blink::UsbAlternateInterfaceInfo& alternate_info = |
80 alternate_->Info(); | 80 alternate_->Info(); |
81 ASSERT(endpoint_index_ < alternate_info.endpoints.size()); | 81 ASSERT(endpoint_index_ < alternate_info.endpoints.size()); |
82 return *alternate_info.endpoints[endpoint_index_]; | 82 return *alternate_info.endpoints[endpoint_index_]; |
83 } | 83 } |
84 | 84 |
85 String USBEndpoint::direction() const { | 85 String USBEndpoint::direction() const { |
86 return ConvertDirectionToEnum(Info().direction); | 86 return ConvertDirectionToEnum(Info().direction); |
87 } | 87 } |
88 | 88 |
89 String USBEndpoint::type() const { | 89 String USBEndpoint::type() const { |
90 return ConvertTypeToEnum(Info().type); | 90 return ConvertTypeToEnum(Info().type); |
91 } | 91 } |
92 | 92 |
93 DEFINE_TRACE(USBEndpoint) { | 93 DEFINE_TRACE(USBEndpoint) { |
94 visitor->Trace(alternate_); | 94 visitor->Trace(alternate_); |
95 } | 95 } |
96 | 96 |
97 } // namespace blink | 97 } // namespace blink |
OLD | NEW |