| #pragma once | |
| #include "boottime_api/node_config.h" | |
| #include "dbus_handler.hpp" | |
| #include "psm_handler.hpp" | |
| #include <fmt/printf.h> | |
| #include <string_view> | |
| #include <vector> | |
| namespace boot_time_monitor | |
| { | |
| /** | |
| * @brief Contains helper functions for generating configuration objects and | |
| * names. | |
| * | |
| * This namespace provides utility functions to create configuration structures | |
| * (like PSMConfig and DbusConfig) and standardized node names based on system | |
| * properties like the number of hosts or BMCs and their indices. | |
| */ | |
| namespace gen | |
| { | |
| namespace btm = boot_time_monitor; | |
| /** | |
| * @brief Generates the PSM D-Bus configuration for a specific host. | |
| * | |
| * This function constructs the necessary D-Bus service names and object paths | |
| * for the phosphor-state-manager (PSM) based on a host's numerical index. | |
| * This configuration is used to monitor host state and OS status changes. | |
| * | |
| * @param idx The zero-based index of the host. | |
| * @return psm::PSMConfig The generated PSM configuration. | |
| */ | |
| inline psm::PSMConfig GenPSMConfig(int idx) | |
| { | |
| std::vector<btm::psm::DbusServiceLocation> possibleOsStatus = { | |
| // New multi host nodes style. | |
| {"xyz.openbmc_project.State.OperatingSystem", | |
| fmt::format("/xyz/openbmc_project/state/host{}", idx)}, | |
| {fmt::format("xyz.openbmc_project.State.OperatingSystem{}", idx), | |
| fmt::format("/xyz/openbmc_project/state/host{}", idx)}, | |
| {fmt::format("xyz.openbmc_project.State.OperatingSystem{}", idx), | |
| fmt::format("/xyz/openbmc_project/state/os{}", idx)}, | |
| // Old multi host nodes style. | |
| {fmt::format("xyz.openbmc_project.State.OperatingSystem{}", idx), | |
| "/xyz/openbmc_project/state/os"}, | |
| }; | |
| if (idx == 0) | |
| { | |
| // Legacy style is only valid if idx == 0. Do not try this interface | |
| // on other host nodes. | |
| possibleOsStatus.push_back({"xyz.openbmc_project.State.OperatingSystem", | |
| "/xyz/openbmc_project/state/os"}); | |
| } | |
| return { | |
| .hostState = {fmt::format("xyz.openbmc_project.State.Host{}", idx), | |
| fmt::format("/xyz/openbmc_project/state/host{}", idx)}, | |
| .possibleOsStatus = possibleOsStatus, | |
| }; | |
| } | |
| /** | |
| * @brief Generates the D-Bus configuration for a specific node. | |
| * | |
| * Constructs the D-Bus object path for the boot time monitor interfaces | |
| * based on the node's name. | |
| * | |
| * @param nodeConfig The configuration of the node. | |
| * @return dbus::DbusConfig The generated D-Bus configuration containing the | |
| * object path. | |
| */ | |
| inline dbus::DbusConfig GenDbusConfig(const btm::NodeConfig& nodeConfig) | |
| { | |
| return {.dbusObjPath = fmt::format("/xyz/openbmc_project/time/boot/{}", | |
| nodeConfig.node_name)}; | |
| } | |
| /** | |
| * @brief Generates a standard host node name based on its index. | |
| * | |
| * @param idx The zero-based index of the host. | |
| * @return std::string The generated host node name (e.g., "host0", "host1"). | |
| */ | |
| inline std::string GenHostNodeName(int idx) | |
| { | |
| return fmt::format("host{}", idx); | |
| } | |
| /** | |
| * @brief Generates a standard BMC node name based on the total number of BMCs | |
| * and its index. | |
| * @param bmcAmount The total number of BMCs in the system. | |
| * @param idx The zero-based index of this BMC. | |
| * @return std::string The generated BMC node name (e.g., "bmc" for single BMC, | |
| * "bmc0", "bmc1" for multiple). | |
| */ | |
| inline std::string GenBmcNodeName(int64_t bmcAmount, int idx) | |
| { | |
| if (bmcAmount == 1) | |
| { | |
| return "bmc"; | |
| } | |
| return fmt::format("bmc{}", idx); | |
| } | |
| } // namespace gen | |
| } // namespace boot_time_monitor |