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