169b0cf08SMatt Spinler #pragma once 269b0cf08SMatt Spinler 3ba3ee9aeSMatt Spinler #include "types.hpp" 4ba3ee9aeSMatt Spinler 569b0cf08SMatt Spinler namespace phosphor::fan::monitor 669b0cf08SMatt Spinler { 769b0cf08SMatt Spinler 869b0cf08SMatt Spinler /** 969b0cf08SMatt Spinler * @class PowerInterfaceBase 1069b0cf08SMatt Spinler * 1169b0cf08SMatt Spinler * The base class that contains the APIs to do power offs. 1269b0cf08SMatt Spinler * This is required so it can be mocked in testcases. 1369b0cf08SMatt Spinler */ 1469b0cf08SMatt Spinler class PowerInterfaceBase 1569b0cf08SMatt Spinler { 1669b0cf08SMatt Spinler public: 1769b0cf08SMatt Spinler PowerInterfaceBase() = default; 1869b0cf08SMatt Spinler virtual ~PowerInterfaceBase() = default; 1969b0cf08SMatt Spinler PowerInterfaceBase(const PowerInterfaceBase&) = delete; 2069b0cf08SMatt Spinler PowerInterfaceBase& operator=(const PowerInterfaceBase&) = delete; 2169b0cf08SMatt Spinler PowerInterfaceBase(PowerInterfaceBase&&) = delete; 2269b0cf08SMatt Spinler PowerInterfaceBase& operator=(PowerInterfaceBase&&) = delete; 2369b0cf08SMatt Spinler 2469b0cf08SMatt Spinler /** 2569b0cf08SMatt Spinler * @brief Perform a soft power off 2669b0cf08SMatt Spinler */ 2769b0cf08SMatt Spinler virtual void softPowerOff() = 0; 2869b0cf08SMatt Spinler 2969b0cf08SMatt Spinler /** 3069b0cf08SMatt Spinler * @brief Perform a hard power off 3169b0cf08SMatt Spinler */ 3269b0cf08SMatt Spinler virtual void hardPowerOff() = 0; 33ba3ee9aeSMatt Spinler 34ba3ee9aeSMatt Spinler /** 35ba3ee9aeSMatt Spinler * @brief Sets the thermal alert D-Bus property 36ba3ee9aeSMatt Spinler * 37ba3ee9aeSMatt Spinler * @param[in] alert - The alert value 38ba3ee9aeSMatt Spinler */ 39ba3ee9aeSMatt Spinler virtual void thermalAlert(bool alert) = 0; 4069b0cf08SMatt Spinler }; 4169b0cf08SMatt Spinler 4269b0cf08SMatt Spinler /** 4369b0cf08SMatt Spinler * @class PowerInterface 4469b0cf08SMatt Spinler * 4569b0cf08SMatt Spinler * Concrete class to perform power offs 4669b0cf08SMatt Spinler */ 4769b0cf08SMatt Spinler class PowerInterface : public PowerInterfaceBase 4869b0cf08SMatt Spinler { 4969b0cf08SMatt Spinler public: 50ba3ee9aeSMatt Spinler PowerInterface() = delete; 5169b0cf08SMatt Spinler ~PowerInterface() = default; 5269b0cf08SMatt Spinler PowerInterface(const PowerInterface&) = delete; 5369b0cf08SMatt Spinler PowerInterface& operator=(const PowerInterface&) = delete; 5469b0cf08SMatt Spinler PowerInterface(PowerInterface&&) = delete; 5569b0cf08SMatt Spinler PowerInterface& operator=(PowerInterface&&) = delete; 5669b0cf08SMatt Spinler 5769b0cf08SMatt Spinler /** 58ba3ee9aeSMatt Spinler * @brief Constructor 59ba3ee9aeSMatt Spinler * 60ba3ee9aeSMatt Spinler * @param[in] ThermalAlertObject& - The thermal alert D-Bus object 61ba3ee9aeSMatt Spinler */ PowerInterface(ThermalAlertObject & alertObject)62ba3ee9aeSMatt Spinler explicit PowerInterface(ThermalAlertObject& alertObject) : 63ba3ee9aeSMatt Spinler _alert(alertObject) 64ba3ee9aeSMatt Spinler {} 65ba3ee9aeSMatt Spinler 66ba3ee9aeSMatt Spinler /** 6769b0cf08SMatt Spinler * @brief Perform a soft power off 6869b0cf08SMatt Spinler */ 6969b0cf08SMatt Spinler void softPowerOff() override; 7069b0cf08SMatt Spinler 7169b0cf08SMatt Spinler /** 7269b0cf08SMatt Spinler * @brief Perform a hard power off 7369b0cf08SMatt Spinler */ 7469b0cf08SMatt Spinler void hardPowerOff() override; 75ba3ee9aeSMatt Spinler 76ba3ee9aeSMatt Spinler /** 77ba3ee9aeSMatt Spinler * @brief Sets the thermal alert D-Bus property 78ba3ee9aeSMatt Spinler * 79ba3ee9aeSMatt Spinler * @param[in] alert - The alert value 80ba3ee9aeSMatt Spinler */ thermalAlert(bool alert)81ba3ee9aeSMatt Spinler void thermalAlert(bool alert) override 82ba3ee9aeSMatt Spinler { 83ba3ee9aeSMatt Spinler _alert.enabled(alert); 84ba3ee9aeSMatt Spinler } 85ba3ee9aeSMatt Spinler 86*bb449c1cSMatt Spinler /** 87*bb449c1cSMatt Spinler * @brief Calls the D-Bus method to execute the hard power off. 88*bb449c1cSMatt Spinler * 89*bb449c1cSMatt Spinler * A static function so this can be used by code that doesn't 90*bb449c1cSMatt Spinler * want to create a PowerInterface object. 91*bb449c1cSMatt Spinler */ 92*bb449c1cSMatt Spinler static void executeHardPowerOff(); 93*bb449c1cSMatt Spinler 94ba3ee9aeSMatt Spinler private: 95ba3ee9aeSMatt Spinler /** 96ba3ee9aeSMatt Spinler * @brief Reference to the thermal alert D-Bus object 97ba3ee9aeSMatt Spinler */ 98ba3ee9aeSMatt Spinler ThermalAlertObject& _alert; 9969b0cf08SMatt Spinler }; 10069b0cf08SMatt Spinler 10169b0cf08SMatt Spinler } // namespace phosphor::fan::monitor 102