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

Unified 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: 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
Index: Source/modules/webusb/USBEndpoint.cpp
diff --git a/Source/modules/webusb/USBEndpoint.cpp b/Source/modules/webusb/USBEndpoint.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..471c6b7c07f4df82ea545bf618568f6780d66251
--- /dev/null
+++ b/Source/modules/webusb/USBEndpoint.cpp
@@ -0,0 +1,89 @@
+// 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/USBEndpoint.h"
+
+#include "modules/webusb/USBAlternateInterface.h"
+#include "public/platform/modules/webusb/WebUSBDevice.h"
+
+namespace blink {
+
+namespace {
+
+String ConvertDirection(const WebUSBDevice::TransferDirection& direction)
+{
+ switch (direction) {
+ case WebUSBDevice::TransferDirectionIn:
+ return "in";
+ case WebUSBDevice::TransferDirectionOut:
+ return "out";
+ default:
+ ASSERT_NOT_REACHED();
Reilly Grant (use Gerrit) 2015/07/23 23:24:08 If you can convince the compiler these switch stat
Ken Rockot(use gerrit already) 2015/07/28 22:30:38 Acknowledged. I don't think that's realistic witho
+ return "";
+ }
+}
+
+String ConvertType(const WebUSBDeviceInfo::Endpoint::Type& type)
+{
+ switch (type) {
+ case WebUSBDeviceInfo::Endpoint::TypeBulk:
+ return "bulk";
+ case WebUSBDeviceInfo::Endpoint::TypeInterrupt:
+ return "interrupt";
+ case WebUSBDeviceInfo::Endpoint::TypeIsochronous:
+ return "isochronous";
+ default:
+ ASSERT_NOT_REACHED();
+ return "";
+ }
+}
+
+} // namespace
+
+// static
+USBEndpoint* USBEndpoint::create(const USBAlternateInterface* alternate, size_t endpointIndex)
+{
+ return new USBEndpoint(alternate, endpointIndex);
+}
+
+USBEndpoint::USBEndpoint(const USBAlternateInterface* alternate, size_t endpointIndex)
+ : m_alternate(alternate)
+ , m_endpointIndex(endpointIndex)
+{
+}
+
+const WebUSBDeviceInfo::Endpoint& USBEndpoint::info() const
+{
+ const WebUSBDeviceInfo::AlternateInterface& alternateInfo = m_alternate->info();
+ ASSERT(m_endpointIndex < alternateInfo.endpoints.size());
+ return alternateInfo.endpoints[m_endpointIndex];
+}
+
+uint8_t USBEndpoint::endpointNumber() const
+{
+ return info().endpointNumber;
+}
+
+String USBEndpoint::direction() const
+{
+ return ConvertDirection(info().direction);
+}
+
+String USBEndpoint::type() const
+{
+ return ConvertType(info().type);
+}
+
+unsigned USBEndpoint::packetSize() const
+{
+ return info().packetSize;
+}
+
+DEFINE_TRACE(USBEndpoint)
+{
+ visitor->trace(m_alternate);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698