OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_MANAGER_H_ | 5 #ifndef DBUS_OBJECT_MANAGER_H_ |
6 #define DBUS_OBJECT_MANAGER_H_ | 6 #define DBUS_OBJECT_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // cast the returned pointer to the appropriate type, e.g.: | 216 // cast the returned pointer to the appropriate type, e.g.: |
217 // static_cast<Properties*>(GetProperties(object_path, my_interface)); | 217 // static_cast<Properties*>(GetProperties(object_path, my_interface)); |
218 PropertySet* GetProperties(const ObjectPath& object_path, | 218 PropertySet* GetProperties(const ObjectPath& object_path, |
219 const std::string& interface_name); | 219 const std::string& interface_name); |
220 | 220 |
221 // Instructs the object manager to refresh its list of managed objects; | 221 // Instructs the object manager to refresh its list of managed objects; |
222 // automatically called by the D-Bus thread manager, there should never be | 222 // automatically called by the D-Bus thread manager, there should never be |
223 // a need to call this manually. | 223 // a need to call this manually. |
224 void GetManagedObjects(); | 224 void GetManagedObjects(); |
225 | 225 |
| 226 // Cleans up any match rules and filter functions added by this ObjectManager. |
| 227 // The Bus object will take care of this so you don't have to do it manually. |
| 228 // |
| 229 // BLOCKING CALL. |
| 230 void CleanUp(); |
| 231 |
226 protected: | 232 protected: |
227 virtual ~ObjectManager(); | 233 virtual ~ObjectManager(); |
228 | 234 |
229 private: | 235 private: |
230 friend class base::RefCountedThreadSafe<ObjectManager>; | 236 friend class base::RefCountedThreadSafe<ObjectManager>; |
231 | 237 |
| 238 // Connects the InterfacesAdded and InterfacesRemoved signals and calls |
| 239 // GetManagedObjects. Called from OnSetupMatchRuleAndFilterComplete. |
| 240 void InitializeObjects(); |
| 241 |
| 242 // Called from the constructor to add a match rule for PropertiesChanged |
| 243 // signals on the DBus thread and set up a corresponding filter function. |
| 244 bool SetupMatchRuleAndFilter(); |
| 245 |
| 246 // Called on the origin thread once the match rule and filter have been set |
| 247 // up. |success| is false, if an error occurred during set up; it's true |
| 248 // otherwise. |
| 249 void OnSetupMatchRuleAndFilterComplete(bool success); |
| 250 |
| 251 // Called by dbus:: when a message is received. This is used to filter |
| 252 // PropertiesChanged signals from the correct sender and relay the event to |
| 253 // the correct PropertySet. |
| 254 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
| 255 DBusMessage* raw_message, |
| 256 void* user_data); |
| 257 DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 258 DBusMessage* raw_message); |
| 259 |
| 260 // Called when a PropertiesChanged signal is received from the sender. |
| 261 // This method notifies the relevant PropertySet that it should update its |
| 262 // properties based on the received signal. Called from HandleMessage. |
| 263 void NotifyPropertiesChanged(const dbus::ObjectPath object_path, |
| 264 Signal* signal); |
| 265 void NotifyPropertiesChangedHelper(const dbus::ObjectPath object_path, |
| 266 Signal* signal); |
232 | 267 |
233 // Called by dbus:: in response to the GetManagedObjects() method call. | 268 // Called by dbus:: in response to the GetManagedObjects() method call. |
234 void OnGetManagedObjects(Response* response); | 269 void OnGetManagedObjects(Response* response); |
235 | 270 |
236 // Called by dbus:: when an InterfacesAdded signal is received and initially | 271 // Called by dbus:: when an InterfacesAdded signal is received and initially |
237 // connected. | 272 // connected. |
238 void InterfacesAddedReceived(Signal* signal); | 273 void InterfacesAddedReceived(Signal* signal); |
239 void InterfacesAddedConnected(const std::string& interface_name, | 274 void InterfacesAddedConnected(const std::string& interface_name, |
240 const std::string& signal_name, | 275 const std::string& signal_name, |
241 bool success); | 276 bool success); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 const std::string& interface_name); | 309 const std::string& interface_name); |
275 | 310 |
276 // Removes all objects and interfaces from the object manager when | 311 // Removes all objects and interfaces from the object manager when |
277 // |old_owner| is not the empty string and/or re-requests the set of managed | 312 // |old_owner| is not the empty string and/or re-requests the set of managed |
278 // objects when |new_owner| is not the empty string. | 313 // objects when |new_owner| is not the empty string. |
279 void NameOwnerChanged(const std::string& old_owner, | 314 void NameOwnerChanged(const std::string& old_owner, |
280 const std::string& new_owner); | 315 const std::string& new_owner); |
281 | 316 |
282 Bus* bus_; | 317 Bus* bus_; |
283 std::string service_name_; | 318 std::string service_name_; |
| 319 std::string service_name_owner_; |
| 320 std::string match_rule_; |
284 ObjectPath object_path_; | 321 ObjectPath object_path_; |
285 ObjectProxy* object_proxy_; | 322 ObjectProxy* object_proxy_; |
| 323 bool setup_success_; |
| 324 bool cleanup_called_; |
286 | 325 |
287 // Maps the name of an interface to the implementation class used for | 326 // Maps the name of an interface to the implementation class used for |
288 // instantiating PropertySet structures for that interface's properties. | 327 // instantiating PropertySet structures for that interface's properties. |
289 typedef std::map<std::string, Interface*> InterfaceMap; | 328 typedef std::map<std::string, Interface*> InterfaceMap; |
290 InterfaceMap interface_map_; | 329 InterfaceMap interface_map_; |
291 | 330 |
292 // Each managed object consists of a ObjectProxy used to make calls | 331 // Each managed object consists of a ObjectProxy used to make calls |
293 // against that object and a collection of D-Bus interface names and their | 332 // against that object and a collection of D-Bus interface names and their |
294 // associated PropertySet structures. | 333 // associated PropertySet structures. |
295 struct Object { | 334 struct Object { |
(...skipping 17 matching lines...) Expand all Loading... |
313 // Note: This should remain the last member so it'll be destroyed and | 352 // Note: This should remain the last member so it'll be destroyed and |
314 // invalidate its weak pointers before any other members are destroyed. | 353 // invalidate its weak pointers before any other members are destroyed. |
315 base::WeakPtrFactory<ObjectManager> weak_ptr_factory_; | 354 base::WeakPtrFactory<ObjectManager> weak_ptr_factory_; |
316 | 355 |
317 DISALLOW_COPY_AND_ASSIGN(ObjectManager); | 356 DISALLOW_COPY_AND_ASSIGN(ObjectManager); |
318 }; | 357 }; |
319 | 358 |
320 } // namespace dbus | 359 } // namespace dbus |
321 | 360 |
322 #endif // DBUS_OBJECT_MANAGER_H_ | 361 #endif // DBUS_OBJECT_MANAGER_H_ |
OLD | NEW |