Chromium Code Reviews| Index: tools/battor_agent/battor_finder.cc |
| diff --git a/tools/battor_agent/battor_finder.cc b/tools/battor_agent/battor_finder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e4549f5e71146c91951452c998e820eeee49e7a |
| --- /dev/null |
| +++ b/tools/battor_agent/battor_finder.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
sky
2016/01/21 22:59:20
nit: 2016
charliea (OOO until 10-5)
2016/01/22 16:11:03
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "tools/battor_agent/battor_finder.h" |
| + |
| +#include "device/serial/serial.mojom.h" |
| +#include "device/serial/serial_device_enumerator.h" |
| +#include "mojo/public/cpp/bindings/array.h" |
| + |
| +namespace battor { |
| + |
| +namespace { |
| + |
| +// The USB display name prefix that all BattOrs have. |
| +const char kBattOrDisplayNamePrefix[] = "BattOr"; |
| + |
| +} // namespace |
| + |
| +// Returns the path of the first BattOr that we find. |
| +std::string BattOrFinder::FindBattOr() { |
| + scoped_ptr<device::SerialDeviceEnumerator> serial_device_enumerator = |
| + device::SerialDeviceEnumerator::Create(); |
| + |
| + mojo::Array<device::serial::DeviceInfoPtr> devices = |
| + serial_device_enumerator->GetDevices(); |
| + |
| + for (size_t i = 0; i < devices.size(); i++) { |
| + std::string display_name = devices[i]->display_name.get(); |
| + |
| + if (display_name.find(kBattOrDisplayNamePrefix) != std::string::npos) { |
| + return devices[i]->path; |
| + } |
| + } |
| + |
| + return ""; |
|
sky
2016/01/21 22:59:20
nit: std::string()
charliea (OOO until 10-5)
2016/01/22 16:11:03
Done.
|
| +} |
| + |
| +} // namespace battor |