OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DBUS_EXPORTED_OBJECT_H_ | 5 #ifndef DBUS_EXPORTED_OBJECT_H_ |
6 #define DBUS_EXPORTED_OBJECT_H_ | 6 #define DBUS_EXPORTED_OBJECT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <dbus/dbus.h> | 9 #include <dbus/dbus.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "dbus/object_path.h" | |
21 | 20 |
22 namespace dbus { | 21 namespace dbus { |
23 | 22 |
24 class Bus; | 23 class Bus; |
25 class MethodCall; | 24 class MethodCall; |
26 class Response; | 25 class Response; |
27 class Signal; | 26 class Signal; |
28 | 27 |
29 // ExportedObject is used to export objects and methods to other D-Bus | 28 // ExportedObject is used to export objects and methods to other D-Bus |
30 // clients. | 29 // clients. |
31 // | 30 // |
32 // ExportedObject is a ref counted object, to ensure that |this| of the | 31 // ExportedObject is a ref counted object, to ensure that |this| of the |
33 // object is alive when callbacks referencing |this| are called. | 32 // object is alive when callbacks referencing |this| are called. |
34 class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { | 33 class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { |
35 public: | 34 public: |
36 // Client code should use Bus::GetExportedObject() instead of this | 35 // Client code should use Bus::GetExportedObject() instead of this |
37 // constructor. | 36 // constructor. |
38 ExportedObject(Bus* bus, | 37 ExportedObject(Bus* bus, |
39 const std::string& service_name, | 38 const std::string& service_name, |
40 const ObjectPath& object_path); | 39 const std::string& object_path); |
41 | 40 |
42 // Called to send a response from an exported method. Response* is the | 41 // Called to send a response from an exported method. Response* is the |
43 // response message. Callers should pass a NULL Response* in the event | 42 // response message. Callers should pass a NULL Response* in the event |
44 // of an error that prevents the sending of a response. | 43 // of an error that prevents the sending of a response. |
45 typedef base::Callback<void (Response*)> ResponseSender; | 44 typedef base::Callback<void (Response*)> ResponseSender; |
46 | 45 |
47 // Called when an exported method is called. MethodCall* is the request | 46 // Called when an exported method is called. MethodCall* is the request |
48 // message. ResponseSender is the callback that should be used to send a | 47 // message. ResponseSender is the callback that should be used to send a |
49 // response. | 48 // response. |
50 typedef base::Callback<void (MethodCall*, ResponseSender)> MethodCallCallback; | 49 typedef base::Callback<void (MethodCall*, ResponseSender)> MethodCallCallback; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 150 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
152 DBusMessage* raw_message, | 151 DBusMessage* raw_message, |
153 void* user_data); | 152 void* user_data); |
154 | 153 |
155 // Redirects the function call to OnUnregistered(). | 154 // Redirects the function call to OnUnregistered(). |
156 static void OnUnregisteredThunk(DBusConnection* connection, | 155 static void OnUnregisteredThunk(DBusConnection* connection, |
157 void* user_data); | 156 void* user_data); |
158 | 157 |
159 scoped_refptr<Bus> bus_; | 158 scoped_refptr<Bus> bus_; |
160 std::string service_name_; | 159 std::string service_name_; |
161 ObjectPath object_path_; | 160 std::string object_path_; |
162 bool object_is_registered_; | 161 bool object_is_registered_; |
163 | 162 |
164 // The method table where keys are absolute method names (i.e. interface | 163 // The method table where keys are absolute method names (i.e. interface |
165 // name + method name), and values are the corresponding callbacks. | 164 // name + method name), and values are the corresponding callbacks. |
166 typedef std::map<std::string, MethodCallCallback> MethodTable; | 165 typedef std::map<std::string, MethodCallCallback> MethodTable; |
167 MethodTable method_table_; | 166 MethodTable method_table_; |
168 }; | 167 }; |
169 | 168 |
170 } // namespace dbus | 169 } // namespace dbus |
171 | 170 |
172 #endif // DBUS_EXPORTED_OBJECT_H_ | 171 #endif // DBUS_EXPORTED_OBJECT_H_ |
OLD | NEW |