OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "device/usb/usb_ids.h" | |
6 | |
7 #include <stdlib.h> | |
8 | |
9 #include "base/basictypes.h" | |
10 | |
11 using device::UsbProduct; | |
bryeung
2012/10/31 15:01:27
seems weird to have these when you're in a device/
Garret Kelly
2012/10/31 15:24:26
Done.
| |
12 using device::UsbVendor; | |
13 | |
14 namespace { | |
15 | |
16 static int CompareVendors(const void* a, const void* b) { | |
17 const UsbVendor* vendor_a = static_cast<const UsbVendor*>(a); | |
18 const UsbVendor* vendor_b = static_cast<const UsbVendor*>(b); | |
19 return vendor_a->id - vendor_b->id; | |
20 } | |
21 | |
22 static int CompareProducts(const void* a, const void* b) { | |
23 const UsbProduct* product_a = static_cast<const UsbProduct*>(a); | |
24 const UsbProduct* product_b = static_cast<const UsbProduct*>(b); | |
25 return product_a->id - product_b->id; | |
26 } | |
27 | |
28 } // namespace | |
29 | |
30 namespace device { | |
bryeung
2012/10/31 15:01:27
blank line after namespace lines
Garret Kelly
2012/10/31 15:24:26
Done.
| |
31 const UsbVendor* UsbIds::FindVendor(uint16_t vendor_id) { | |
32 const UsbVendor key = {vendor_id, NULL, 0, NULL}; | |
33 void* result = bsearch(&key, vendors_, vendor_size_, sizeof(vendors_[0]), | |
34 &CompareVendors); | |
35 if (!result) | |
36 return NULL; | |
37 | |
bryeung
2012/10/31 15:01:27
either remove this blank line or add it below for
Garret Kelly
2012/10/31 15:24:26
Done.
| |
38 return static_cast<const UsbVendor*>(result); | |
39 } | |
40 | |
41 const char* UsbIds::GetVendorName(uint16_t vendor_id) { | |
42 const UsbVendor* vendor = FindVendor(vendor_id); | |
43 if (!vendor) | |
44 return NULL; | |
45 return vendor->name; | |
46 } | |
47 | |
48 const char* UsbIds::GetProductName(uint16_t vendor_id, uint16_t product_id) { | |
49 const UsbVendor* vendor = FindVendor(vendor_id); | |
50 if (!vendor) | |
51 return NULL; | |
52 | |
53 const UsbProduct key = {product_id, NULL}; | |
54 void* result = bsearch(&key, vendor->products, vendor->product_size, | |
55 sizeof(vendor->products[0]), &CompareProducts); | |
56 if (!result) | |
57 return NULL; | |
58 return static_cast<const UsbProduct*>(result)->name; | |
59 } | |
60 | |
61 } // namespace device | |
OLD | NEW |