Faisal Awada | 348168b | 2025-07-08 11:23:02 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "chassis.hpp" |
| 4 | #include "types.hpp" |
| 5 | #include "utility.hpp" |
| 6 | |
| 7 | #include <sdbusplus/bus/match.hpp> |
| 8 | #include <sdbusplus/server/manager.hpp> |
| 9 | #include <sdbusplus/server/object.hpp> |
| 10 | #include <sdeventplus/event.hpp> |
| 11 | #include <sdeventplus/utility/timer.hpp> |
| 12 | #include <xyz/openbmc_project/State/Decorator/PowerSystemInputs/server.hpp> |
| 13 | |
| 14 | using namespace phosphor::power::psu; |
| 15 | |
| 16 | namespace phosphor::power::chassis_manager |
| 17 | { |
| 18 | |
| 19 | // Validation timeout. Allow 30s to detect if new EM interfaces show up in D-Bus |
| 20 | // before performing the validation. |
| 21 | constexpr auto validationTimeout = std::chrono::seconds(30); |
| 22 | |
| 23 | /** |
| 24 | * @class ChassisManager |
| 25 | * |
| 26 | * @brief Manages and monitors power supply devices for the chassis. |
| 27 | * |
| 28 | * @detail This class interacts with D-Bus to detect chassis power supply, |
| 29 | * subscribe to Entity Manager interface changes. |
| 30 | */ |
| 31 | class ChassisManager |
| 32 | { |
| 33 | public: |
| 34 | ChassisManager() = delete; |
| 35 | ~ChassisManager() = default; |
| 36 | ChassisManager(const ChassisManager&) = delete; |
| 37 | ChassisManager& operator=(const ChassisManager&) = delete; |
| 38 | ChassisManager(ChassisManager&&) = delete; |
| 39 | ChassisManager& operator=(ChassisManager&&) = delete; |
| 40 | |
| 41 | /** |
| 42 | * @brief Constructs a ChassisManager instance. |
| 43 | * |
| 44 | * @details Sets up D-Bus interfaces, creates timer for power supply |
| 45 | * validation and monitoring, and subscribes to entity-manager interfaces. |
| 46 | * |
| 47 | * @param[in] bus - Reference to the system D-Bus object. |
| 48 | * @param[in] e - Reference to event loop. |
| 49 | */ |
| 50 | ChassisManager(sdbusplus::bus_t& bus, const sdeventplus::Event& e); |
| 51 | |
| 52 | /** |
| 53 | * @brief Starts the main event loop for monitoring. |
| 54 | * |
| 55 | * @return int Returns the result the result of the event loop execution. |
| 56 | */ |
| 57 | int run() |
| 58 | { |
| 59 | return timer->get_event().loop(); |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | /** |
| 64 | * @brief The D-Bus object |
| 65 | */ |
| 66 | sdbusplus::bus_t& bus; |
| 67 | |
| 68 | /** |
| 69 | * @brief The timer that runs to periodically check the power supplies. |
| 70 | */ |
| 71 | std::unique_ptr< |
| 72 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic>> |
| 73 | timer; |
| 74 | |
| 75 | /** |
| 76 | * @brief Used to subscribe to Entity Manager interfaces added |
| 77 | */ |
| 78 | std::unique_ptr<sdbusplus::bus::match_t> entityManagerIfacesAddedMatch; |
| 79 | |
| 80 | /** |
| 81 | * @brief List of chassis objects populated dynamically. |
| 82 | */ |
| 83 | std::vector<std::unique_ptr<phosphor::power::chassis::Chassis>> |
| 84 | listOfChassis; |
| 85 | |
| 86 | /** |
| 87 | * @brief Declares a constant reference to an sdeventplus::Envent to manage |
| 88 | * async processing. |
| 89 | */ |
| 90 | const sdeventplus::Event& eventLoop; |
| 91 | |
| 92 | /** |
| 93 | * @brief Callback for entity-manager interface added |
| 94 | * |
| 95 | * @details Process the information from the supported configuration and |
| 96 | * or IBM CFFPS Connector interface being added. |
| 97 | * |
| 98 | * @param[in] msg - D-Bus message containing the interface details. |
| 99 | */ |
| 100 | void entityManagerIfaceAdded(sdbusplus::message_t& msg); |
| 101 | |
| 102 | /** |
| 103 | * @brief Invoke the PSU analysis method in each chassis on the system. |
| 104 | * |
| 105 | * @details Scan the system for chassis and analyze each chassis power |
| 106 | * supplies and log any detected errors. |
| 107 | */ |
| 108 | void analyze(); |
| 109 | |
| 110 | /** |
| 111 | * @brief Initialize the list of chassis object from the inventory, scans |
| 112 | * the D-Bus subtree for chassis and creates Chassis instances. |
| 113 | */ |
| 114 | void initializeChassisList(); |
| 115 | |
| 116 | /** |
| 117 | * @brief Retrieves a pointer to a Chassis object matching the given ID. |
| 118 | * |
| 119 | * @param[in] chassisId - Unique identifier of the chassis to search for. |
| 120 | * @return Raw pointer to the matching Chassis object if found, otherwise a |
| 121 | * nullptr. |
| 122 | */ |
| 123 | phosphor::power::chassis::Chassis* getMatchingChassisPtr( |
| 124 | uint64_t chassisId); |
| 125 | }; |
| 126 | |
| 127 | } // namespace phosphor::power::chassis_manager |