Brandon Wyman | 2bac860 | 2019-09-12 18:12:21 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus/match.hpp> |
| 4 | #include <sdeventplus/event.hpp> |
| 5 | #include <sdeventplus/utility/timer.hpp> |
| 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace power |
| 10 | { |
| 11 | namespace manager |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @class PSUManager |
| 16 | * |
| 17 | * This class will create an object used to manage and monitor a list of power |
| 18 | * supply devices. |
| 19 | */ |
| 20 | class PSUManager |
| 21 | { |
| 22 | public: |
| 23 | PSUManager() = delete; |
| 24 | ~PSUManager() = default; |
| 25 | PSUManager(const PSUManager&) = delete; |
| 26 | PSUManager& operator=(const PSUManager&) = delete; |
| 27 | PSUManager(PSUManager&&) = delete; |
| 28 | PSUManager& operator=(PSUManager&&) = delete; |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | * |
| 33 | * @param[in] bus - D-Bus bus object |
| 34 | * @param[in] e - event object |
| 35 | * @param[in] i - polling interval in milliseconds |
| 36 | */ |
| 37 | PSUManager(sdbusplus::bus::bus& bus, const sdeventplus::Event& e, |
| 38 | std::chrono::milliseconds i) : |
| 39 | bus(bus), |
| 40 | timer(e, std::bind(&PSUManager::analyze, this), i) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Initializes the manager. |
| 46 | * |
| 47 | * Get current BMC state, ... |
| 48 | */ |
| 49 | void initialize() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Starts the timer to start monitoring the list of devices. |
| 55 | */ |
| 56 | int run() |
| 57 | { |
| 58 | return timer.get_event().loop(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This function will be called in various situations in order to clear |
| 63 | * any fault status bits that may have been set, in order to start over |
| 64 | * with a clean state. Presence changes and power state changes will want |
| 65 | * to clear any faults logged. |
| 66 | */ |
| 67 | void clearFaults() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | /** |
| 73 | * The D-Bus object |
| 74 | */ |
| 75 | sdbusplus::bus::bus& bus; |
| 76 | |
| 77 | /** |
| 78 | * The timer that runs to periodically check the power supplies. |
| 79 | */ |
| 80 | sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer; |
| 81 | |
| 82 | /** |
| 83 | * Analyze the status of each of the power supplies. |
| 84 | */ |
| 85 | void analyze() |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | /** @brief True if the power is on. */ |
| 90 | bool powerOn = false; |
| 91 | |
| 92 | /** @brief Used to subscribe to D-Bus power on state changes */ |
| 93 | std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch; |
| 94 | |
| 95 | /** |
| 96 | * @brief Updates the poweredOn status by querying D-Bus |
| 97 | * |
| 98 | * The D-Bus property for the system power state will be read to determine |
| 99 | * if the system is powered on or not. |
| 100 | */ |
| 101 | void updatePowerState(); |
| 102 | |
| 103 | /** |
| 104 | * @brief Callback for power state property changes |
| 105 | * |
| 106 | * Process changes to the powered on state property for the system. |
| 107 | * |
| 108 | * @param[in] msg - Data associated with the power state signal |
| 109 | */ |
| 110 | void powerStateChanged(sdbusplus::message::message& msg); |
| 111 | |
| 112 | /** |
| 113 | * @brief Adds properties to the inventory. |
| 114 | * |
| 115 | * Reads the values from the devices and writes them to the associated |
| 116 | * power supply D-Bus inventory objects. |
| 117 | * |
| 118 | * This needs to be done on startup, and each time the presence state |
| 119 | * changes. |
| 120 | */ |
| 121 | void updateInventory(); |
| 122 | }; |
| 123 | |
| 124 | } // namespace manager |
| 125 | } // namespace power |
| 126 | } // namespace phosphor |