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

Unified Diff: device/usb/usb_ids.cc

Issue 11344039: Adding USB ID vendor and product lookups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding use_system_usbutils option. Created 8 years, 2 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: device/usb/usb_ids.cc
diff --git a/device/usb/usb_ids.cc b/device/usb/usb_ids.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fbb5b7ee2ed17deb351642aaab97b83deef8f9c1
--- /dev/null
+++ b/device/usb/usb_ids.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 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 "device/usb/usb_ids.h"
+
+#include <stdlib.h>
+
+#include "base/basictypes.h"
+
+namespace device {
+
+namespace {
+
+static int CompareVendors(const void* a, const void* b) {
+ const UsbVendor* vendor_a = static_cast<const UsbVendor*>(a);
+ const UsbVendor* vendor_b = static_cast<const UsbVendor*>(b);
+ return vendor_a->id - vendor_b->id;
+}
+
+static int CompareProducts(const void* a, const void* b) {
+ const UsbProduct* product_a = static_cast<const UsbProduct*>(a);
+ const UsbProduct* product_b = static_cast<const UsbProduct*>(b);
+ return product_a->id - product_b->id;
+}
+
+} // namespace
+
+const UsbVendor* UsbIds::FindVendor(uint16_t vendor_id) {
+ const UsbVendor key = {vendor_id, NULL, 0, NULL};
+ void* result = bsearch(&key, vendors_, vendor_size_, sizeof(vendors_[0]),
+ &CompareVendors);
+ if (!result)
+ return NULL;
+ return static_cast<const UsbVendor*>(result);
+}
+
+const char* UsbIds::GetVendorName(uint16_t vendor_id) {
+ const UsbVendor* vendor = FindVendor(vendor_id);
+ if (!vendor)
+ return NULL;
+ return vendor->name;
+}
+
+const char* UsbIds::GetProductName(uint16_t vendor_id, uint16_t product_id) {
+ const UsbVendor* vendor = FindVendor(vendor_id);
+ if (!vendor)
+ return NULL;
+
+ const UsbProduct key = {product_id, NULL};
+ void* result = bsearch(&key, vendor->products, vendor->product_size,
+ sizeof(vendor->products[0]), &CompareProducts);
+ if (!result)
+ return NULL;
+ return static_cast<const UsbProduct*>(result)->name;
+}
+
+} // namespace device
« device/device.gyp ('K') | « device/usb/usb_ids.h ('k') | device/usb/usb_ids_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698