| #pragma once |
| |
| #include "boottime_api/boottime_api.h" |
| #include "boottime_api/node_config.h" |
| |
| #include <boost/asio/steady_timer.hpp> |
| #include <boost/container/flat_map.hpp> |
| #include <sdbusplus/asio/connection.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/bus/match.hpp> |
| #include <sdbusplus/message.hpp> |
| |
| #include <string> |
| |
| namespace boot_time_monitor |
| { |
| /** |
| * @brief Contains functionality related to interacting with the |
| * [Phosphor-state-manager](https://github.com/openbmc/phosphor-state-manager) |
| * (PSM). |
| */ |
| namespace psm |
| { |
| |
| namespace btm = boot_time_monitor; |
| |
| // Define a structure to hold a path and interface pair. |
| struct DbusServiceLocation |
| { |
| std::string serviceName; |
| std::string objectPath; |
| }; |
| |
| /** |
| * @brief Configuration for interacting with PSM D-Bus interfaces. |
| * |
| * Stores the necessary D-Bus service names and object paths required to |
| * monitor host state and operating system status properties. |
| */ |
| struct PSMConfig |
| { |
| /** @brief Host State D-Bus interface (e.g., |
| * "xyz.openbmc_project.State.Host", |
| * "/xyz/openbmc_project/state/host0"). */ |
| DbusServiceLocation hostState; |
| /** @brief OS Status D-Bus (e.g. |
| * "xyz.openbmc_project.State.OperatingSystem" |
| * "/xyz/openbmc_project/state/os"). */ |
| std::vector<DbusServiceLocation> possibleOsStatus; |
| }; |
| |
| /** |
| * @brief Handles monitoring of Platform State Manager (PSM) D-Bus signals for a |
| * specific node. |
| * |
| * This class sets up D-Bus match rules to listen for property changes on |
| * the Host State (`xyz.openbmc_project.State.Host`) and OS Status |
| * (`xyz.openbmc_project.State.OperatingSystem.Status`) interfaces defined |
| * in the `PSMConfig`. When a relevant property changes (e.g., |
| * `CurrentHostState`, `OperatingSystemState`), it translates the new state |
| * into a checkpoint name and records it using the provided `IApi` instance |
| * for the associated `NodeConfig`. |
| */ |
| class Handler |
| { |
| public: |
| /** |
| * @brief Constructs the PSM Handler. |
| * |
| * Initializes previous state variables by querying current D-Bus properties |
| * and sets up D-Bus match rules to monitor for future changes. |
| * |
| * @param bus The sdbusplus bus connection. |
| * @param nodeConfig Configuration of the node this handler monitors. |
| * @param psmConfig D-Bus configuration for PSM interfaces. |
| * @param api Shared pointer to the central boot time monitoring API. |
| */ |
| Handler(sdbusplus::bus::bus& bus, const btm::NodeConfig& nodeConfig, |
| const btm::psm::PSMConfig& psmConfig, |
| std::shared_ptr<btm::api::IBoottimeApi> api); |
| |
| private: |
| /** @brief Callback for hostStateWatcher */ |
| void hostStateWatcherCallback(sdbusplus::message::message& message); |
| /** @brief Callback for oSStatusWatcher */ |
| void oSStatusWatcherCallback(sdbusplus::message::message& message); |
| |
| /** @brief Stores the previously observed Host State to detect changes. */ |
| std::string mPreHostState; |
| /** @brief Stores the previously observed OS State/Status to detect changes. |
| */ |
| std::string mPreOSStatus; |
| /** @brief Configuration of the node associated with this handler. */ |
| btm::NodeConfig mNodeConfig; |
| /** @brief Shared pointer to the central boot time monitoring API. */ |
| std::shared_ptr<btm::api::IBoottimeApi> mApi; |
| /** @brief D-Bus match rule watcher for Host State property changes. */ |
| std::unique_ptr<sdbusplus::bus::match::match> mHostStateWatcher; |
| /** @brief D-Bus match rule watcher for OS Status property changes. */ |
| std::vector<std::unique_ptr<sdbusplus::bus::match::match>> mOSStatusWatcher; |
| }; |
| } // namespace psm |
| } // namespace boot_time_monitor |