Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 // 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 |
| 32 // object is alive when callbacks referencing |this| are called. | 32 // object is alive when callbacks referencing |this| are called. |
| 33 class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { | 33 class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { |
| 34 public: | 34 public: |
| 35 // Client code should use Bus::GetExportedObject() instead of this | 35 // Client code should use Bus::GetExportedObject() instead of this |
| 36 // constructor. | 36 // constructor. |
| 37 ExportedObject(Bus* bus, | 37 ExportedObject(Bus* bus, |
| 38 const std::string& service_name, | 38 const std::string& service_name, |
| 39 const std::string& object_path); | 39 const std::string& object_path); |
| 40 | 40 |
| 41 // Called to send a response from an exported method. Response* is the | |
| 42 // response message. | |
|
satorux1
2011/11/22 06:20:05
Please describe that the export method should call
Vince Laviano
2011/11/22 22:10:17
Done.
| |
| 43 typedef base::Callback<void (Response*)> SendResponseCallback; | |
|
satorux1
2011/11/22 06:20:05
I suggested SendResponseCallback, but I'm now thin
Vince Laviano
2011/11/22 22:10:17
Done.
| |
| 44 | |
| 41 // Called when an exported method is called. MethodCall* is the request | 45 // Called when an exported method is called. MethodCall* is the request |
| 42 // message. | 46 // message. SendResponseCallback is the callback that should be used to |
| 43 typedef base::Callback<Response* (MethodCall*)> MethodCallCallback; | 47 // send a response. |
| 48 typedef base::Callback<void (MethodCall*, SendResponseCallback)> | |
| 49 MethodCallCallback; | |
| 44 | 50 |
| 45 // Called when method exporting is done. | 51 // Called when method exporting is done. |
| 46 // Parameters: | 52 // Parameters: |
| 47 // - the interface name. | 53 // - the interface name. |
| 48 // - the method name. | 54 // - the method name. |
| 49 // - whether exporting was successful or not. | 55 // - whether exporting was successful or not. |
| 50 typedef base::Callback<void (const std::string&, const std::string&, bool)> | 56 typedef base::Callback<void (const std::string&, const std::string&, bool)> |
| 51 OnExportedCallback; | 57 OnExportedCallback; |
| 52 | 58 |
| 53 // Exports the method specified by |interface_name| and |method_name|, | 59 // Exports the method specified by |interface_name| and |method_name|, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 // Handles the incoming request messages and dispatches to the exported | 123 // Handles the incoming request messages and dispatches to the exported |
| 118 // methods. | 124 // methods. |
| 119 DBusHandlerResult HandleMessage(DBusConnection* connection, | 125 DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 120 DBusMessage* raw_message); | 126 DBusMessage* raw_message); |
| 121 | 127 |
| 122 // Runs the method. Helper function for HandleMessage(). | 128 // Runs the method. Helper function for HandleMessage(). |
| 123 void RunMethod(MethodCallCallback method_call_callback, | 129 void RunMethod(MethodCallCallback method_call_callback, |
| 124 MethodCall* method_call, | 130 MethodCall* method_call, |
| 125 base::TimeTicks start_time); | 131 base::TimeTicks start_time); |
| 126 | 132 |
| 127 // Called on completion of the method run from RunMethod(). | 133 // Callback invoked by service provider to send a response to a method call. |
| 134 // Can be called immediately from a MethodCallCallback to implement a | |
| 135 // synchronous service or called later to implement an asynchronous service. | |
| 136 void SendResponse(base::TimeTicks start_time, | |
| 137 MethodCall* method_call, | |
| 138 Response* response); | |
| 139 | |
| 140 // Called on completion of the method run from SendResponse(). | |
| 128 // Takes ownership of |method_call| and |response|. | 141 // Takes ownership of |method_call| and |response|. |
| 129 void OnMethodCompleted(MethodCall* method_call, | 142 void OnMethodCompleted(MethodCall* method_call, |
| 130 Response* response, | 143 Response* response, |
| 131 base::TimeTicks start_time); | 144 base::TimeTicks start_time); |
| 132 | 145 |
| 133 // Called when the object is unregistered. | 146 // Called when the object is unregistered. |
| 134 void OnUnregistered(DBusConnection* connection); | 147 void OnUnregistered(DBusConnection* connection); |
| 135 | 148 |
| 136 // Redirects the function call to HandleMessage(). | 149 // Redirects the function call to HandleMessage(). |
| 137 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 150 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 149 | 162 |
| 150 // 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 |
| 151 // name + method name), and values are the corresponding callbacks. | 164 // name + method name), and values are the corresponding callbacks. |
| 152 typedef std::map<std::string, MethodCallCallback> MethodTable; | 165 typedef std::map<std::string, MethodCallCallback> MethodTable; |
| 153 MethodTable method_table_; | 166 MethodTable method_table_; |
| 154 }; | 167 }; |
| 155 | 168 |
| 156 } // namespace dbus | 169 } // namespace dbus |
| 157 | 170 |
| 158 #endif // DBUS_EXPORTED_OBJECT_H_ | 171 #endif // DBUS_EXPORTED_OBJECT_H_ |
| OLD | NEW |