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)
{
diff --git a/control/json/manager.hpp b/control/json/manager.hpp
index e449145..c807252 100644
--- a/control/json/manager.hpp
+++ b/control/json/manager.hpp
@@ -270,6 +270,15 @@
static bool hasOwner(const std::string& path, const std::string& intf);
/**
+ * @brief Sets the dbus service owner state for all entries in the _servTree
+ * cache and removes associated objects from the _objects cache
+ *
+ * @param[in] serv - Dbus service name
+ * @param[in] hasOwner - Dbus service owner state
+ */
+ void setOwner(const std::string& serv, bool hasOwner);
+
+ /**
* @brief Sets the dbus service owner state of a given object
*
* @param[in] path - Dbus object path
diff --git a/control/json/triggers/handlers.hpp b/control/json/triggers/handlers.hpp
index f4e7adb..15bced0 100644
--- a/control/json/triggers/handlers.hpp
+++ b/control/json/triggers/handlers.hpp
@@ -1,6 +1,9 @@
#pragma once
#include "../manager.hpp"
+#include "../utils/flight_recorder.hpp"
+
+#include <fmt/format.h>
#include <sdbusplus/message.hpp>
@@ -127,13 +130,12 @@
/**
* @brief Processes a name owner changed signal and updates the service's
- * owner state
+ * owner state for all objects/interfaces associated in the cache
*
* @param[in] msg - The sdbusplus signal message
- * @param[in] obj - Object data associated with the signal
* @param[in] mgr - Manager that stores the service's owner state
*/
- static bool nameOwnerChanged(message& msg, const SignalObject& obj,
+ static bool nameOwnerChanged(message& msg, const SignalObject&,
Manager& mgr)
{
bool hasOwner = false;
@@ -150,8 +152,10 @@
{
hasOwner = true;
}
-
- mgr.setOwner(std::get<Path>(obj), serv, std::get<Intf>(obj), hasOwner);
+ FlightRecorder::instance().log(
+ "nameOwnerChanged", fmt::format("Service: {}, Owned: {}", serv,
+ hasOwner ? "true" : "false"));
+ mgr.setOwner(serv, hasOwner);
return true;
}
diff --git a/control/json/triggers/signal.cpp b/control/json/triggers/signal.cpp
index 7a2dce0..9f7caa3 100644
--- a/control/json/triggers/signal.cpp
+++ b/control/json/triggers/signal.cpp
@@ -188,12 +188,8 @@
// Setup name owner changed signal handler on the group
// member's service
const auto match = rules::nameOwnerChanged(serv);
- SignalPkg signalPkg = {
- Handlers::nameOwnerChanged,
- SignalObject(std::cref(member),
- std::cref(group.getInterface()),
- std::cref(group.getProperty())),
- actions};
+ SignalPkg signalPkg = {Handlers::nameOwnerChanged,
+ SignalObject(), actions};
// If signal match already exists, then the service will be the
// same so add action to be run
auto isSameSig = [](SignalPkg& pkg) { return true; };