summaryrefslogtreecommitdiffstats
path: root/dbus/test_service.h
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-17 20:58:12 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-17 20:58:12 +0000
commita510761104333ec7da3943399f059ff693839856 (patch)
tree2a9f81a60bccf4db3367ad1b8f71e9ea130efb7d /dbus/test_service.h
parent07f93af15169ee054552a376ac4953abd1346cb2 (diff)
downloadchromium_src-a510761104333ec7da3943399f059ff693839856.zip
chromium_src-a510761104333ec7da3943399f059ff693839856.tar.gz
chromium_src-a510761104333ec7da3943399f059ff693839856.tar.bz2
Implement Bus and ObjectProxy classes for our D-Bus library.
ObjectProxy is used to access remote objects. ExportedObject is used to export objects to other D-Bus BUG=90036 TEST=run unit tests. The code is not yet used in Chrome. Review URL: http://codereview.chromium.org/7491029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/test_service.h')
-rw-r--r--dbus/test_service.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/dbus/test_service.h b/dbus/test_service.h
new file mode 100644
index 0000000..362ecb7
--- /dev/null
+++ b/dbus/test_service.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef DBUS_TEST_SERVICE_H_
+#define DBUS_TEST_SERVICE_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "base/threading/thread.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/synchronization/lock.h"
+
+namespace dbus {
+
+class Bus;
+class ExportedObject;
+class MethodCall;
+class Response;
+
+// The test service is used for end-to-end tests. The service runs in a
+// separate thread, so it does not interfere the test code that runs in
+// the main thread. Methods such as Echo() and SlowEcho() are exported.
+class TestService : public base::Thread {
+ public:
+ // SlowEcho() sleeps for this period of time before returns.
+ static const int kSlowEchoSleepMs;
+
+ TestService();
+ virtual ~TestService();
+
+ // Starts the service in a separate thread.
+ void StartService();
+
+ // Waits until the service is started (i.e. methods are exported).
+ void WaitUntilServiceIsStarted();
+
+ private:
+ // Called when the service is started (i.e. the task is run from the
+ // message loop).
+ void OnServiceStarted();
+
+ // base::Thread override.
+ virtual void Run(MessageLoop* message_loop);
+
+ // base::Thread override.
+ virtual void CleanUp();
+
+ //
+ // Exported methods.
+ //
+
+ // Echos the text message received from the method call.
+ Response* Echo(MethodCall* method_call);
+
+ // Echos the text message received from the method call, but sleeps for
+ // kSlowEchoSleepMs before returning the response.
+ Response* SlowEcho(MethodCall* method_call);
+
+ // Returns NULL, instead of a valid Response.
+ Response* BrokenMethod(MethodCall* method_call);
+
+ bool service_started_;
+ base::Lock service_started_lock_;
+ base::ConditionVariable on_service_started_;
+
+ scoped_refptr<Bus> bus_;
+ ExportedObject* exported_object_;
+};
+
+} // namespace dbus
+
+#endif // DBUS_TEST_SERVICE_H_