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

Side by Side Diff: chromeos/dbus/nfc_client_helpers.cc

Issue 221393004: dbus/values_util.h: Add functions to append collection type values to message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed keybuk@'s comment, unmarked old functions as deprecated as they are useful. Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/nfc_client_helpers.h ('k') | chromeos/dbus/nfc_device_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chromeos/dbus/nfc_client_helpers.h" 5 #include "chromeos/dbus/nfc_client_helpers.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "dbus/values_util.h" 8 #include "dbus/values_util.h"
9 9
10 namespace chromeos { 10 namespace chromeos {
(...skipping 16 matching lines...) Expand all
27 dbus::MessageReader reader(response); 27 dbus::MessageReader reader(response);
28 error_name = response->GetErrorName(); 28 error_name = response->GetErrorName();
29 reader.PopString(&error_message); 29 reader.PopString(&error_message);
30 } else { 30 } else {
31 error_name = kNoResponseError; 31 error_name = kNoResponseError;
32 error_message = ""; 32 error_message = "";
33 } 33 }
34 error_callback.Run(error_name, error_message); 34 error_callback.Run(error_name, error_message);
35 } 35 }
36 36
37 void AppendValueDataAsVariant(dbus::MessageWriter* writer,
38 const base::Value& value) {
39 switch (value.GetType()) {
40 case base::Value::TYPE_DICTIONARY: {
41 const base::DictionaryValue* dictionary = NULL;
42 value.GetAsDictionary(&dictionary);
43 dbus::MessageWriter variant_writer(NULL);
44 dbus::MessageWriter array_writer(NULL);
45 writer->OpenVariant("a{sv}", &variant_writer);
46 variant_writer.OpenArray("{sv}", &array_writer);
47 for (base::DictionaryValue::Iterator iter(*dictionary);
48 !iter.IsAtEnd(); iter.Advance()) {
49 dbus::MessageWriter entry_writer(NULL);
50 array_writer.OpenDictEntry(&entry_writer);
51 entry_writer.AppendString(iter.key());
52 AppendValueDataAsVariant(&entry_writer, iter.value());
53 array_writer.CloseContainer(&entry_writer);
54 }
55 variant_writer.CloseContainer(&array_writer);
56 writer->CloseContainer(&variant_writer);
57 break;
58 }
59 case base::Value::TYPE_LIST: {
60 const base::ListValue* list = NULL;
61 value.GetAsList(&list);
62 dbus::MessageWriter variant_writer(NULL);
63 dbus::MessageWriter array_writer(NULL);
64 writer->OpenVariant("av", &variant_writer);
65 variant_writer.OpenArray("v", &array_writer);
66 for (base::ListValue::const_iterator iter = list->begin();
67 iter != list->end(); ++iter) {
68 const base::Value* value = *iter;
69 AppendValueDataAsVariant(&array_writer, *value);
70 }
71 variant_writer.CloseContainer(&array_writer);
72 writer->CloseContainer(&variant_writer);
73 break;
74 }
75 case base::Value::TYPE_BOOLEAN:
76 case base::Value::TYPE_INTEGER:
77 case base::Value::TYPE_DOUBLE:
78 case base::Value::TYPE_STRING:
79 dbus::AppendBasicTypeValueDataAsVariant(writer, value);
80 break;
81 default:
82 DLOG(ERROR) << "Unexpected type: " << value.GetType();
83 }
84 }
85
86 DBusObjectMap::DBusObjectMap(const std::string& service_name, 37 DBusObjectMap::DBusObjectMap(const std::string& service_name,
87 Delegate* delegate, 38 Delegate* delegate,
88 dbus::Bus* bus) 39 dbus::Bus* bus)
89 : bus_(bus), 40 : bus_(bus),
90 service_name_(service_name), 41 service_name_(service_name),
91 delegate_(delegate) { 42 delegate_(delegate) {
92 DCHECK(bus_); 43 DCHECK(bus_);
93 DCHECK(delegate_); 44 DCHECK(delegate_);
94 } 45 }
95 46
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 NfcPropertySet* properties = 244 NfcPropertySet* properties =
294 object_map->GetObjectProperties(object_proxy_path); 245 object_map->GetObjectProperties(object_proxy_path);
295 if (properties) 246 if (properties)
296 return properties; 247 return properties;
297 } 248 }
298 return NULL; 249 return NULL;
299 } 250 }
300 251
301 } // namespace nfc_client_helpers 252 } // namespace nfc_client_helpers
302 } // namespace chromeos 253 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/nfc_client_helpers.h ('k') | chromeos/dbus/nfc_device_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698