| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // : bus_(bus), | 64 // : bus_(bus), |
| 65 // weak_ptr_factory_(this) { | 65 // weak_ptr_factory_(this) { |
| 66 // object_manager_ = bus_->GetObjectManager(kServiceName, kManagerPath); | 66 // object_manager_ = bus_->GetObjectManager(kServiceName, kManagerPath); |
| 67 // object_manager_->RegisterInterface(kInterface, this); | 67 // object_manager_->RegisterInterface(kInterface, this); |
| 68 // } | 68 // } |
| 69 // | 69 // |
| 70 // virtual ExampleClient::~ExampleClient() { | 70 // virtual ExampleClient::~ExampleClient() { |
| 71 // object_manager_->UnregisterInterface(kInterface); | 71 // object_manager_->UnregisterInterface(kInterface); |
| 72 // } | 72 // } |
| 73 // | 73 // |
| 74 // The D-Bus thread manager takes care of issuing the necessary call to | 74 // This class calls GetManagedObjects() asynchronously after the remote service |
| 75 // GetManagedObjects() after the implementation classes have been set up. | 75 // becomes available and additionally refreshes managed objects after the |
| 76 // service stops or restarts. |
| 76 // | 77 // |
| 77 // The object manager interface class has one abstract method that must be | 78 // The object manager interface class has one abstract method that must be |
| 78 // implemented by the class to create Properties structures on demand. As well | 79 // implemented by the class to create Properties structures on demand. As well |
| 79 // as implementing this, you will want to implement a public GetProperties() | 80 // as implementing this, you will want to implement a public GetProperties() |
| 80 // method. | 81 // method. |
| 81 // | 82 // |
| 82 // Example: | 83 // Example: |
| 83 // dbus::PropertySet* CreateProperties(dbus::ObjectProxy* object_proxy, | 84 // dbus::PropertySet* CreateProperties(dbus::ObjectProxy* object_proxy, |
| 84 // const std::string& interface_name) | 85 // const std::string& interface_name) |
| 85 // override { | 86 // override { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // | 232 // |
| 232 // BLOCKING CALL. | 233 // BLOCKING CALL. |
| 233 void CleanUp(); | 234 void CleanUp(); |
| 234 | 235 |
| 235 protected: | 236 protected: |
| 236 virtual ~ObjectManager(); | 237 virtual ~ObjectManager(); |
| 237 | 238 |
| 238 private: | 239 private: |
| 239 friend class base::RefCountedThreadSafe<ObjectManager>; | 240 friend class base::RefCountedThreadSafe<ObjectManager>; |
| 240 | 241 |
| 241 // Connects the InterfacesAdded and InterfacesRemoved signals and calls | |
| 242 // GetManagedObjects. Called from OnSetupMatchRuleAndFilterComplete. | |
| 243 void InitializeObjects(); | |
| 244 | |
| 245 // Called from the constructor to add a match rule for PropertiesChanged | 242 // Called from the constructor to add a match rule for PropertiesChanged |
| 246 // signals on the DBus thread and set up a corresponding filter function. | 243 // signals on the D-Bus thread and set up a corresponding filter function. |
| 247 bool SetupMatchRuleAndFilter(); | 244 bool SetupMatchRuleAndFilter(); |
| 248 | 245 |
| 249 // Called on the origin thread once the match rule and filter have been set | 246 // Called on the origin thread once the match rule and filter have been set |
| 250 // up. |success| is false, if an error occurred during set up; it's true | 247 // up. Connects the InterfacesAdded and InterfacesRemoved signals and |
| 251 // otherwise. | 248 // refreshes objects if the service is available. |success| is false if an |
| 249 // error occurred during setup and true otherwise. |
| 252 void OnSetupMatchRuleAndFilterComplete(bool success); | 250 void OnSetupMatchRuleAndFilterComplete(bool success); |
| 253 | 251 |
| 254 // Called by dbus:: when a message is received. This is used to filter | 252 // Called by dbus:: when a message is received. This is used to filter |
| 255 // PropertiesChanged signals from the correct sender and relay the event to | 253 // PropertiesChanged signals from the correct sender and relay the event to |
| 256 // the correct PropertySet. | 254 // the correct PropertySet. |
| 257 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, | 255 static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, |
| 258 DBusMessage* raw_message, | 256 DBusMessage* raw_message, |
| 259 void* user_data); | 257 void* user_data); |
| 260 DBusHandlerResult HandleMessage(DBusConnection* connection, | 258 DBusHandlerResult HandleMessage(DBusConnection* connection, |
| 261 DBusMessage* raw_message); | 259 DBusMessage* raw_message); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // Note: This should remain the last member so it'll be destroyed and | 353 // Note: This should remain the last member so it'll be destroyed and |
| 356 // invalidate its weak pointers before any other members are destroyed. | 354 // invalidate its weak pointers before any other members are destroyed. |
| 357 base::WeakPtrFactory<ObjectManager> weak_ptr_factory_; | 355 base::WeakPtrFactory<ObjectManager> weak_ptr_factory_; |
| 358 | 356 |
| 359 DISALLOW_COPY_AND_ASSIGN(ObjectManager); | 357 DISALLOW_COPY_AND_ASSIGN(ObjectManager); |
| 360 }; | 358 }; |
| 361 | 359 |
| 362 } // namespace dbus | 360 } // namespace dbus |
| 363 | 361 |
| 364 #endif // DBUS_OBJECT_MANAGER_H_ | 362 #endif // DBUS_OBJECT_MANAGER_H_ |
| OLD | NEW |