diff options
author | keybuk@google.com <keybuk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 23:43:45 +0000 |
---|---|---|
committer | keybuk@google.com <keybuk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 23:43:45 +0000 |
commit | 72bbaccaa082a3ad6fff9bbc1cf70d01dabd79e8 (patch) | |
tree | 4e166217bf3c9cf8b2f88e518080b74a7ca324bf /dbus/test_service.cc | |
parent | 21e0c7bdcf2916d98b5e9668ba6f3e9ddf8b0132 (diff) | |
download | chromium_src-72bbaccaa082a3ad6fff9bbc1cf70d01dabd79e8.zip chromium_src-72bbaccaa082a3ad6fff9bbc1cf70d01dabd79e8.tar.gz chromium_src-72bbaccaa082a3ad6fff9bbc1cf70d01dabd79e8.tar.bz2 |
dbus: clear array values before reading from variant
PopArrayFromVariant() appends values to the existing value, rather
than clearing first like I expected, so using this without clear()
first means the property value accumulates all values and never
loses them.
BUG=none
TEST=unit test included
Change-Id: Ie392a89190f4ad8570a905f24b2f446e1f2bed81
R=satorux@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9809001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128108 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/test_service.cc')
-rw-r--r-- | dbus/test_service.cc | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/dbus/test_service.cc b/dbus/test_service.cc index 443ad9b..986ebd6 100644 --- a/dbus/test_service.cc +++ b/dbus/test_service.cc @@ -336,17 +336,62 @@ void TestService::GetProperty( return; } - if (name != "Version") { + if (name == "Name") { + // Return the previous value for the "Name" property: + // Variant<"TestService"> + Response* response = Response::FromMethodCall(method_call); + MessageWriter writer(response); + + writer.AppendVariantOfString("TestService"); + + response_sender.Run(response); + } else if (name == "Version") { + // Return a new value for the "Version" property: + // Variant<20> + Response* response = Response::FromMethodCall(method_call); + MessageWriter writer(response); + + writer.AppendVariantOfInt16(20); + + response_sender.Run(response); + } else if (name == "Methods") { + // Return the previous value for the "Methods" property: + // Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]> + Response* response = Response::FromMethodCall(method_call); + MessageWriter writer(response); + MessageWriter variant_writer(NULL); + MessageWriter variant_array_writer(NULL); + + writer.OpenVariant("as", &variant_writer); + variant_writer.OpenArray("s", &variant_array_writer); + variant_array_writer.AppendString("Echo"); + variant_array_writer.AppendString("SlowEcho"); + variant_array_writer.AppendString("AsyncEcho"); + variant_array_writer.AppendString("BrokenMethod"); + variant_writer.CloseContainer(&variant_array_writer); + writer.CloseContainer(&variant_writer); + + response_sender.Run(response); + } else if (name == "Objects") { + // Return the previous value for the "Objects" property: + // Variant<[objectpath:"/TestObjectPath"]> + Response* response = Response::FromMethodCall(method_call); + MessageWriter writer(response); + MessageWriter variant_writer(NULL); + MessageWriter variant_array_writer(NULL); + + writer.OpenVariant("ao", &variant_writer); + variant_writer.OpenArray("o", &variant_array_writer); + variant_array_writer.AppendObjectPath(dbus::ObjectPath("/TestObjectPath")); + variant_writer.CloseContainer(&variant_array_writer); + writer.CloseContainer(&variant_writer); + + response_sender.Run(response); + } else { + // Return error. response_sender.Run(NULL); return; } - - Response* response = Response::FromMethodCall(method_call); - MessageWriter writer(response); - - writer.AppendVariantOfInt16(20); - - response_sender.Run(response); } void TestService::SetProperty( |