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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webusb/USBAlternateInterface.h ('k') | Source/modules/webusb/USBAlternateInterface.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webusb/USBAlternateInterface.cpp
diff --git a/Source/modules/webusb/USBAlternateInterface.cpp b/Source/modules/webusb/USBAlternateInterface.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7178688cc02284b221f4528d6da5d208f12889ca
--- /dev/null
+++ b/Source/modules/webusb/USBAlternateInterface.cpp
@@ -0,0 +1,80 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/webusb/USBAlternateInterface.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "modules/webusb/USBEndpoint.h"
+#include "modules/webusb/USBInterface.h"
+
+namespace blink {
+
+// static
+USBAlternateInterface* USBAlternateInterface::create(const USBInterface* interface, size_t alternateIndex)
+{
+ return new USBAlternateInterface(interface, alternateIndex);
+}
+
+// static
+USBAlternateInterface* USBAlternateInterface::create(const USBInterface* interface, size_t alternateIndex, ExceptionState& exceptionState)
+{
+ if (alternateIndex < interface->info().alternates.size())
+ return new USBAlternateInterface(interface, alternateIndex);
+ exceptionState.throwRangeError("Invalid alternate index.");
+ return nullptr;
+}
+
+USBAlternateInterface::USBAlternateInterface(const USBInterface* interface, size_t alternateIndex)
+ : m_interface(interface)
+ , m_alternateIndex(alternateIndex)
+{
+}
+
+const WebUSBDeviceInfo::AlternateInterface& USBAlternateInterface::info() const
+{
+ const WebUSBDeviceInfo::Interface& interfaceInfo = m_interface->info();
+ ASSERT(m_alternateIndex < interfaceInfo.alternates.size());
+ return interfaceInfo.alternates[m_alternateIndex];
+}
+
+uint8_t USBAlternateInterface::alternateSetting() const
+{
+ return info().alternateSetting;
+}
+
+uint8_t USBAlternateInterface::interfaceClass() const
+{
+ return info().classCode;
+}
+
+uint8_t USBAlternateInterface::interfaceSubclass() const
+{
+ return info().subclassCode;
+}
+
+uint8_t USBAlternateInterface::interfaceProtocol() const
+{
+ return info().protocolCode;
+}
+
+String USBAlternateInterface::interfaceName() const
+{
+ return info().interfaceName;
+}
+
+HeapVector<Member<USBEndpoint>> USBAlternateInterface::endpoints() const
+{
+ HeapVector<Member<USBEndpoint>> endpoints;
+ for (size_t i = 0; i < info().endpoints.size(); ++i)
+ endpoints.append(USBEndpoint::create(this, i));
+ return endpoints;
+}
+
+DEFINE_TRACE(USBAlternateInterface)
+{
+ visitor->trace(m_interface);
+}
+
+} // namespace blink
« 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