| 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 { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const char kSerialSubsystem[] = "tty"; | 14 const char kSerialSubsystem[] = "tty"; |
| 15 | 15 |
| 16 const char kHostPathKey[] = "DEVNAME"; | 16 const char kHostPathKey[] = "DEVNAME"; |
| 17 const char kHostBusKey[] = "ID_BUS"; | 17 const char kHostBusKey[] = "ID_BUS"; |
| 18 const char kVendorIDKey[] = "ID_VENDOR_ID"; | 18 const char kVendorIDKey[] = "ID_VENDOR_ID"; |
| 19 const char kProductIDKey[] = "ID_MODEL_ID"; | 19 const char kProductIDKey[] = "ID_MODEL_ID"; |
| 20 const char kProductNameKey[] = "ID_MODEL"; | 20 const char kProductNameKey[] = "ID_MODEL"; |
| 21 | 21 |
| 22 struct UdevEnumerateDeleter { | 22 } // namespace |
| 23 void operator()(udev_enumerate* enumerate) { | |
| 24 udev_enumerate_unref(enumerate); | |
| 25 } | |
| 26 }; | |
| 27 | |
| 28 struct UdevDeviceDeleter { | |
| 29 void operator()(udev_device* device) { udev_device_unref(device); } | |
| 30 }; | |
| 31 | |
| 32 typedef scoped_ptr<udev_enumerate, UdevEnumerateDeleter> ScopedUdevEnumeratePtr; | |
| 33 typedef scoped_ptr<udev_device, UdevDeviceDeleter> ScopedUdevDevicePtr; | |
| 34 } | |
| 35 | 23 |
| 36 // static | 24 // static |
| 37 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() { | 25 scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() { |
| 38 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorLinux()); | 26 return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorLinux()); |
| 39 } | 27 } |
| 40 | 28 |
| 41 SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() { | 29 SerialDeviceEnumeratorLinux::SerialDeviceEnumeratorLinux() { |
| 42 udev_.reset(udev_new()); | 30 udev_.reset(udev_new()); |
| 43 } | 31 } |
| 44 | 32 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 info->has_product_id = true; | 81 info->has_product_id = true; |
| 94 } | 82 } |
| 95 if (product_name) | 83 if (product_name) |
| 96 info->display_name = product_name; | 84 info->display_name = product_name; |
| 97 devices.push_back(info.Pass()); | 85 devices.push_back(info.Pass()); |
| 98 } | 86 } |
| 99 } | 87 } |
| 100 return devices.Pass(); | 88 return devices.Pass(); |
| 101 } | 89 } |
| 102 | 90 |
| 103 void SerialDeviceEnumeratorLinux::UdevDeleter::operator()(udev* handle) { | |
| 104 udev_unref(handle); | |
| 105 } | |
| 106 | |
| 107 } // namespace device | 91 } // namespace device |
| OLD | NEW |