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

Side by Side Diff: Source/modules/webusb/USBAlternateInterface.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
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/USBAlternateInterface.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "modules/webusb/USBEndpoint.h"
10 #include "modules/webusb/USBInterface.h"
11
12 namespace blink {
13
14 // static
15 USBAlternateInterface* USBAlternateInterface::create(const USBInterface* interfa ce, size_t alternateIndex)
16 {
17 return new USBAlternateInterface(interface, alternateIndex);
18 }
19
20 // static
21 USBAlternateInterface* USBAlternateInterface::create(const USBInterface* interfa ce, size_t alternateIndex, ExceptionState& exceptionState)
22 {
23 if (alternateIndex < interface->info().alternates.size())
24 return new USBAlternateInterface(interface, alternateIndex);
25 exceptionState.throwRangeError("Invalid alternate index.");
26 return nullptr;
27 }
28
29 USBAlternateInterface::USBAlternateInterface(const USBInterface* interface, size _t alternateIndex)
30 : m_interface(interface)
31 , m_alternateIndex(alternateIndex)
32 {
33 }
34
35 const WebUSBDeviceInfo::AlternateInterface& USBAlternateInterface::info() const
36 {
37 const WebUSBDeviceInfo::Interface& interfaceInfo = m_interface->info();
38 ASSERT(m_alternateIndex < interfaceInfo.alternates.size());
39 return interfaceInfo.alternates[m_alternateIndex];
40 }
41
42 uint8_t USBAlternateInterface::alternateSetting() const
43 {
44 return info().alternateSetting;
45 }
46
47 uint8_t USBAlternateInterface::interfaceClass() const
48 {
49 return info().classCode;
50 }
51
52 uint8_t USBAlternateInterface::interfaceSubclass() const
53 {
54 return info().subclassCode;
55 }
56
57 uint8_t USBAlternateInterface::interfaceProtocol() const
58 {
59 return info().protocolCode;
60 }
61
62 String USBAlternateInterface::interfaceName() const
63 {
64 return info().interfaceName;
65 }
66
67 HeapVector<Member<USBEndpoint>> USBAlternateInterface::endpoints() const
68 {
69 HeapVector<Member<USBEndpoint>> endpoints;
70 for (size_t i = 0; i < info().endpoints.size(); ++i)
71 endpoints.append(USBEndpoint::create(this, i));
72 return endpoints;
73 }
74
75 DEFINE_TRACE(USBAlternateInterface)
76 {
77 visitor->trace(m_interface);
78 }
79
80 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webusb/USBAlternateInterface.h ('k') | Source/modules/webusb/USBAlternateInterface.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698