Index: dbus/test_service.cc |
diff --git a/dbus/test_service.cc b/dbus/test_service.cc |
index 1ec207024670be30c001fcf853d0f97efdc08f6a..838035ef40e14a7702f091bb50d86787721e9c41 100644 |
--- a/dbus/test_service.cc |
+++ b/dbus/test_service.cc |
@@ -5,6 +5,7 @@ |
#include "dbus/test_service.h" |
#include "base/bind.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/test/test_timeouts.h" |
#include "base/threading/platform_thread.h" |
#include "dbus/bus.h" |
@@ -430,6 +431,52 @@ void TestService::GetProperty(MethodCall* method_call, |
writer.CloseContainer(&variant_writer); |
response_sender.Run(response.Pass()); |
+ } else if (name == "StringMap") { |
+ // Return the previous value for the "StringMap" property: |
+ // Variant<[{"One": "1"}, {"Two": "2"}, {"Three": "3"}, {"Four": "4"}]> |
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
+ MessageWriter writer(response.get()); |
+ MessageWriter variant_writer(NULL); |
+ MessageWriter variant_array_writer(NULL); |
+ MessageWriter struct_entry_writer(NULL); |
+ |
+ writer.OpenVariant("a{ss}", &variant_writer); |
+ variant_writer.OpenArray("{ss}", &variant_array_writer); |
+ const char* items[] = {"One", "Two", "Three", "Four"}; |
+ for (unsigned i = 0; i < arraysize(items); ++i) { |
+ variant_array_writer.OpenDictEntry(&struct_entry_writer); |
+ struct_entry_writer.AppendString(items[i]); |
+ struct_entry_writer.AppendString(base::UintToString(i + 1)); |
+ variant_array_writer.CloseContainer(&struct_entry_writer); |
+ } |
+ variant_writer.CloseContainer(&variant_array_writer); |
+ writer.CloseContainer(&variant_writer); |
+ } else if (name == "IPList") { |
+ // Return the previous value for the "IPList" property: |
+ // "IPList": Variant<[([0x54, 0x65, 0x73, 0x74, 0x30], 0), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x31], 1), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x32], 2), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x33], 3), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x34], 4)]> |
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
+ MessageWriter writer(response.get()); |
+ MessageWriter variant_writer(NULL); |
+ MessageWriter variant_array_writer(NULL); |
+ MessageWriter struct_entry_writer(NULL); |
+ |
+ writer.OpenVariant("a(ayq)", &variant_writer); |
+ variant_writer.OpenArray("(ayq)", &variant_array_writer); |
+ uint8 ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
+ for (uint16 i = 0; i < 5; ++i) { |
+ variant_array_writer.OpenStruct(&struct_entry_writer); |
+ ip_bytes[4] = 0x30 + i; |
+ struct_entry_writer.AppendArrayOfBytes(ip_bytes, arraysize(ip_bytes)); |
+ struct_entry_writer.AppendUint16(i); |
+ variant_array_writer.CloseContainer(&struct_entry_writer); |
+ } |
+ variant_writer.CloseContainer(&variant_array_writer); |
+ writer.CloseContainer(&variant_writer); |
+ |
} else { |
// Return error. |
response_sender.Run(scoped_ptr<Response>()); |
@@ -582,12 +629,20 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) { |
// "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, |
// "Objects": Variant<[objectpath:"/TestObjectPath"]> |
// "Bytes": Variant<[0x54, 0x65, 0x73, 0x74]> |
+ // "StringMap": Variant<[{"One": "1"}, {"Two": "2"}, {"Three": "3"}, |
+ // {"Four": "4"}]> |
+ // "IPList": Variant<[([0x54, 0x65, 0x73, 0x74, 0x30], 0), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x31], 1), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x32], 2), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x33], 3), |
+ // ([0x54, 0x65, 0x73, 0x74, 0x34], 4)]> |
// } |
MessageWriter array_writer(NULL); |
MessageWriter dict_entry_writer(NULL); |
MessageWriter variant_writer(NULL); |
MessageWriter variant_array_writer(NULL); |
+ MessageWriter struct_entry_writer(NULL); |
writer->OpenArray("{sv}", &array_writer); |
@@ -630,6 +685,37 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) { |
dict_entry_writer.CloseContainer(&variant_writer); |
array_writer.CloseContainer(&dict_entry_writer); |
+ array_writer.OpenDictEntry(&dict_entry_writer); |
+ dict_entry_writer.AppendString("StringMap"); |
+ dict_entry_writer.OpenVariant("a{ss}", &variant_writer); |
+ variant_writer.OpenArray("{ss}", &variant_array_writer); |
+ const char* items[] = {"One", "Two", "Three", "Four"}; |
+ for (unsigned i = 0; i < arraysize(items); ++i) { |
+ variant_array_writer.OpenDictEntry(&struct_entry_writer); |
+ struct_entry_writer.AppendString(items[i]); |
+ struct_entry_writer.AppendString(base::UintToString(i + 1)); |
+ variant_array_writer.CloseContainer(&struct_entry_writer); |
+ } |
+ variant_writer.CloseContainer(&variant_array_writer); |
+ dict_entry_writer.CloseContainer(&variant_writer); |
+ array_writer.CloseContainer(&dict_entry_writer); |
+ |
+ array_writer.OpenDictEntry(&dict_entry_writer); |
+ dict_entry_writer.AppendString("IPList"); |
+ dict_entry_writer.OpenVariant("a(ayq)", &variant_writer); |
+ variant_writer.OpenArray("(ayq)", &variant_array_writer); |
+ uint8 ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30}; |
+ for (uint16 i = 0; i < 5; ++i) { |
+ variant_array_writer.OpenStruct(&struct_entry_writer); |
+ ip_bytes[4] = 0x30 + i; |
+ struct_entry_writer.AppendArrayOfBytes(ip_bytes, arraysize(ip_bytes)); |
+ struct_entry_writer.AppendUint16(i); |
+ variant_array_writer.CloseContainer(&struct_entry_writer); |
+ } |
+ variant_writer.CloseContainer(&variant_array_writer); |
+ dict_entry_writer.CloseContainer(&variant_writer); |
+ array_writer.CloseContainer(&dict_entry_writer); |
+ |
writer->CloseContainer(&array_writer); |
} |