Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <systemd/sd-bus.h> |
| 4 | |
| 5 | #include <sdbusplus/sdbus.hpp> |
| 6 | #include <sdbusplus/server/interface.hpp> |
| 7 | #include <sdbusplus/vtable.hpp> |
| 8 | |
| 9 | #include <string> |
| 10 | |
| 11 | namespace phosphor::power::sequencer |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @class PowerControl |
| 16 | * This class provides the org.openbmc.control.Power D-Bus interface. |
| 17 | */ |
| 18 | class PowerInterface |
| 19 | { |
| 20 | public: |
| 21 | PowerInterface() = delete; |
| 22 | PowerInterface(const PowerInterface&) = delete; |
| 23 | PowerInterface& operator=(const PowerInterface&) = delete; |
| 24 | PowerInterface(PowerInterface&&) = delete; |
| 25 | PowerInterface& operator=(PowerInterface&&) = delete; |
| 26 | virtual ~PowerInterface() = default; |
| 27 | |
| 28 | /** |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 29 | * Constructor to put object onto bus at a dbus path. |
| 30 | * @param bus D-Bus bus object |
| 31 | * @param path D-Bus object path |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 32 | */ |
| 33 | PowerInterface(sdbusplus::bus::bus& bus, const char* path); |
| 34 | |
| 35 | /** |
| 36 | * Emit the power good signal |
| 37 | */ |
| 38 | void emitPowerGoodSignal(); |
| 39 | |
| 40 | /** |
| 41 | * Emit the power lost signal |
| 42 | */ |
| 43 | void emitPowerLostSignal(); |
| 44 | |
| 45 | /** |
| 46 | * Emit the property changed signal |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 47 | * @param property the property that changed |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 48 | */ |
| 49 | void emitPropertyChangedSignal(const char* property); |
| 50 | |
| 51 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 52 | * Returns the power good of the chassis |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 53 | * @return power good |
| 54 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 55 | virtual int getPgood() const = 0; |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 56 | |
| 57 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 58 | * Returns the power good timeout |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 59 | * @return power good timeout |
| 60 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 61 | virtual int getPgoodTimeout() const = 0; |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 62 | |
| 63 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 64 | * Returns the value of the last requested power state |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 65 | * @return power state. A power on request is value 1. Power off is 0. |
| 66 | */ |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 67 | virtual int getState() const = 0; |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 68 | |
| 69 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 70 | * Sets the power good timeout |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 71 | * @param timeout power good timeout |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 72 | */ |
| 73 | virtual void setPgoodTimeout(int timeout) = 0; |
| 74 | |
| 75 | /** |
Jim Wright | 22318a3 | 2021-08-27 15:56:09 -0500 | [diff] [blame] | 76 | * Initiates a chassis power state change |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 77 | * @param state power state. Request power on with a value of 1. Request |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 78 | * power off with a value of 0. Other values will be rejected. |
| 79 | */ |
| 80 | virtual void setState(int state) = 0; |
| 81 | |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 82 | /** |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 83 | * Sets the power supply error. |
| 84 | * @param error power supply error. The value should be a message |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 85 | * argument for a phosphor-logging Create call, e.g. |
| 86 | * "xyz.openbmc_project.Power.PowerSupply.Error.PSKillFault" |
| 87 | */ |
| 88 | virtual void setPowerSupplyError(const std::string& error) = 0; |
| 89 | |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 90 | private: |
| 91 | /** |
| 92 | * Holder for the instance of this interface to be on dbus |
| 93 | */ |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 94 | sdbusplus::server::interface::interface serverInterface; |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Systemd vtable structure that contains all the |
| 98 | * methods, signals, and properties of this interface with their |
| 99 | * respective systemd attributes |
| 100 | */ |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 101 | static const sdbusplus::vtable::vtable_t vtable[]; |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Systemd bus callback for getting the pgood property |
| 105 | */ |
| 106 | static int callbackGetPgood(sd_bus* bus, const char* path, |
| 107 | const char* interface, const char* property, |
| 108 | sd_bus_message* msg, void* context, |
| 109 | sd_bus_error* ret_error); |
| 110 | |
| 111 | /** |
| 112 | * Systemd bus callback for getting the pgood_timeout property |
| 113 | */ |
| 114 | static int callbackGetPgoodTimeout(sd_bus* bus, const char* path, |
| 115 | const char* interface, |
| 116 | const char* property, |
| 117 | sd_bus_message* msg, void* context, |
| 118 | sd_bus_error* error); |
| 119 | |
| 120 | /** |
| 121 | * Systemd bus callback for the getPowerState method |
| 122 | */ |
| 123 | static int callbackGetPowerState(sd_bus_message* msg, void* context, |
| 124 | sd_bus_error* error); |
| 125 | |
| 126 | /** |
| 127 | * Systemd bus callback for getting the state property |
| 128 | */ |
| 129 | static int callbackGetState(sd_bus* bus, const char* path, |
| 130 | const char* interface, const char* property, |
| 131 | sd_bus_message* msg, void* context, |
| 132 | sd_bus_error* error); |
| 133 | |
| 134 | /** |
| 135 | * Systemd bus callback for setting the pgood_timeout property |
| 136 | */ |
| 137 | static int callbackSetPgoodTimeout(sd_bus* bus, const char* path, |
| 138 | const char* interface, |
| 139 | const char* property, |
| 140 | sd_bus_message* msg, void* context, |
| 141 | sd_bus_error* error); |
| 142 | |
| 143 | /** |
Jim Wright | ccea2d2 | 2021-12-10 14:10:46 -0600 | [diff] [blame] | 144 | * Systemd bus callback for the setPowerSupplyError method |
| 145 | */ |
| 146 | static int callbackSetPowerSupplyError(sd_bus_message* msg, void* context, |
| 147 | sd_bus_error* error); |
| 148 | |
| 149 | /** |
Jim Wright | 1992083 | 2021-08-25 11:13:56 -0500 | [diff] [blame] | 150 | * Systemd bus callback for the setPowerState method |
| 151 | */ |
| 152 | static int callbackSetPowerState(sd_bus_message* msg, void* context, |
| 153 | sd_bus_error* error); |
| 154 | }; |
| 155 | |
| 156 | } // namespace phosphor::power::sequencer |