1 #pragma once 2 3 #include "types.hpp" 4 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; 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; 40 }; 41 42 /** 43 * @class PowerInterface 44 * 45 * Concrete class to perform power offs 46 */ 47 class PowerInterface : public PowerInterfaceBase 48 { 49 public: 50 PowerInterface() = delete; 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 /** 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 /** 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; 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 86 private: 87 /** 88 * @brief Reference to the thermal alert D-Bus object 89 */ 90 ThermalAlertObject& _alert; 91 }; 92 93 } // namespace phosphor::fan::monitor 94