entity-manager: create power_status_monitor.cpp
These functions belong to PowerStatusMonitor class but were still in
utils.cpp.
Code was only moved and otherwise unchanged.
Tested: Inspection only.
Change-Id: I179eb53718df376116e056b1285f7d1eb4a0ec22
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/power_status_monitor.cpp b/src/entity_manager/power_status_monitor.cpp
new file mode 100644
index 0000000..cd8b9ca
--- /dev/null
+++ b/src/entity_manager/power_status_monitor.cpp
@@ -0,0 +1,61 @@
+#include "power_status_monitor.hpp"
+
+#include "utils.hpp"
+
+#include <boost/algorithm/string/predicate.hpp>
+#include <sdbusplus/bus/match.hpp>
+
+namespace power
+{
+
+const static constexpr char* busname = "xyz.openbmc_project.State.Host";
+const static constexpr char* interface = "xyz.openbmc_project.State.Host";
+const static constexpr char* path = "/xyz/openbmc_project/state/host0";
+const static constexpr char* property = "CurrentHostState";
+
+bool PowerStatusMonitor::isPowerOn()
+{
+ if (!powerMatch)
+ {
+ throw std::runtime_error("Power Match Not Created");
+ }
+ return powerStatusOn;
+}
+
+void PowerStatusMonitor::setupPowerMatch(
+ const std::shared_ptr<sdbusplus::asio::connection>& conn)
+{
+ powerMatch = std::make_unique<sdbusplus::bus::match_t>(
+ static_cast<sdbusplus::bus_t&>(*conn),
+ "type='signal',interface='" +
+ std::string(em_utils::properties::interface) + "',path='" +
+ std::string(power::path) + "',arg0='" +
+ std::string(power::interface) + "'",
+ [this](sdbusplus::message_t& message) {
+ std::string objectName;
+ boost::container::flat_map<std::string, std::variant<std::string>>
+ values;
+ message.read(objectName, values);
+ auto findState = values.find(power::property);
+ if (findState != values.end())
+ {
+ powerStatusOn = boost::ends_with(
+ std::get<std::string>(findState->second), "Running");
+ }
+ });
+
+ conn->async_method_call(
+ [this](boost::system::error_code ec,
+ const std::variant<std::string>& state) {
+ if (ec)
+ {
+ return;
+ }
+ powerStatusOn =
+ boost::ends_with(std::get<std::string>(state), "Running");
+ },
+ power::busname, power::path, em_utils::properties::interface,
+ em_utils::properties::get, power::interface, power::property);
+}
+
+} // namespace power