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

Unified Diff: dbus/object_proxy.h

Issue 7491029: Implement Bus and ObjectProxy classes for our D-Bus library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: work-in-progress Created 9 years, 5 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
Index: dbus/object_proxy.h
diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h
new file mode 100644
index 0000000000000000000000000000000000000000..30599a9b1f4d23af9954e03b802dea44b56d4e49
--- /dev/null
+++ b/dbus/object_proxy.h
@@ -0,0 +1,135 @@
+// 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.
+//
+// D-Bus library for Chrome.
+
+#ifndef DBUS_OBJECT_PROXY_H_
+#define DBUS_OBJECT_PROXY_H_
+#pragma once
+
+#include <string>
+#include <vector>
+#include <dbus/dbus.h>
+
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+#include "base/threading/platform_thread.h"
+
+class MessageLoop;
+
+namespace dbus {
+
+class Bus;
+class MethodCall;
+class Response;
+
+// ObjectProxy is used to communicate with remote objects, such as calling
+// methods and sending signals.
+//
+// TODO(satorux): Add support for sending signals.
+class ObjectProxy {
+ public:
+ virtual ~ObjectProxy();
+
+ // The constants correspond to DBUS_TIMEOUT_USE_DEFAULT and
+ // DBUS_TIMEOUT_INFINITE. Here we use literal numbers instead of these
+ // macros as these aren't defined with D-Bus earlier than 1.4.12.
+ // http://dbus.freedesktop.org/doc/api/html/group__DBusPendingCall.html
+ enum {
+ // Note: the default timeout is set to 25 secs per
+ // dbus-1.2.16/dbus/dbus-connection-internal.h
+ // #define _DBUS_DEFAULT_TIMEOUT_VALUE (25 * 1000)
+ TIMEOUT_USE_DEFAULT = -1,
+ TIMEOUT_INFINITE = 0x7fffffff,
+ };
+
+ // Used for CallMethodAsync().
+ typedef base::Callback<void(Response*)> ResponseCallback;
+
+ // Calls the method of the remote object and waits until the response is
+ // returned. This is a blocking call hence shouldn't be called from the
+ // UI thread.
+ virtual bool CallMethodAndWait(MethodCall* method_call,
+ Response* response,
+ int timeout_ms);
+
+ // Calls the method of the remote object. |callback| will be called in
+ // the message loop of the thread that calls this function. If the
+ // method call is successful, a valid Response object will be passed to
+ // the callback, and the callback needs to delete the response object.
+ // If the method call is unsuccessful, NULL will be passed to the
+ // callback.
+ //
+ // This is not a blocking call (this function just posts a task to the
+ // message loop in another thread maintained by Bus object), hence it's
+ // safe to be called from the UI thread.
+ //
+ // TODO(satorux): Implement timeout. timeout_ms is currently unused.
+ virtual void CallMethod(MethodCall* method_call,
+ ResponseCallback callback,
+ int timeout_ms);
+
+ const std::string& service_name() const { return service_name_; }
+ const std::string& object_path() const { return object_path_; }
+
+ private:
+ // Struct of data we'll be passing from StartAsyncMethodCall() to
+ // OnPendingCallIsCompleteStub().
+ struct OnPendingCallIsCompleteData {
+ OnPendingCallIsCompleteData(ObjectProxy* in_object_proxy,
+ MessageLoop* in_origin_loop,
+ ResponseCallback in_response_callback);
+ ObjectProxy* object_proxy;
+ MessageLoop* origin_loop;
+ ResponseCallback response_callback;
+ };
+
+ // Starts the async method call.
+ void StartAsyncMethodCall(int timeout_ms,
+ void* request_message,
+ MessageLoop* origin_loop,
+ ResponseCallback response_callback);
+
+ // Called when the pending call is complete.
+ void OnPendingCallIsComplete(DBusPendingCall* pending_call,
+ ResponseCallback response_callback,
+ MessageLoop* origin_loop);
+
+ // Runs the response callback with the given response object.
+ void RunResponseCallback(ResponseCallback response_callback,
+ Response* response);
+
+ // Checks whether the current thread is on the same thread that created
+ // the object proxy. If not, DCHECK() will fail.
+ void AssertOnOriginThread();
+
+ // Checks whether the current thread is on the IO thread, if the
+ // underlying bus is configured to use it. If not, DCHECK() will fail.
+ //
+ // The function does the same with AssertOnOriginThread() if the bus is
+ // NOT configured to use the IO thread.
+ void AssertOnIoThreadIfConfigured();
+
+ // Redirects the function call to OnPendingCallIsComplete().
+ static void OnPendingCallIsCompleteStub(DBusPendingCall* pending_call,
+ void* user_data);
+
+ friend class Bus;
+
+ // The object proxy can only be created by Bus.
+ ObjectProxy(Bus* bus,
+ const std::string& service_name,
+ const std::string& object_path);
+
+ Bus* bus_;
+ std::string service_name_;
+ std::string object_path_;
+ const base::PlatformThreadId origin_thread_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(ObjectProxy);
+};
+
+} // namespace dbus
+
+#endif // DBUS_OBJECT_PROXY_H_
« dbus/bus.cc ('K') | « dbus/dbus_test_client.cc ('k') | dbus/object_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698