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

Unified Diff: dbus/test_service.cc

Issue 7491029: Implement Bus and ObjectProxy classes for our D-Bus library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: another clang challenge Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/test_service.cc
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c25f803c3079b55ca26a81291bab6478c943d58e
--- /dev/null
+++ b/dbus/test_service.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "dbus/test_service.h"
+
+#include "base/bind.h"
+#include "base/threading/platform_thread.h"
+#include "dbus/bus.h"
+#include "dbus/exported_object.h"
+#include "dbus/message.h"
+
+namespace dbus {
+
+const int TestService::kSlowEchoSleepMs = 100; // In milliseconds.
+
+TestService::TestService()
+ : base::Thread("TestService"),
+ service_started_(false),
+ on_service_started_(&service_started_lock_) {
+}
+
+TestService::~TestService() {
+}
+
+void TestService::StartService() {
+ base::Thread::Options thread_options;
+ thread_options.message_loop_type = MessageLoop::TYPE_IO;
+ StartWithOptions(thread_options);
+}
+
+void TestService::WaitUntilServiceIsStarted() {
+ message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestService::OnServiceStarted,
+ base::Unretained(this)));
+ base::AutoLock auto_lock(service_started_lock_);
+ while (!service_started_)
+ on_service_started_.Wait();
+}
+
+void TestService::OnServiceStarted() {
+ base::AutoLock auto_lock(service_started_lock_);
+ service_started_ = true;
+ on_service_started_.Signal();
+}
+
+void TestService::Run(MessageLoop* message_loop) {
+ Bus::Options bus_options;
+ bus_options.bus_type = Bus::SESSION;
+ bus_options.connection_type = Bus::PRIVATE;
+ bus_ = new Bus(bus_options);
+
+ exported_object_ = bus_->GetExportedObject(
+ "org.chromium.TestService",
+ "/org/chromium/TestObject");
+ CHECK(exported_object_->ExportMethodAndBlock(
+ "org.chromium.TestInterface",
+ "Echo",
+ base::Bind(&TestService::Echo,
+ base::Unretained(this))));
+ CHECK(exported_object_->ExportMethodAndBlock(
+ "org.chromium.TestInterface",
+ "SlowEcho",
+ base::Bind(&TestService::SlowEcho,
+ base::Unretained(this))));
+ CHECK(exported_object_->ExportMethodAndBlock(
+ "org.chromium.TestInterface",
+ "BrokenMethod",
+ base::Bind(&TestService::BrokenMethod,
+ base::Unretained(this))));
+
+ message_loop->Run();
+}
+
+void TestService::CleanUp() {
+ bus_->ShutdownAndBlock();
+}
+
+Response* TestService::Echo(MethodCall* method_call) {
+ MessageReader reader(method_call);
+ std::string text_message;
+ if (!reader.PopString(&text_message))
+ return NULL;
+
+ Response* response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response);
+ writer.AppendString(text_message);
+ return response;
+}
+
+Response* TestService::SlowEcho(MethodCall* method_call) {
+ base::PlatformThread::Sleep(kSlowEchoSleepMs);
+ return Echo(method_call);
+}
+
+Response* TestService::BrokenMethod(MethodCall* method_call) {
+ return NULL;
+}
+
+} // namespace dbus
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698