| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/serial/serial_device_enumerator_win.h" | 5 #include "device/serial/serial_device_enumerator_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <devguid.h> | 9 #include <devguid.h> |
| 10 #include <setupapi.h> | 10 #include <setupapi.h> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // value to display_name, and returns whether the operation was successful. | 59 // value to display_name, and returns whether the operation was successful. |
| 60 bool GetDisplayName(const std::string friendly_name, | 60 bool GetDisplayName(const std::string friendly_name, |
| 61 std::string* display_name) { | 61 std::string* display_name) { |
| 62 return RE2::PartialMatch(friendly_name, "(.*) \\(COM[0-9]+\\)", display_name); | 62 return RE2::PartialMatch(friendly_name, "(.*) \\(COM[0-9]+\\)", display_name); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Searches for the vendor ID in the device's hardware ID, assigns its value to | 65 // Searches for the vendor ID in the device's hardware ID, assigns its value to |
| 66 // vendor_id, and returns whether the operation was successful. | 66 // vendor_id, and returns whether the operation was successful. |
| 67 bool GetVendorID(const std::string hardware_id, uint32_t* vendor_id) { | 67 bool GetVendorID(const std::string hardware_id, uint32_t* vendor_id) { |
| 68 std::string vendor_id_str; | 68 std::string vendor_id_str; |
| 69 return RE2::PartialMatch(hardware_id, "VID_([0-9]+)", &vendor_id_str) && | 69 return RE2::PartialMatch(hardware_id, "VID_([0-9a-fA-F]+)", &vendor_id_str) && |
| 70 base::HexStringToUInt(vendor_id_str, vendor_id); | 70 base::HexStringToUInt(vendor_id_str, vendor_id); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Searches for the product ID in the device's product ID, assigns its value to | 73 // Searches for the product ID in the device's product ID, assigns its value to |
| 74 // product_id, and returns whether the operation was successful. | 74 // product_id, and returns whether the operation was successful. |
| 75 bool GetProductID(const std::string hardware_id, uint32_t* product_id) { | 75 bool GetProductID(const std::string hardware_id, uint32_t* product_id) { |
| 76 std::string product_id_str; | 76 std::string product_id_str; |
| 77 return RE2::PartialMatch(hardware_id, "PID_([0-9]+)", &product_id_str) && | 77 return RE2::PartialMatch(hardware_id, "PID_([0-9a-fA-F]+)", |
| 78 &product_id_str) && |
| 78 base::HexStringToUInt(product_id_str, product_id); | 79 base::HexStringToUInt(product_id_str, product_id); |
| 79 } | 80 } |
| 80 | 81 |
| 81 // Returns value clamped to the range of [min, max]. | 82 // Returns value clamped to the range of [min, max]. |
| 82 int Clamp(int value, int min, int max) { | 83 int Clamp(int value, int min, int max) { |
| 83 return std::min(std::max(value, min), max); | 84 return std::min(std::max(value, min), max); |
| 84 } | 85 } |
| 85 | 86 |
| 86 // Returns an array of devices as retrieved through the new method of | 87 // Returns an array of devices as retrieved through the new method of |
| 87 // enumerating serial devices (SetupDi). This new method gives more information | 88 // enumerating serial devices (SetupDi). This new method gives more information |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 184 } |
| 184 | 185 |
| 185 mojo::Array<mojo::String> paths; | 186 mojo::Array<mojo::String> paths; |
| 186 mojo::Array<serial::DeviceInfoPtr> devices; | 187 mojo::Array<serial::DeviceInfoPtr> devices; |
| 187 deviceMap.DecomposeMapTo(&paths, &devices); | 188 deviceMap.DecomposeMapTo(&paths, &devices); |
| 188 | 189 |
| 189 return devices; | 190 return devices; |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace device | 193 } // namespace device |
| OLD | NEW |