summaryrefslogtreecommitdiffstats
path: root/dbus/object_manager.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/object_manager.cc')
-rw-r--r--dbus/object_manager.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/dbus/object_manager.cc b/dbus/object_manager.cc
index 0386228..d8eb569 100644
--- a/dbus/object_manager.cc
+++ b/dbus/object_manager.cc
@@ -32,6 +32,9 @@ ObjectManager::ObjectManager(Bus* bus,
DCHECK(bus_);
object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_);
+ object_proxy_->SetNameOwnerChangedCallback(
+ base::Bind(&ObjectManager::NameOwnerChanged,
+ weak_ptr_factory_.GetWeakPtr()));
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
@@ -292,4 +295,35 @@ void ObjectManager::RemoveInterface(const ObjectPath& object_path,
}
}
+void ObjectManager::NameOwnerChanged(const std::string& old_owner,
+ const std::string& new_owner) {
+ if (!old_owner.empty()) {
+ ObjectMap::iterator iter = object_map_.begin();
+ while (iter != object_map_.end()) {
+ ObjectMap::iterator tmp = iter;
+ ++iter;
+
+ // PropertiesMap is mutated by RemoveInterface, and also Object is
+ // destroyed; easier to collect the object path and interface names
+ // and remove them safely.
+ const dbus::ObjectPath object_path = tmp->first;
+ Object* object = tmp->second;
+ std::vector<std::string> interfaces;
+
+ for (Object::PropertiesMap::iterator piter =
+ object->properties_map.begin();
+ piter != object->properties_map.end(); ++piter)
+ interfaces.push_back(piter->first);
+
+ for (std::vector<std::string>::iterator iiter = interfaces.begin();
+ iiter != interfaces.end(); ++iiter)
+ RemoveInterface(object_path, *iiter);
+ }
+
+ }
+
+ if (!new_owner.empty())
+ GetManagedObjects();
+}
+
} // namespace dbus