Chromium Code Reviews| Index: device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.cc |
| diff --git a/device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.cc b/device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fa6c690d2b55c5f0868061046c94e0bf79085612 |
| --- /dev/null |
| +++ b/device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.cc |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.h" |
| + |
| +#include <string> |
| + |
| +#include "base/logging.h" |
| +#include "dbus/message.h" |
| +#include "dbus/object_path.h" |
| + |
| +namespace bluez { |
| + |
| +namespace { |
| + |
| +const char kDeviceField[] = "device"; |
|
xiyuan
2016/05/17 18:06:29
nit: const -> constexpr
learned from my other rev
rkc
2016/05/17 18:42:59
Makes sense, since constexpr is compile-time.
Done
|
| + |
| +} // namespace |
| + |
| +dbus::ObjectPath ReadDevicePath(dbus::MessageReader* reader) { |
| + dbus::MessageReader array_reader(nullptr); |
| + if (!reader->PopArray(&array_reader)) |
| + return dbus::ObjectPath(); |
| + |
| + // Go through all the keys in the dictionary to find the device key. |
| + while (array_reader.HasMoreData()) { |
| + dbus::MessageReader dict_entry_reader(nullptr); |
| + std::string key; |
| + if (!array_reader.PopDictEntry(&dict_entry_reader) || |
| + !dict_entry_reader.PopString(&key)) { |
| + return dbus::ObjectPath(); |
| + } else if (key == kDeviceField) { |
| + dbus::ObjectPath device_path; |
| + dict_entry_reader.PopVariantOfObjectPath(&device_path); |
| + return device_path; |
| + } |
| + } |
| + |
| + return dbus::ObjectPath(); |
| +} |
| + |
| +} // namespace bluez |