1 // Copyright (c) 2012 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.
5 #include "device/usb/usb_ids.h"
9 #include "base/basictypes.h"
15 static int CompareVendors(const void* a
, const void* b
) {
16 const UsbVendor
* vendor_a
= static_cast<const UsbVendor
*>(a
);
17 const UsbVendor
* vendor_b
= static_cast<const UsbVendor
*>(b
);
18 return vendor_a
->id
- vendor_b
->id
;
21 static int CompareProducts(const void* a
, const void* b
) {
22 const UsbProduct
* product_a
= static_cast<const UsbProduct
*>(a
);
23 const UsbProduct
* product_b
= static_cast<const UsbProduct
*>(b
);
24 return product_a
->id
- product_b
->id
;
29 const UsbVendor
* UsbIds::FindVendor(uint16_t vendor_id
) {
30 const UsbVendor key
= {vendor_id
, NULL
, 0, NULL
};
31 void* result
= bsearch(&key
, vendors_
, vendor_size_
, sizeof(vendors_
[0]),
35 return static_cast<const UsbVendor
*>(result
);
38 const char* UsbIds::GetVendorName(uint16_t vendor_id
) {
39 const UsbVendor
* vendor
= FindVendor(vendor_id
);
45 const char* UsbIds::GetProductName(uint16_t vendor_id
, uint16_t product_id
) {
46 const UsbVendor
* vendor
= FindVendor(vendor_id
);
50 const UsbProduct key
= {product_id
, NULL
};
51 void* result
= bsearch(&key
, vendor
->products
, vendor
->product_size
,
52 sizeof(vendor
->products
[0]), &CompareProducts
);
55 return static_cast<const UsbProduct
*>(result
)->name
;