Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: Source/modules/webusb/USBEndpoint.cpp

Issue 1245363002: Add WebUSB bindings and client interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: iface ctors, OWNERS, rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/webusb/USBEndpoint.h ('k') | Source/modules/webusb/USBEndpoint.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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::TransferDirectionIn:
20 return "in";
21 case WebUSBDevice::TransferDirectionOut:
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::TypeBulk:
33 return "bulk";
34 case WebUSBDeviceInfo::Endpoint::TypeInterrupt:
35 return "interrupt";
36 case WebUSBDeviceInfo::Endpoint::TypeIsochronous:
37 return "isochronous";
38 default:
39 ASSERT_NOT_REACHED();
40 return "";
41 }
42 }
43
44 } // namespace
45
46 // static
47 USBEndpoint* USBEndpoint::create(const USBAlternateInterface* alternate, size_t endpointIndex)
48 {
49 return new USBEndpoint(alternate, endpointIndex);
50 }
51
52 // static
53 USBEndpoint* USBEndpoint::create(const USBAlternateInterface* alternate, size_t endpointIndex, ExceptionState& exceptionState)
54 {
55 if (endpointIndex < alternate->info().endpoints.size())
56 return new USBEndpoint(alternate, endpointIndex);
57 exceptionState.throwRangeError("Invalid endpoint index.");
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 }
66
67 const WebUSBDeviceInfo::Endpoint& USBEndpoint::info() const
68 {
69 const WebUSBDeviceInfo::AlternateInterface& alternateInfo = m_alternate->inf o();
70 ASSERT(m_endpointIndex < alternateInfo.endpoints.size());
71 return alternateInfo.endpoints[m_endpointIndex];
72 }
73
74 uint8_t USBEndpoint::endpointNumber() const
75 {
76 return info().endpointNumber;
77 }
78
79 String USBEndpoint::direction() const
80 {
81 return convertDirection(info().direction);
82 }
83
84 String USBEndpoint::type() const
85 {
86 return convertType(info().type);
87 }
88
89 unsigned USBEndpoint::packetSize() const
90 {
91 return info().packetSize;
92 }
93
94 DEFINE_TRACE(USBEndpoint)
95 {
96 visitor->trace(m_alternate);
97 }
98
99 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webusb/USBEndpoint.h ('k') | Source/modules/webusb/USBEndpoint.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698