OLD | NEW |
1 // Copyright (c) 2012 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 | 7 |
8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 20 matching lines...) Expand all Loading... |
31 // | 31 // |
32 // 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 |
33 // object is alive when callbacks referencing |this| are called. | 33 // object is alive when callbacks referencing |this| are called. |
34 class CHROME_DBUS_EXPORT ExportedObject | 34 class CHROME_DBUS_EXPORT ExportedObject |
35 : public base::RefCountedThreadSafe<ExportedObject> { | 35 : public base::RefCountedThreadSafe<ExportedObject> { |
36 public: | 36 public: |
37 // Client code should use Bus::GetExportedObject() instead of this | 37 // Client code should use Bus::GetExportedObject() instead of this |
38 // constructor. | 38 // constructor. |
39 ExportedObject(Bus* bus, const ObjectPath& object_path); | 39 ExportedObject(Bus* bus, const ObjectPath& object_path); |
40 | 40 |
41 // 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 |
42 // response message. Callers should pass a NULL Response* in the event | 42 // response message. Callers should pass NULL in the event of an error that |
43 // of an error that prevents the sending of a response. | 43 // prevents the sending of a response. |
44 typedef base::Callback<void (Response*)> ResponseSender; | 44 // |
| 45 // ResponseSender takes ownership of |response| hence client code should |
| 46 // not delete |response|. |
| 47 // TODO(satorux): Change this to take scoped_ptr<Response> to make |
| 48 // ownership clearer. crbug.com/163231 |
| 49 typedef base::Callback<void (Response* response)> ResponseSender; |
45 | 50 |
46 // Called when an exported method is called. MethodCall* is the request | 51 // Called when an exported method is called. |method_call| is the request |
47 // message. ResponseSender is the callback that should be used to send a | 52 // message. |sender| is the callback that's used to send a response. |
48 // response. | 53 // |
49 typedef base::Callback<void (MethodCall*, ResponseSender)> MethodCallCallback; | 54 // |method_call| is owned by ExportedObject, hence client code should not |
| 55 // delete |method_call|. |
| 56 typedef base::Callback<void (MethodCall* method_call, ResponseSender sender)> |
| 57 MethodCallCallback; |
50 | 58 |
51 // Called when method exporting is done. | 59 // Called when method exporting is done. |
52 // Parameters: | 60 // |success| indicates whether exporting was successful or not. |
53 // - the interface name. | 61 typedef base::Callback<void (const std::string& interface_name, |
54 // - the method name. | 62 const std::string& method_name, |
55 // - whether exporting was successful or not. | 63 bool success)> |
56 typedef base::Callback<void (const std::string&, const std::string&, bool)> | |
57 OnExportedCallback; | 64 OnExportedCallback; |
58 | 65 |
59 // Exports the method specified by |interface_name| and |method_name|, | 66 // Exports the method specified by |interface_name| and |method_name|, |
60 // and blocks until exporting is done. Returns true on success. | 67 // and blocks until exporting is done. Returns true on success. |
61 // | 68 // |
62 // |method_call_callback| will be called in the origin thread, when the | 69 // |method_call_callback| will be called in the origin thread, when the |
63 // exported method is called. As it's called in the origin thread, | 70 // exported method is called. As it's called in the origin thread, |
64 // |method_callback| can safely reference objects in the origin thread | 71 // |method_callback| can safely reference objects in the origin thread |
65 // (i.e. UI thread in most cases). | 72 // (i.e. UI thread in most cases). |
66 // | 73 // |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 168 |
162 // The method table where keys are absolute method names (i.e. interface | 169 // The method table where keys are absolute method names (i.e. interface |
163 // name + method name), and values are the corresponding callbacks. | 170 // name + method name), and values are the corresponding callbacks. |
164 typedef std::map<std::string, MethodCallCallback> MethodTable; | 171 typedef std::map<std::string, MethodCallCallback> MethodTable; |
165 MethodTable method_table_; | 172 MethodTable method_table_; |
166 }; | 173 }; |
167 | 174 |
168 } // namespace dbus | 175 } // namespace dbus |
169 | 176 |
170 #endif // DBUS_EXPORTED_OBJECT_H_ | 177 #endif // DBUS_EXPORTED_OBJECT_H_ |
OLD | NEW |