summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus
diff options
context:
space:
mode:
authorarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 11:52:55 +0000
committerarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 11:52:55 +0000
commita68242f419e2ef9a5167dc59c2caf64c28aee530 (patch)
treea47aae5ddcdd0bc91205f1c19fa991a5d9db45fd /chromeos/dbus
parent9c497f14121c6ee2aed0ea9edfbf73e7faa455be (diff)
downloadchromium_src-a68242f419e2ef9a5167dc59c2caf64c28aee530.zip
chromium_src-a68242f419e2ef9a5167dc59c2caf64c28aee530.tar.gz
chromium_src-a68242f419e2ef9a5167dc59c2caf64c28aee530.tar.bz2
dbus/values_util.h: Add functions to append collection type values to message.
Added functions AppendValueData and AppendValueDataAsVariant to values_util.h. These functions are useful for writing both basic types and variant lists and dictionaries to a message writer. Lists and dictionaries are written with type "av" and "a{sv}", respectively. BUG=359413 TEST=dbus_unittests,chromeos_unittests Review URL: https://codereview.chromium.org/221393004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272167 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus')
-rw-r--r--chromeos/dbus/nfc_client_helpers.cc49
-rw-r--r--chromeos/dbus/nfc_client_helpers.h6
-rw-r--r--chromeos/dbus/nfc_device_client.cc14
-rw-r--r--chromeos/dbus/nfc_tag_client.cc14
4 files changed, 4 insertions, 79 deletions
diff --git a/chromeos/dbus/nfc_client_helpers.cc b/chromeos/dbus/nfc_client_helpers.cc
index b99502b..1469d26 100644
--- a/chromeos/dbus/nfc_client_helpers.cc
+++ b/chromeos/dbus/nfc_client_helpers.cc
@@ -34,55 +34,6 @@ void OnError(const ErrorCallback& error_callback,
error_callback.Run(error_name, error_message);
}
-void AppendValueDataAsVariant(dbus::MessageWriter* writer,
- const base::Value& value) {
- switch (value.GetType()) {
- case base::Value::TYPE_DICTIONARY: {
- const base::DictionaryValue* dictionary = NULL;
- value.GetAsDictionary(&dictionary);
- dbus::MessageWriter variant_writer(NULL);
- dbus::MessageWriter array_writer(NULL);
- writer->OpenVariant("a{sv}", &variant_writer);
- variant_writer.OpenArray("{sv}", &array_writer);
- for (base::DictionaryValue::Iterator iter(*dictionary);
- !iter.IsAtEnd(); iter.Advance()) {
- dbus::MessageWriter entry_writer(NULL);
- array_writer.OpenDictEntry(&entry_writer);
- entry_writer.AppendString(iter.key());
- AppendValueDataAsVariant(&entry_writer, iter.value());
- array_writer.CloseContainer(&entry_writer);
- }
- variant_writer.CloseContainer(&array_writer);
- writer->CloseContainer(&variant_writer);
- break;
- }
- case base::Value::TYPE_LIST: {
- const base::ListValue* list = NULL;
- value.GetAsList(&list);
- dbus::MessageWriter variant_writer(NULL);
- dbus::MessageWriter array_writer(NULL);
- writer->OpenVariant("av", &variant_writer);
- variant_writer.OpenArray("v", &array_writer);
- for (base::ListValue::const_iterator iter = list->begin();
- iter != list->end(); ++iter) {
- const base::Value* value = *iter;
- AppendValueDataAsVariant(&array_writer, *value);
- }
- variant_writer.CloseContainer(&array_writer);
- writer->CloseContainer(&variant_writer);
- break;
- }
- case base::Value::TYPE_BOOLEAN:
- case base::Value::TYPE_INTEGER:
- case base::Value::TYPE_DOUBLE:
- case base::Value::TYPE_STRING:
- dbus::AppendBasicTypeValueDataAsVariant(writer, value);
- break;
- default:
- DLOG(ERROR) << "Unexpected type: " << value.GetType();
- }
-}
-
DBusObjectMap::DBusObjectMap(const std::string& service_name,
Delegate* delegate,
dbus::Bus* bus)
diff --git a/chromeos/dbus/nfc_client_helpers.h b/chromeos/dbus/nfc_client_helpers.h
index be38a72..d50db07 100644
--- a/chromeos/dbus/nfc_client_helpers.h
+++ b/chromeos/dbus/nfc_client_helpers.h
@@ -45,12 +45,6 @@ CHROMEOS_EXPORT void OnSuccess(const base::Closure& callback,
CHROMEOS_EXPORT void OnError(const ErrorCallback& error_callback,
dbus::ErrorResponse* response);
-// Appends any value (basic types and nested types) represented by |value| to
-// the writer |writer| as a variant type.
-// TODO(armansito): Consider moving this to dbus/values_util.h"
-CHROMEOS_EXPORT void AppendValueDataAsVariant(dbus::MessageWriter* writer,
- const base::Value& value);
-
// DBusObjectMap is a simple data structure that facilitates keeping track of
// D-Bus object proxies and properties. It maintains a mapping from object
// paths to object proxy - property structure pairs.
diff --git a/chromeos/dbus/nfc_device_client.cc b/chromeos/dbus/nfc_device_client.cc
index e9833c9..a1976c8 100644
--- a/chromeos/dbus/nfc_device_client.cc
+++ b/chromeos/dbus/nfc_device_client.cc
@@ -11,6 +11,7 @@
#include "chromeos/dbus/nfc_adapter_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
+#include "dbus/values_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
using chromeos::nfc_client_helpers::DBusObjectMap;
@@ -108,18 +109,7 @@ class NfcDeviceClientImpl : public NfcDeviceClient,
dbus::MethodCall method_call(nfc_device::kNfcDeviceInterface,
nfc_device::kPush);
dbus::MessageWriter writer(&method_call);
- dbus::MessageWriter array_writer(NULL);
- dbus::MessageWriter dict_entry_writer(NULL);
- writer.OpenArray("{sv}", &array_writer);
- for (base::DictionaryValue::Iterator iter(attributes);
- !iter.IsAtEnd(); iter.Advance()) {
- array_writer.OpenDictEntry(&dict_entry_writer);
- dict_entry_writer.AppendString(iter.key());
- nfc_client_helpers::AppendValueDataAsVariant(&dict_entry_writer,
- iter.value());
- array_writer.CloseContainer(&dict_entry_writer);
- }
- writer.CloseContainer(&array_writer);
+ dbus::AppendValueData(&writer, attributes);
object_proxy->CallMethodWithErrorCallback(
&method_call,
diff --git a/chromeos/dbus/nfc_tag_client.cc b/chromeos/dbus/nfc_tag_client.cc
index 6c439fa..eae3ef9 100644
--- a/chromeos/dbus/nfc_tag_client.cc
+++ b/chromeos/dbus/nfc_tag_client.cc
@@ -11,6 +11,7 @@
#include "chromeos/dbus/nfc_adapter_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
+#include "dbus/values_util.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
using chromeos::nfc_client_helpers::DBusObjectMap;
@@ -109,18 +110,7 @@ class NfcTagClientImpl : public NfcTagClient,
// Create the arguments.
dbus::MethodCall method_call(nfc_tag::kNfcTagInterface, nfc_tag::kWrite);
dbus::MessageWriter writer(&method_call);
- dbus::MessageWriter array_writer(NULL);
- dbus::MessageWriter dict_entry_writer(NULL);
- writer.OpenArray("{sv}", &array_writer);
- for (base::DictionaryValue::Iterator iter(attributes);
- !iter.IsAtEnd(); iter.Advance()) {
- array_writer.OpenDictEntry(&dict_entry_writer);
- dict_entry_writer.AppendString(iter.key());
- nfc_client_helpers::AppendValueDataAsVariant(&dict_entry_writer,
- iter.value());
- array_writer.CloseContainer(&dict_entry_writer);
- }
- writer.CloseContainer(&array_writer);
+ dbus::AppendValueData(&writer, attributes);
object_proxy->CallMethodWithErrorCallback(
&method_call,