| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 | 9 |
| 10 namespace device { | 10 namespace device { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() { | 37 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() { |
| 38 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorLinux()); | 38 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorLinux()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() { | 41 SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() { |
| 42 udev_.reset(udev_new()); | 42 udev_.reset(udev_new()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() {} | 45 SerialDeviceEnumeratorLinux::~SerialDeviceEnumeratorLinux() {} |
| 46 | 46 |
| 47 mojo::Array<SerialDeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() { | 47 mojo::Array<serial::DeviceInfoPtr> SerialDeviceEnumeratorLinux::GetDevices() { |
| 48 mojo::Array<SerialDeviceInfoPtr> devices; | 48 mojo::Array<serial::DeviceInfoPtr> devices; |
| 49 ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); | 49 ScopedUdevEnumeratePtr enumerate(udev_enumerate_new(udev_.get())); |
| 50 if (!enumerate) { | 50 if (!enumerate) { |
| 51 LOG(ERROR) << "Serial device enumeration failed."; | 51 LOG(ERROR) << "Serial device enumeration failed."; |
| 52 return devices.Pass(); | 52 return devices.Pass(); |
| 53 } | 53 } |
| 54 if (udev_enumerate_add_match_subsystem(enumerate.get(), kSerialSubsystem)) { | 54 if (udev_enumerate_add_match_subsystem(enumerate.get(), kSerialSubsystem)) { |
| 55 LOG(ERROR) << "Serial device enumeration failed."; | 55 LOG(ERROR) << "Serial device enumeration failed."; |
| 56 return devices.Pass(); | 56 return devices.Pass(); |
| 57 } | 57 } |
| 58 if (udev_enumerate_scan_devices(enumerate.get())) { | 58 if (udev_enumerate_scan_devices(enumerate.get())) { |
| 59 LOG(ERROR) << "Serial device enumeration failed."; | 59 LOG(ERROR) << "Serial device enumeration failed."; |
| 60 return devices.Pass(); | 60 return devices.Pass(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 udev_list_entry* entry = udev_enumerate_get_list_entry(enumerate.get()); | 63 udev_list_entry* entry = udev_enumerate_get_list_entry(enumerate.get()); |
| 64 for (; entry != NULL; entry = udev_list_entry_get_next(entry)) { | 64 for (; entry != NULL; entry = udev_list_entry_get_next(entry)) { |
| 65 ScopedUdevDevicePtr device(udev_device_new_from_syspath( | 65 ScopedUdevDevicePtr device(udev_device_new_from_syspath( |
| 66 udev_.get(), udev_list_entry_get_name(entry))); | 66 udev_.get(), udev_list_entry_get_name(entry))); |
| 67 // TODO(rockot): There may be a better way to filter serial devices here, | 67 // TODO(rockot): There may be a better way to filter serial devices here, |
| 68 // but it's not clear what that would be. Udev will list lots of virtual | 68 // but it's not clear what that would be. Udev will list lots of virtual |
| 69 // devices with no real endpoint to back them anywhere. The presence of | 69 // devices with no real endpoint to back them anywhere. The presence of |
| 70 // a bus identifier (e.g., "pci" or "usb") seems to be a good heuristic | 70 // a bus identifier (e.g., "pci" or "usb") seems to be a good heuristic |
| 71 // for detecting actual devices. | 71 // for detecting actual devices. |
| 72 const char* path = | 72 const char* path = |
| 73 udev_device_get_property_value(device.get(), kHostPathKey); | 73 udev_device_get_property_value(device.get(), kHostPathKey); |
| 74 const char* bus = udev_device_get_property_value(device.get(), kHostBusKey); | 74 const char* bus = udev_device_get_property_value(device.get(), kHostBusKey); |
| 75 if (path != NULL && bus != NULL) { | 75 if (path != NULL && bus != NULL) { |
| 76 SerialDeviceInfoPtr info(SerialDeviceInfo::New()); | 76 serial::DeviceInfoPtr info(serial::DeviceInfo::New()); |
| 77 info->path = path; | 77 info->path = path; |
| 78 | 78 |
| 79 const char* vendor_id = | 79 const char* vendor_id = |
| 80 udev_device_get_property_value(device.get(), kVendorIDKey); | 80 udev_device_get_property_value(device.get(), kVendorIDKey); |
| 81 const char* product_id = | 81 const char* product_id = |
| 82 udev_device_get_property_value(device.get(), kProductIDKey); | 82 udev_device_get_property_value(device.get(), kProductIDKey); |
| 83 const char* product_name = | 83 const char* product_name = |
| 84 udev_device_get_property_value(device.get(), kProductNameKey); | 84 udev_device_get_property_value(device.get(), kProductNameKey); |
| 85 | 85 |
| 86 uint32 int_value; | 86 uint32 int_value; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return devices.Pass(); | 100 return devices.Pass(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void SerialDeviceEnumeratorLinux::UdevDeleter::operator()(udev* handle) { | 103 void SerialDeviceEnumeratorLinux::UdevDeleter::operator()(udev* handle) { |
| 104 udev_unref(handle); | 104 udev_unref(handle); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace device | 107 } // namespace device |
| OLD | NEW |