control: `nameOwnerChanged` signals update all caches
When a `nameOwnerChanged` signal is received, update all entries within
the service tree cache for the given service's owner state change. Also,
use the service tree cache to cross reference removal of the associated
interfaces from objects within the objects cache.
Change-Id: Idab52a7533d626f1f7ef03397f904a74cb6457a3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index def8d95..c45c873 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -310,6 +310,29 @@
return false;
}
+void Manager::setOwner(const std::string& serv, bool hasOwner)
+{
+ // Update owner state on all entries of `serv`
+ for (auto& itPath : _servTree)
+ {
+ auto itServ = itPath.second.find(serv);
+ if (itServ != itPath.second.end())
+ {
+ itServ->second.first = hasOwner;
+
+ // Remove associated interfaces from object cache when service no
+ // longer has an owner
+ if (!hasOwner && _objects.find(itPath.first) != _objects.end())
+ {
+ for (auto& intf : itServ->second.second)
+ {
+ _objects[itPath.first].erase(intf);
+ }
+ }
+ }
+ }
+}
+
void Manager::setOwner(const std::string& path, const std::string& serv,
const std::string& intf, bool isOwned)
{