summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng C Yang <cheng.c.yang@intel.com>2019-08-07 03:01:32 +0300
committerCheng C Yang <cheng.c.yang@intel.com>2019-08-07 03:01:32 +0300
commit35478dce1b79e65d3a0862baf0b99166809da700 (patch)
tree6e72c5ab063e83869c8b1d53d5c94d8d8a096f6c
parenta7c102ccff9ed8ccc0c3b6c1a9558c7e0a26a769 (diff)
downloadprovingground-35478dce1b79e65d3a0862baf0b99166809da700.tar.xz
Checking PSU event to set PSU status
Checking PSU event to see if PSUs are normal status or not. Tested: Remove one PSU, check the PSU status is in ACLost. Change-Id: I1d83e1544d77adeed0b8961be5ae470330b5e9ab Signed-off-by: Cheng C Yang <cheng.c.yang@intel.com>
-rw-r--r--psu-manager/src/cold_redundancy.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/psu-manager/src/cold_redundancy.cpp b/psu-manager/src/cold_redundancy.cpp
index 118627d..81169a8 100644
--- a/psu-manager/src/cold_redundancy.cpp
+++ b/psu-manager/src/cold_redundancy.cpp
@@ -74,6 +74,64 @@ ColdRedundancy::ColdRedundancy(
createPSU(io, objectServer, systemBus);
});
};
+
+ std::function<void(sdbusplus::message::message&)> eventCollect =
+ [&](sdbusplus::message::message& message) {
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<bool>> values;
+ std::string path = message.get_path();
+ std::size_t slantingPos = path.find_last_of("/\\");
+ if ((slantingPos == std::string::npos) ||
+ ((slantingPos + 1) >= path.size()))
+ {
+ std::cerr << "Unable to get PSU state name from path\n";
+ return;
+ }
+ std::string statePSUName = path.substr(slantingPos + 1);
+ bool stateChanged = false;
+
+ std::size_t hypenPos = statePSUName.find("_");
+ if (hypenPos == std::string::npos)
+ {
+ std::cerr << "Unable to get PSU name from PSU path\n";
+ return;
+ }
+ std::string psuName = statePSUName.substr(0, hypenPos);
+
+ try
+ {
+ message.read(objectName, values);
+ }
+ catch (const sdbusplus::exception::exception& e)
+ {
+ std::cerr << "Failed to read message from PSU Event\n";
+ return;
+ }
+
+ for (auto& psu : powerSupplies)
+ {
+
+ if (psu->name != psuName)
+ {
+ continue;
+ }
+
+ std::string psuEventName = "OperationalStatus";
+ auto findEvent = values.find(psuEventName);
+ if (findEvent != values.end())
+ {
+ if (std::get<bool>(findEvent->second))
+ {
+ psu->state = PSUState::acLost;
+ }
+ else
+ {
+ psu->state = PSUState::normal;
+ }
+ }
+ }
+ };
+
for (const char* type : psuInterfaceTypes)
{
auto match = std::make_unique<sdbusplus::bus::match::match>(
@@ -84,6 +142,16 @@ ColdRedundancy::ColdRedundancy(
matches.emplace_back(std::move(match));
}
+ for (const char* eventType : psuEventInterface)
+ {
+ auto eventMatch = std::make_unique<sdbusplus::bus::match::match>(
+ static_cast<sdbusplus::bus::bus&>(*systemBus),
+ "type='signal',member='PropertiesChanged',path_namespace='" +
+ std::string(eventPath) + "',arg0namespace='" + eventType + "'",
+ eventCollect);
+ matches.emplace_back(std::move(eventMatch));
+ }
+
io.run();
}