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 23 matching lines...) Expand all Loading... |
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 NULL in the event of an error that | 42 // response message. Callers should pass NULL in the event of an error that |
43 // prevents the sending of a response. | 43 // prevents the sending of a response. |
44 // | 44 typedef base::Callback<void (scoped_ptr<Response> response)> ResponseSender; |
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; | |
50 | 45 |
51 // Called when an exported method is called. |method_call| is the request | 46 // Called when an exported method is called. |method_call| is the request |
52 // message. |sender| is the callback that's used to send a response. | 47 // message. |sender| is the callback that's used to send a response. |
53 // | 48 // |
54 // |method_call| is owned by ExportedObject, hence client code should not | 49 // |method_call| is owned by ExportedObject, hence client code should not |
55 // delete |method_call|. | 50 // delete |method_call|. |
56 typedef base::Callback<void (MethodCall* method_call, ResponseSender sender)> | 51 typedef base::Callback<void (MethodCall* method_call, ResponseSender sender)> |
57 MethodCallCallback; | 52 MethodCallCallback; |
58 | 53 |
59 // Called when method exporting is done. | 54 // Called when method exporting is done. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // BLOCKING CALL. | 122 // BLOCKING CALL. |
128 bool Register(); | 123 bool Register(); |
129 | 124 |
130 // Handles the incoming request messages and dispatches to the exported | 125 // Handles the incoming request messages and dispatches to the exported |
131 // methods. | 126 // methods. |
132 DBusHandlerResult HandleMessage(DBusConnection* connection, | 127 DBusHandlerResult HandleMessage(DBusConnection* connection, |
133 DBusMessage* raw_message); | 128 DBusMessage* raw_message); |
134 | 129 |
135 // Runs the method. Helper function for HandleMessage(). | 130 // Runs the method. Helper function for HandleMessage(). |
136 void RunMethod(MethodCallCallback method_call_callback, | 131 void RunMethod(MethodCallCallback method_call_callback, |
137 MethodCall* method_call, | 132 scoped_ptr<MethodCall> method_call, |
138 base::TimeTicks start_time); | 133 base::TimeTicks start_time); |
139 | 134 |
140 // Callback invoked by service provider to send a response to a method call. | 135 // Callback invoked by service provider to send a response to a method call. |
141 // Can be called immediately from a MethodCallCallback to implement a | 136 // Can be called immediately from a MethodCallCallback to implement a |
142 // synchronous service or called later to implement an asynchronous service. | 137 // synchronous service or called later to implement an asynchronous service. |
143 void SendResponse(base::TimeTicks start_time, | 138 void SendResponse(base::TimeTicks start_time, |
144 MethodCall* method_call, | 139 scoped_ptr<MethodCall> method_call, |
145 Response* response); | 140 scoped_ptr<Response> response); |
146 | 141 |
147 // Called on completion of the method run from SendResponse(). | 142 // Called on completion of the method run from SendResponse(). |
148 // Takes ownership of |method_call| and |response|. | 143 // Takes ownership of |method_call| and |response|. |
149 void OnMethodCompleted(MethodCall* method_call, | 144 void OnMethodCompleted(scoped_ptr<MethodCall> method_call, |
150 Response* response, | 145 scoped_ptr<Response> response, |
151 base::TimeTicks start_time); | 146 base::TimeTicks start_time); |
152 | 147 |
153 // Called when the object is unregistered. | 148 // Called when the object is unregistered. |
154 void OnUnregistered(DBusConnection* connection); | 149 void OnUnregistered(DBusConnection* connection); |
155 | 150 |
156 // Redirects the function call to HandleMessage(). | 151 // Redirects the function call to HandleMessage(). |
157 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 152 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
158 DBusMessage* raw_message, | 153 DBusMessage* raw_message, |
159 void* user_data); | 154 void* user_data); |
160 | 155 |
161 // Redirects the function call to OnUnregistered(). | 156 // Redirects the function call to OnUnregistered(). |
162 static void OnUnregisteredThunk(DBusConnection* connection, | 157 static void OnUnregisteredThunk(DBusConnection* connection, |
163 void* user_data); | 158 void* user_data); |
164 | 159 |
165 scoped_refptr<Bus> bus_; | 160 scoped_refptr<Bus> bus_; |
166 ObjectPath object_path_; | 161 ObjectPath object_path_; |
167 bool object_is_registered_; | 162 bool object_is_registered_; |
168 | 163 |
169 // 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 |
170 // name + method name), and values are the corresponding callbacks. | 165 // name + method name), and values are the corresponding callbacks. |
171 typedef std::map<std::string, MethodCallCallback> MethodTable; | 166 typedef std::map<std::string, MethodCallCallback> MethodTable; |
172 MethodTable method_table_; | 167 MethodTable method_table_; |
173 }; | 168 }; |
174 | 169 |
175 } // namespace dbus | 170 } // namespace dbus |
176 | 171 |
177 #endif // DBUS_EXPORTED_OBJECT_H_ | 172 #endif // DBUS_EXPORTED_OBJECT_H_ |
OLD | NEW |