Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1121)

Unified Diff: device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.cc

Issue 1984723006: Add implementation for parsing device info in read/write attribute calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices_dbus_readwrite
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8cfcb3735057f4f2e53b4562d6363e8e3d80909a
--- /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 {
+
+constexpr char kDeviceField[] = "device";
+
+} // 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

Powered by Google App Engine
This is Rietveld 408576698