| #include "host_monitor_app.hpp" |
| |
| #include "boot_manager.hpp" |
| #include "dbus_handler.hpp" |
| #include "utils.hpp" |
| |
| #include <fmt/printf.h> |
| |
| #include <boost/container/flat_map.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/bus/match.hpp> |
| #include <sdbusplus/message.hpp> |
| |
| #include <memory> |
| #include <string> |
| #include <string_view> |
| #include <variant> |
| |
| namespace boot_time_monitor |
| { |
| |
| constexpr std::string_view kHostPath = "/xyz/openbmc_project/state/host0"; |
| constexpr std::string_view kHostIface = "xyz.openbmc_project.State.Host"; |
| constexpr std::string_view kHostProperty = "CurrentHostState"; |
| |
| constexpr std::string_view kHostStateRunning = |
| "xyz.openbmc_project.State.Host.HostState.Running"; |
| constexpr std::string_view kHostStateOff = |
| "xyz.openbmc_project.State.Host.HostState.Off"; |
| |
| HostMonitorApp::HostMonitorApp(sdbusplus::bus::bus& bus, uint32_t hostNum) : |
| kNodeName(std::string{"host"} + std::to_string(hostNum)), |
| kObjPath(std::string{"/xyz/openbmc_project/time/boot/"} + kNodeName), |
| objManager(bus, kObjPath.c_str()) |
| { |
| util = std::make_shared<Util>(); |
| cpCSV = std::make_shared<FileUtil>(util->getCPPath(kNodeName, false)); |
| durCSV = std::make_shared<FileUtil>(util->getDurPath(kNodeName, false)); |
| bootManager = std::make_shared<BootManager>(util, cpCSV, durCSV); |
| dbusHandler = std::make_shared<DbusHandler>(bus, kObjPath.data(), |
| bootManager, util); |
| |
| powerMatcher = std::make_unique<sdbusplus::bus::match::match>( |
| bus, |
| sdbusplus::bus::match::rules::propertiesChanged(kHostPath.data(), |
| kHostIface.data()), |
| [this](sdbusplus::message::message& message) { |
| constexpr std::string_view kS0 = "S0"; |
| constexpr std::string_view kS5 = "S5"; |
| |
| std::string objectName; |
| boost::container::flat_map< |
| std::string, |
| std::variant<std::string, bool, int64_t, uint64_t, double>> |
| values; |
| message.read(objectName, values); |
| |
| auto findState = values.find(kHostProperty.data()); |
| if (findState != values.end()) |
| { |
| if (std::get<std::string>(findState->second) == kHostStateRunning) |
| { |
| bootManager->setCheckpoint(kS0.data(), 0, 0); |
| } |
| else if (std::get<std::string>(findState->second) == kHostStateOff) |
| { |
| bootManager->setCheckpoint(kS5.data(), 0, 0); |
| } |
| } |
| }); |
| } |
| |
| } // namespace boot_time_monitor |