blob: edbf32569958941d2d773e82b5bef1bfa96c6b8c [file] [log] [blame]
Matt Spinler69b0cf02020-10-14 10:59:03 -05001#pragma once
2
Matt Spinlerba3ee9a2021-01-06 14:45:50 -06003#include "types.hpp"
4
Matt Spinler69b0cf02020-10-14 10:59:03 -05005namespace 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 */
14class 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 Spinlerba3ee9a2021-01-06 14:45:50 -060033
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 Spinler69b0cf02020-10-14 10:59:03 -050040};
41
42/**
43 * @class PowerInterface
44 *
45 * Concrete class to perform power offs
46 */
47class PowerInterface : public PowerInterfaceBase
48{
49 public:
Matt Spinlerba3ee9a2021-01-06 14:45:50 -060050 PowerInterface() = delete;
Matt Spinler69b0cf02020-10-14 10:59:03 -050051 ~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 Spinlerba3ee9a2021-01-06 14:45:50 -060058 * @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 Spinler69b0cf02020-10-14 10:59:03 -050067 * @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 Spinlerba3ee9a2021-01-06 14:45:50 -060075
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 Spinlerbb449c12021-06-14 11:45:28 -060086 /**
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 Spinlerba3ee9a2021-01-06 14:45:50 -060094 private:
95 /**
96 * @brief Reference to the thermal alert D-Bus object
97 */
98 ThermalAlertObject& _alert;
Matt Spinler69b0cf02020-10-14 10:59:03 -050099};
100
101} // namespace phosphor::fan::monitor