| 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_OBJECT_PROXY_H_ | 5 #ifndef DBUS_OBJECT_PROXY_H_ |
| 6 #define DBUS_OBJECT_PROXY_H_ | 6 #define DBUS_OBJECT_PROXY_H_ |
| 7 | 7 |
| 8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 typedef base::Callback<void(Response*)> ResponseCallback; | 70 typedef base::Callback<void(Response*)> ResponseCallback; |
| 71 | 71 |
| 72 // Called when a signal is received. Signal* is the incoming signal. | 72 // Called when a signal is received. Signal* is the incoming signal. |
| 73 typedef base::Callback<void (Signal*)> SignalCallback; | 73 typedef base::Callback<void (Signal*)> SignalCallback; |
| 74 | 74 |
| 75 // Called when NameOwnerChanged signal is received. | 75 // Called when NameOwnerChanged signal is received. |
| 76 typedef base::Callback<void( | 76 typedef base::Callback<void( |
| 77 const std::string& old_owner, | 77 const std::string& old_owner, |
| 78 const std::string& new_owner)> NameOwnerChangedCallback; | 78 const std::string& new_owner)> NameOwnerChangedCallback; |
| 79 | 79 |
| 80 // Called when the service becomes available. |
| 81 typedef base::Callback<void( |
| 82 bool service_is_available)> WaitForServiceToBeAvailableCallback; |
| 83 |
| 80 // Called when the object proxy is connected to the signal. | 84 // Called when the object proxy is connected to the signal. |
| 81 // Parameters: | 85 // Parameters: |
| 82 // - the interface name. | 86 // - the interface name. |
| 83 // - the signal name. | 87 // - the signal name. |
| 84 // - whether it was successful or not. | 88 // - whether it was successful or not. |
| 85 typedef base::Callback<void (const std::string&, const std::string&, bool)> | 89 typedef base::Callback<void (const std::string&, const std::string&, bool)> |
| 86 OnConnectedCallback; | 90 OnConnectedCallback; |
| 87 | 91 |
| 88 // Calls the method of the remote object and blocks until the response | 92 // Calls the method of the remote object and blocks until the response |
| 89 // is returned. Returns NULL on error. | 93 // is returned. Returns NULL on error. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 virtual void ConnectToSignal(const std::string& interface_name, | 149 virtual void ConnectToSignal(const std::string& interface_name, |
| 146 const std::string& signal_name, | 150 const std::string& signal_name, |
| 147 SignalCallback signal_callback, | 151 SignalCallback signal_callback, |
| 148 OnConnectedCallback on_connected_callback); | 152 OnConnectedCallback on_connected_callback); |
| 149 | 153 |
| 150 // Sets a callback for "NameOwnerChanged" signal. The callback is called on | 154 // Sets a callback for "NameOwnerChanged" signal. The callback is called on |
| 151 // the origin thread when D-Bus system sends "NameOwnerChanged" for the name | 155 // the origin thread when D-Bus system sends "NameOwnerChanged" for the name |
| 152 // represented by |service_name_|. | 156 // represented by |service_name_|. |
| 153 virtual void SetNameOwnerChangedCallback(NameOwnerChangedCallback callback); | 157 virtual void SetNameOwnerChangedCallback(NameOwnerChangedCallback callback); |
| 154 | 158 |
| 159 // Runs the callback as soon as the service becomes available. |
| 160 virtual void WaitForServiceToBeAvailable( |
| 161 WaitForServiceToBeAvailableCallback callback); |
| 162 |
| 155 // Detaches from the remote object. The Bus object will take care of | 163 // Detaches from the remote object. The Bus object will take care of |
| 156 // detaching so you don't have to do this manually. | 164 // detaching so you don't have to do this manually. |
| 157 // | 165 // |
| 158 // BLOCKING CALL. | 166 // BLOCKING CALL. |
| 159 virtual void Detach(); | 167 virtual void Detach(); |
| 160 | 168 |
| 161 // Returns an empty callback that does nothing. Can be used for | 169 // Returns an empty callback that does nothing. Can be used for |
| 162 // CallMethod(). | 170 // CallMethod(). |
| 163 static ResponseCallback EmptyResponseCallback(); | 171 static ResponseCallback EmptyResponseCallback(); |
| 164 | 172 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Runs the response callback with the given response object. | 209 // Runs the response callback with the given response object. |
| 202 void RunResponseCallback(ResponseCallback response_callback, | 210 void RunResponseCallback(ResponseCallback response_callback, |
| 203 ErrorCallback error_callback, | 211 ErrorCallback error_callback, |
| 204 base::TimeTicks start_time, | 212 base::TimeTicks start_time, |
| 205 DBusMessage* response_message); | 213 DBusMessage* response_message); |
| 206 | 214 |
| 207 // Redirects the function call to OnPendingCallIsComplete(). | 215 // Redirects the function call to OnPendingCallIsComplete(). |
| 208 static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, | 216 static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, |
| 209 void* user_data); | 217 void* user_data); |
| 210 | 218 |
| 219 // Connects to NameOwnerChanged signal. |
| 220 bool ConnectToNameOwnerChangedSignal(); |
| 221 |
| 211 // Helper function for ConnectToSignal(). | 222 // Helper function for ConnectToSignal(). |
| 212 bool ConnectToSignalInternal(const std::string& interface_name, | 223 bool ConnectToSignalInternal(const std::string& interface_name, |
| 213 const std::string& signal_name, | 224 const std::string& signal_name, |
| 214 SignalCallback signal_callback); | 225 SignalCallback signal_callback); |
| 215 | 226 |
| 227 // Helper function for WaitForServiceToBeAvailable(). |
| 228 void WaitForServiceToBeAvailableInternal(); |
| 229 |
| 216 // Handles the incoming request messages and dispatches to the signal | 230 // Handles the incoming request messages and dispatches to the signal |
| 217 // callbacks. | 231 // callbacks. |
| 218 DBusHandlerResult HandleMessage(DBusConnection* connection, | 232 DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 219 DBusMessage* raw_message); | 233 DBusMessage* raw_message); |
| 220 | 234 |
| 221 // Runs the method. Helper function for HandleMessage(). | 235 // Runs the method. Helper function for HandleMessage(). |
| 222 void RunMethod(base::TimeTicks start_time, | 236 void RunMethod(base::TimeTicks start_time, |
| 223 std::vector<SignalCallback> signal_callbacks, | 237 std::vector<SignalCallback> signal_callbacks, |
| 224 Signal* signal); | 238 Signal* signal); |
| 225 | 239 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 255 // BLOCKING CALL. | 269 // BLOCKING CALL. |
| 256 void UpdateNameOwnerAndBlock(); | 270 void UpdateNameOwnerAndBlock(); |
| 257 | 271 |
| 258 // Handles NameOwnerChanged signal from D-Bus's special message bus. | 272 // Handles NameOwnerChanged signal from D-Bus's special message bus. |
| 259 DBusHandlerResult HandleNameOwnerChanged(scoped_ptr<dbus::Signal> signal); | 273 DBusHandlerResult HandleNameOwnerChanged(scoped_ptr<dbus::Signal> signal); |
| 260 | 274 |
| 261 // Runs |name_owner_changed_callback_|. | 275 // Runs |name_owner_changed_callback_|. |
| 262 void RunNameOwnerChangedCallback(const std::string& old_owner, | 276 void RunNameOwnerChangedCallback(const std::string& old_owner, |
| 263 const std::string& new_owner); | 277 const std::string& new_owner); |
| 264 | 278 |
| 279 // Runs |wait_for_service_to_be_available_callbacks_|. |
| 280 void RunWaitForServiceToBeAvailableCallbacks(bool service_is_available); |
| 281 |
| 265 scoped_refptr<Bus> bus_; | 282 scoped_refptr<Bus> bus_; |
| 266 std::string service_name_; | 283 std::string service_name_; |
| 267 ObjectPath object_path_; | 284 ObjectPath object_path_; |
| 268 | 285 |
| 269 // True if the message filter was added. | 286 // True if the message filter was added. |
| 270 bool filter_added_; | 287 bool filter_added_; |
| 271 | 288 |
| 272 // The method table where keys are absolute signal names (i.e. interface | 289 // The method table where keys are absolute signal names (i.e. interface |
| 273 // name + signal name), and values are lists of the corresponding callbacks. | 290 // name + signal name), and values are lists of the corresponding callbacks. |
| 274 typedef std::map<std::string, std::vector<SignalCallback> > MethodTable; | 291 typedef std::map<std::string, std::vector<SignalCallback> > MethodTable; |
| 275 MethodTable method_table_; | 292 MethodTable method_table_; |
| 276 | 293 |
| 277 // The callback called when NameOwnerChanged signal is received. | 294 // The callback called when NameOwnerChanged signal is received. |
| 278 NameOwnerChangedCallback name_owner_changed_callback_; | 295 NameOwnerChangedCallback name_owner_changed_callback_; |
| 279 | 296 |
| 297 // Called when the service becomes available. |
| 298 std::vector<WaitForServiceToBeAvailableCallback> |
| 299 wait_for_service_to_be_available_callbacks_; |
| 300 |
| 280 std::set<std::string> match_rules_; | 301 std::set<std::string> match_rules_; |
| 281 | 302 |
| 282 const bool ignore_service_unknown_errors_; | 303 const bool ignore_service_unknown_errors_; |
| 283 | 304 |
| 284 // Known name owner of the well-known bus name represnted by |service_name_|. | 305 // Known name owner of the well-known bus name represnted by |service_name_|. |
| 285 std::string service_name_owner_; | 306 std::string service_name_owner_; |
| 286 | 307 |
| 287 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); | 308 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
| 288 }; | 309 }; |
| 289 | 310 |
| 290 } // namespace dbus | 311 } // namespace dbus |
| 291 | 312 |
| 292 #endif // DBUS_OBJECT_PROXY_H_ | 313 #endif // DBUS_OBJECT_PROXY_H_ |
| OLD | NEW |