| 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_linux.h" | 5 #include "device/serial/serial_device_enumerator_linux.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
|  | 8 #include <utility> | 
| 8 | 9 | 
| 9 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" | 
| 11 | 12 | 
| 12 namespace device { | 13 namespace device { | 
| 13 | 14 | 
| 14 namespace { | 15 namespace { | 
| 15 | 16 | 
| 16 const char kSerialSubsystem[] = "tty"; | 17 const char kSerialSubsystem[] = "tty"; | 
| 17 | 18 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 32   udev_.reset(udev_new()); | 33   udev_.reset(udev_new()); | 
| 33 } | 34 } | 
| 34 | 35 | 
| 35 SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() {} | 36 SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() {} | 
| 36 | 37 | 
| 37 mojo::Array<serial::DeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() { | 38 mojo::Array<serial::DeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() { | 
| 38   mojo::Array<serial::DeviceInfoPtr> devices(0); | 39   mojo::Array<serial::DeviceInfoPtr> devices(0); | 
| 39   ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); | 40   ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); | 
| 40   if (!enumerate) { | 41   if (!enumerate) { | 
| 41     LOG(ERROR) << "Serial device enumeration failed."; | 42     LOG(ERROR) << "Serial device enumeration failed."; | 
| 42     return devices.Pass(); | 43     return devices; | 
| 43   } | 44   } | 
| 44   if (udev_enumerate_add_match_subsystem(enumerate.get(), kSerialSubsystem)) { | 45   if (udev_enumerate_add_match_subsystem(enumerate.get(), kSerialSubsystem)) { | 
| 45     LOG(ERROR) << "Serial device enumeration failed."; | 46     LOG(ERROR) << "Serial device enumeration failed."; | 
| 46     return devices.Pass(); | 47     return devices; | 
| 47   } | 48   } | 
| 48   if (udev_enumerate_scan_devices(enumerate.get())) { | 49   if (udev_enumerate_scan_devices(enumerate.get())) { | 
| 49     LOG(ERROR) << "Serial device enumeration failed."; | 50     LOG(ERROR) << "Serial device enumeration failed."; | 
| 50     return devices.Pass(); | 51     return devices; | 
| 51   } | 52   } | 
| 52 | 53 | 
| 53   udev_list_entry* entry = udev_enumerate_get_list_entry(enumerate.get()); | 54   udev_list_entry* entry = udev_enumerate_get_list_entry(enumerate.get()); | 
| 54   for (; entry != NULL; entry = udev_list_entry_get_next(entry)) { | 55   for (; entry != NULL; entry = udev_list_entry_get_next(entry)) { | 
| 55     ScopedUdevDevicePtr device(udev_device_new_from_syspath( | 56     ScopedUdevDevicePtr device(udev_device_new_from_syspath( | 
| 56         udev_.get(), udev_list_entry_get_name(entry))); | 57         udev_.get(), udev_list_entry_get_name(entry))); | 
| 57     // TODO(rockot): There may be a better way to filter serial devices here, | 58     // TODO(rockot): There may be a better way to filter serial devices here, | 
| 58     // but it's not clear what that would be. Udev will list lots of virtual | 59     // but it's not clear what that would be. Udev will list lots of virtual | 
| 59     // devices with no real endpoint to back them anywhere. The presence of | 60     // devices with no real endpoint to back them anywhere. The presence of | 
| 60     // a bus identifier (e.g., "pci" or "usb") seems to be a good heuristic | 61     // a bus identifier (e.g., "pci" or "usb") seems to be a good heuristic | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 77       if (vendor_id && base::HexStringToUInt(vendor_id, &int_value)) { | 78       if (vendor_id && base::HexStringToUInt(vendor_id, &int_value)) { | 
| 78         info->vendor_id = int_value; | 79         info->vendor_id = int_value; | 
| 79         info->has_vendor_id = true; | 80         info->has_vendor_id = true; | 
| 80       } | 81       } | 
| 81       if (product_id && base::HexStringToUInt(product_id, &int_value)) { | 82       if (product_id && base::HexStringToUInt(product_id, &int_value)) { | 
| 82         info->product_id = int_value; | 83         info->product_id = int_value; | 
| 83         info->has_product_id = true; | 84         info->has_product_id = true; | 
| 84       } | 85       } | 
| 85       if (product_name) | 86       if (product_name) | 
| 86         info->display_name = product_name; | 87         info->display_name = product_name; | 
| 87       devices.push_back(info.Pass()); | 88       devices.push_back(std::move(info)); | 
| 88     } | 89     } | 
| 89   } | 90   } | 
| 90   return devices.Pass(); | 91   return devices; | 
| 91 } | 92 } | 
| 92 | 93 | 
| 93 }  // namespace device | 94 }  // namespace device | 
| OLD | NEW | 
|---|