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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Called when an error response is returned or no response is returned. | 65 // Called when an error response is returned or no response is returned. |
66 // Used for CallMethodWithErrorCallback(). | 66 // Used for CallMethodWithErrorCallback(). |
67 typedef base::Callback<void(ErrorResponse*)> ErrorCallback; | 67 typedef base::Callback<void(ErrorResponse*)> ErrorCallback; |
68 | 68 |
69 // Called when the response is returned. Used for CallMethod(). | 69 // Called when the response is returned. Used for CallMethod(). |
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. |
| 76 typedef base::Callback<void( |
| 77 const std::string& old_owner, |
| 78 const std::string& new_owner)> NameOwnerChangedCallback; |
| 79 |
75 // Called when the object proxy is connected to the signal. | 80 // Called when the object proxy is connected to the signal. |
76 // Parameters: | 81 // Parameters: |
77 // - the interface name. | 82 // - the interface name. |
78 // - the signal name. | 83 // - the signal name. |
79 // - whether it was successful or not. | 84 // - whether it was successful or not. |
80 typedef base::Callback<void (const std::string&, const std::string&, bool)> | 85 typedef base::Callback<void (const std::string&, const std::string&, bool)> |
81 OnConnectedCallback; | 86 OnConnectedCallback; |
82 | 87 |
83 // Calls the method of the remote object and blocks until the response | 88 // Calls the method of the remote object and blocks until the response |
84 // is returned. Returns NULL on error. | 89 // is returned. Returns NULL on error. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // | 143 // |
139 // Must be called in the origin thread. | 144 // Must be called in the origin thread. |
140 virtual void ConnectToSignal(const std::string& interface_name, | 145 virtual void ConnectToSignal(const std::string& interface_name, |
141 const std::string& signal_name, | 146 const std::string& signal_name, |
142 SignalCallback signal_callback, | 147 SignalCallback signal_callback, |
143 OnConnectedCallback on_connected_callback); | 148 OnConnectedCallback on_connected_callback); |
144 | 149 |
145 // Sets a callback for "NameOwnerChanged" signal. The callback is called on | 150 // Sets a callback for "NameOwnerChanged" signal. The callback is called on |
146 // the origin thread when D-Bus system sends "NameOwnerChanged" for the name | 151 // the origin thread when D-Bus system sends "NameOwnerChanged" for the name |
147 // represented by |service_name_|. | 152 // represented by |service_name_|. |
148 virtual void SetNameOwnerChangedCallback(SignalCallback callback); | 153 virtual void SetNameOwnerChangedCallback(NameOwnerChangedCallback callback); |
149 | 154 |
150 // Detaches from the remote object. The Bus object will take care of | 155 // Detaches from the remote object. The Bus object will take care of |
151 // detaching so you don't have to do this manually. | 156 // detaching so you don't have to do this manually. |
152 // | 157 // |
153 // BLOCKING CALL. | 158 // BLOCKING CALL. |
154 virtual void Detach(); | 159 virtual void Detach(); |
155 | 160 |
156 // Returns an empty callback that does nothing. Can be used for | 161 // Returns an empty callback that does nothing. Can be used for |
157 // CallMethod(). | 162 // CallMethod(). |
158 static ResponseCallback EmptyResponseCallback(); | 163 static ResponseCallback EmptyResponseCallback(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 251 |
247 // Calls D-Bus's GetNameOwner method synchronously to update | 252 // Calls D-Bus's GetNameOwner method synchronously to update |
248 // |service_name_owner_| with the current owner of |service_name_|. | 253 // |service_name_owner_| with the current owner of |service_name_|. |
249 // | 254 // |
250 // BLOCKING CALL. | 255 // BLOCKING CALL. |
251 void UpdateNameOwnerAndBlock(); | 256 void UpdateNameOwnerAndBlock(); |
252 | 257 |
253 // Handles NameOwnerChanged signal from D-Bus's special message bus. | 258 // Handles NameOwnerChanged signal from D-Bus's special message bus. |
254 DBusHandlerResult HandleNameOwnerChanged(scoped_ptr<dbus::Signal> signal); | 259 DBusHandlerResult HandleNameOwnerChanged(scoped_ptr<dbus::Signal> signal); |
255 | 260 |
| 261 // Runs |name_owner_changed_callback_|. |
| 262 void RunNameOwnerChangedCallback(const std::string& old_owner, |
| 263 const std::string& new_owner); |
| 264 |
256 scoped_refptr<Bus> bus_; | 265 scoped_refptr<Bus> bus_; |
257 std::string service_name_; | 266 std::string service_name_; |
258 ObjectPath object_path_; | 267 ObjectPath object_path_; |
259 | 268 |
260 // True if the message filter was added. | 269 // True if the message filter was added. |
261 bool filter_added_; | 270 bool filter_added_; |
262 | 271 |
263 // The method table where keys are absolute signal names (i.e. interface | 272 // The method table where keys are absolute signal names (i.e. interface |
264 // name + signal name), and values are lists of the corresponding callbacks. | 273 // name + signal name), and values are lists of the corresponding callbacks. |
265 typedef std::map<std::string, std::vector<SignalCallback> > MethodTable; | 274 typedef std::map<std::string, std::vector<SignalCallback> > MethodTable; |
266 MethodTable method_table_; | 275 MethodTable method_table_; |
267 | 276 |
268 // The callback called when NameOwnerChanged signal is received. | 277 // The callback called when NameOwnerChanged signal is received. |
269 SignalCallback name_owner_changed_callback_; | 278 NameOwnerChangedCallback name_owner_changed_callback_; |
270 | 279 |
271 std::set<std::string> match_rules_; | 280 std::set<std::string> match_rules_; |
272 | 281 |
273 const bool ignore_service_unknown_errors_; | 282 const bool ignore_service_unknown_errors_; |
274 | 283 |
275 // Known name owner of the well-known bus name represnted by |service_name_|. | 284 // Known name owner of the well-known bus name represnted by |service_name_|. |
276 std::string service_name_owner_; | 285 std::string service_name_owner_; |
277 | 286 |
278 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); | 287 DISALLOW_COPY_AND_ASSIGN(ObjectProxy); |
279 }; | 288 }; |
280 | 289 |
281 } // namespace dbus | 290 } // namespace dbus |
282 | 291 |
283 #endif // DBUS_OBJECT_PROXY_H_ | 292 #endif // DBUS_OBJECT_PROXY_H_ |
OLD | NEW |