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 */ PowerInterface(ThermalAlertObject & alertObject)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 */ thermalAlert(bool alert)81 void thermalAlert(bool alert) override 82 { 83 _alert.enabled(alert); 84 } 85 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 94 private: 95 /** 96 * @brief Reference to the thermal alert D-Bus object 97 */ 98 ThermalAlertObject& _alert; 99 }; 100 101 } // namespace phosphor::fan::monitor 102