blob: e0a802d7bd4b610636cdbf90ed58babd18456604 [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
86 private:
87 /**
88 * @brief Reference to the thermal alert D-Bus object
89 */
90 ThermalAlertObject& _alert;
Matt Spinler69b0cf02020-10-14 10:59:03 -050091};
92
93} // namespace phosphor::fan::monitor