Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 3 | #include "types.hpp" |
| 4 | |
Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 5 | namespace phosphor::fan::monitor |
| 6 | { |
| 7 | |
| 8 | /** |
| 9 | * @class PowerInterfaceBase |
| 10 | * |
| 11 | * The base class that contains the APIs to do power offs. |
| 12 | * This is required so it can be mocked in testcases. |
| 13 | */ |
| 14 | class PowerInterfaceBase |
| 15 | { |
| 16 | public: |
| 17 | PowerInterfaceBase() = default; |
| 18 | virtual ~PowerInterfaceBase() = default; |
| 19 | PowerInterfaceBase(const PowerInterfaceBase&) = delete; |
| 20 | PowerInterfaceBase& operator=(const PowerInterfaceBase&) = delete; |
| 21 | PowerInterfaceBase(PowerInterfaceBase&&) = delete; |
| 22 | PowerInterfaceBase& operator=(PowerInterfaceBase&&) = delete; |
| 23 | |
| 24 | /** |
| 25 | * @brief Perform a soft power off |
| 26 | */ |
| 27 | virtual void softPowerOff() = 0; |
| 28 | |
| 29 | /** |
| 30 | * @brief Perform a hard power off |
| 31 | */ |
| 32 | virtual void hardPowerOff() = 0; |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * @brief Sets the thermal alert D-Bus property |
| 36 | * |
| 37 | * @param[in] alert - The alert value |
| 38 | */ |
| 39 | virtual void thermalAlert(bool alert) = 0; |
Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * @class PowerInterface |
| 44 | * |
| 45 | * Concrete class to perform power offs |
| 46 | */ |
| 47 | class PowerInterface : public PowerInterfaceBase |
| 48 | { |
| 49 | public: |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 50 | PowerInterface() = delete; |
Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 51 | ~PowerInterface() = default; |
| 52 | PowerInterface(const PowerInterface&) = delete; |
| 53 | PowerInterface& operator=(const PowerInterface&) = delete; |
| 54 | PowerInterface(PowerInterface&&) = delete; |
| 55 | PowerInterface& operator=(PowerInterface&&) = delete; |
| 56 | |
| 57 | /** |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 58 | * @brief Constructor |
| 59 | * |
| 60 | * @param[in] ThermalAlertObject& - The thermal alert D-Bus object |
| 61 | */ |
| 62 | explicit PowerInterface(ThermalAlertObject& alertObject) : |
| 63 | _alert(alertObject) |
| 64 | {} |
| 65 | |
| 66 | /** |
Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 67 | * @brief Perform a soft power off |
| 68 | */ |
| 69 | void softPowerOff() override; |
| 70 | |
| 71 | /** |
| 72 | * @brief Perform a hard power off |
| 73 | */ |
| 74 | void hardPowerOff() override; |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * @brief Sets the thermal alert D-Bus property |
| 78 | * |
| 79 | * @param[in] alert - The alert value |
| 80 | */ |
| 81 | void thermalAlert(bool alert) override |
| 82 | { |
| 83 | _alert.enabled(alert); |
| 84 | } |
| 85 | |
Matt Spinler | bb449c1 | 2021-06-14 11:45:28 -0600 | [diff] [blame] | 86 | /** |
| 87 | * @brief Calls the D-Bus method to execute the hard power off. |
| 88 | * |
| 89 | * A static function so this can be used by code that doesn't |
| 90 | * want to create a PowerInterface object. |
| 91 | */ |
| 92 | static void executeHardPowerOff(); |
| 93 | |
Matt Spinler | ba3ee9a | 2021-01-06 14:45:50 -0600 | [diff] [blame] | 94 | private: |
| 95 | /** |
| 96 | * @brief Reference to the thermal alert D-Bus object |
| 97 | */ |
| 98 | ThermalAlertObject& _alert; |
Matt Spinler | 69b0cf0 | 2020-10-14 10:59:03 -0500 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | } // namespace phosphor::fan::monitor |