From 908f75075bfb4ece993d6dcfb00ceccbe3983f59 Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Mon, 10 Jul 2017 01:49:54 -0500 Subject: cater for property change signal to invalidate fru data Resolves openbmc/openbmc#1560 Change-Id: I90897959dab76181a6006c372c4b60cc1bdd0c0c Signed-off-by: Marri Devender Rao --- read_fru_data.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'read_fru_data.cpp') diff --git a/read_fru_data.cpp b/read_fru_data.cpp index 5388926..b23498e 100644 --- a/read_fru_data.cpp +++ b/read_fru_data.cpp @@ -7,7 +7,6 @@ #include "utils.hpp" extern const FruMap frus; - namespace ipmi { namespace fru @@ -15,6 +14,7 @@ namespace fru using namespace phosphor::logging; using InternalFailure = sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; +std::unique_ptr matchPtr(nullptr); static constexpr auto INV_INTF = "xyz.openbmc_project.Inventory.Manager"; static constexpr auto OBJ_PATH = "/xyz/openbmc_project/inventory"; @@ -66,6 +66,57 @@ std::string readProperty(const std::string& intf, return value; } +void processFruPropChange(sdbusplus::message::message& msg) +{ + if(cache::fruMap.empty()) + { + return; + } + std::string path = msg.get_path(); + //trim the object base path, if found at the beginning + if (path.compare(0, strlen(OBJ_PATH), OBJ_PATH) == 0) + { + path.erase(0, strlen(OBJ_PATH)); + } + for (auto& fru : frus) + { + bool found = false; + auto& fruId = fru.first; + auto& instanceList = fru.second; + for (auto& instance : instanceList) + { + if(instance.first == path) + { + found = true; + break; + } + } + if (found) + { + cache::fruMap.erase(fruId); + break; + } + } +} + +//register for fru property change +int registerCallbackHandler() +{ + if(matchPtr == nullptr) + { + using namespace sdbusplus::bus::match::rules; + sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; + matchPtr = std::make_unique( + bus, + path_namespace(OBJ_PATH) + + type::signal() + + member("PropertiesChanged") + + interface(PROP_INTF), + std::bind(processFruPropChange, std::placeholders::_1)); + } + return 0; +} + /** * @brief Read FRU property values from Inventory * -- cgit v1.2.1