summaryrefslogtreecommitdiffstats
path: root/dbus/test_service.cc
diff options
context:
space:
mode:
authorvlaviano@chromium.org <vlaviano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 04:57:42 +0000
committervlaviano@chromium.org <vlaviano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 04:57:42 +0000
commit9aa74ccbcaf9f29f03ca4f0dbccd896ef4098118 (patch)
tree353aaadbdf70b223d8e0cbe71572bd9814c7e580 /dbus/test_service.cc
parentcb8a5468be6eb5072a8e9173b554448c0d06e111 (diff)
downloadchromium_src-9aa74ccbcaf9f29f03ca4f0dbccd896ef4098118.zip
chromium_src-9aa74ccbcaf9f29f03ca4f0dbccd896ef4098118.tar.gz
chromium_src-9aa74ccbcaf9f29f03ca4f0dbccd896ef4098118.tar.bz2
chrome: dbus: support asynchronous method replies
BUG=chromium-os:23241 TEST=Unit tests and manual testing on device. Change-Id: Iab009ddbd12dea1e12299ae0ddccd4e430d9cf97 Review URL: http://codereview.chromium.org/8728020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/test_service.cc')
-rw-r--r--dbus/test_service.cc48
1 files changed, 38 insertions, 10 deletions
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
index b0207b0..ea8e360 100644
--- a/dbus/test_service.cc
+++ b/dbus/test_service.cc
@@ -13,8 +13,8 @@
namespace dbus {
-// Echo, SlowEcho, BrokenMethod.
-const int TestService::kNumMethodsToExport = 3;
+// Echo, SlowEcho, AsyncEcho, BrokenMethod.
+const int TestService::kNumMethodsToExport = 4;
TestService::Options::Options() {
}
@@ -148,6 +148,15 @@ void TestService::Run(MessageLoop* message_loop) {
exported_object_->ExportMethod(
"org.chromium.TestInterface",
+ "AsyncEcho",
+ base::Bind(&TestService::AsyncEcho,
+ base::Unretained(this)),
+ base::Bind(&TestService::OnExported,
+ base::Unretained(this)));
+ ++num_methods;
+
+ exported_object_->ExportMethod(
+ "org.chromium.TestInterface",
"BrokenMethod",
base::Bind(&TestService::BrokenMethod,
base::Unretained(this)),
@@ -163,25 +172,44 @@ void TestService::Run(MessageLoop* message_loop) {
message_loop->Run();
}
-Response* TestService::Echo(MethodCall* method_call) {
+void TestService::Echo(MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
MessageReader reader(method_call);
std::string text_message;
- if (!reader.PopString(&text_message))
- return NULL;
+ if (!reader.PopString(&text_message)) {
+ response_sender.Run(NULL);
+ return;
+ }
Response* response = Response::FromMethodCall(method_call);
MessageWriter writer(response);
writer.AppendString(text_message);
- return response;
+ response_sender.Run(response);
}
-Response* TestService::SlowEcho(MethodCall* method_call) {
+void TestService::SlowEcho(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms());
- return Echo(method_call);
+ Echo(method_call, response_sender);
+}
+
+void TestService::AsyncEcho(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ // Schedule a call to Echo() to send an asynchronous response after we return.
+ message_loop()->PostDelayedTask(FROM_HERE,
+ base::Bind(&TestService::Echo,
+ base::Unretained(this),
+ method_call,
+ response_sender),
+ TestTimeouts::tiny_timeout_ms());
}
-Response* TestService::BrokenMethod(MethodCall* method_call) {
- return NULL;
+void TestService::BrokenMethod(
+ MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ response_sender.Run(NULL);
}
} // namespace dbus