blob: e52ff2897b12e7349e62a3672964a6030769ec82 [file] [log] [blame]
Jim Wright19920832021-08-25 11:13:56 -05001#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
11namespace phosphor::power::sequencer
12{
13
14/**
15 * @class PowerControl
16 * This class provides the org.openbmc.control.Power D-Bus interface.
17 */
18class 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 Wright213ffe92022-06-03 08:54:30 -050029 * 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 Wright19920832021-08-25 11:13:56 -050032 */
Patrick Williams7354ce62022-07-22 19:26:56 -050033 PowerInterface(sdbusplus::bus_t& bus, const char* path);
Jim Wright19920832021-08-25 11:13:56 -050034
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 Wright213ffe92022-06-03 08:54:30 -050047 * @param property the property that changed
Jim Wright19920832021-08-25 11:13:56 -050048 */
49 void emitPropertyChangedSignal(const char* property);
50
51 /**
Jim Wright22318a32021-08-27 15:56:09 -050052 * Returns the power good of the chassis
Jim Wright19920832021-08-25 11:13:56 -050053 * @return power good
54 */
Jim Wright22318a32021-08-27 15:56:09 -050055 virtual int getPgood() const = 0;
Jim Wright19920832021-08-25 11:13:56 -050056
57 /**
Jim Wright22318a32021-08-27 15:56:09 -050058 * Returns the power good timeout
Jim Wright19920832021-08-25 11:13:56 -050059 * @return power good timeout
60 */
Jim Wright22318a32021-08-27 15:56:09 -050061 virtual int getPgoodTimeout() const = 0;
Jim Wright19920832021-08-25 11:13:56 -050062
63 /**
Jim Wright22318a32021-08-27 15:56:09 -050064 * Returns the value of the last requested power state
Jim Wright19920832021-08-25 11:13:56 -050065 * @return power state. A power on request is value 1. Power off is 0.
66 */
Jim Wright22318a32021-08-27 15:56:09 -050067 virtual int getState() const = 0;
Jim Wright19920832021-08-25 11:13:56 -050068
69 /**
Jim Wright22318a32021-08-27 15:56:09 -050070 * Sets the power good timeout
Jim Wright213ffe92022-06-03 08:54:30 -050071 * @param timeout power good timeout
Jim Wright19920832021-08-25 11:13:56 -050072 */
73 virtual void setPgoodTimeout(int timeout) = 0;
74
75 /**
Jim Wright22318a32021-08-27 15:56:09 -050076 * Initiates a chassis power state change
Jim Wright213ffe92022-06-03 08:54:30 -050077 * @param state power state. Request power on with a value of 1. Request
Jim Wright19920832021-08-25 11:13:56 -050078 * power off with a value of 0. Other values will be rejected.
79 */
80 virtual void setState(int state) = 0;
81
Jim Wrightccea2d22021-12-10 14:10:46 -060082 /**
Jim Wright213ffe92022-06-03 08:54:30 -050083 * Sets the power supply error.
84 * @param error power supply error. The value should be a message
Jim Wrightccea2d22021-12-10 14:10:46 -060085 * 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 Wright19920832021-08-25 11:13:56 -050090 private:
91 /**
92 * Holder for the instance of this interface to be on dbus
93 */
Jim Wright213ffe92022-06-03 08:54:30 -050094 sdbusplus::server::interface::interface serverInterface;
Jim Wright19920832021-08-25 11:13:56 -050095
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 Wright213ffe92022-06-03 08:54:30 -0500101 static const sdbusplus::vtable::vtable_t vtable[];
Jim Wright19920832021-08-25 11:13:56 -0500102
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 */
Patrick Williamsf5402192024-08-16 15:20:53 -0400114 static int callbackGetPgoodTimeout(
115 sd_bus* bus, const char* path, const char* interface,
116 const char* property, sd_bus_message* msg, void* context,
117 sd_bus_error* error);
Jim Wright19920832021-08-25 11:13:56 -0500118
119 /**
120 * Systemd bus callback for the getPowerState method
121 */
122 static int callbackGetPowerState(sd_bus_message* msg, void* context,
123 sd_bus_error* error);
124
125 /**
126 * Systemd bus callback for getting the state property
127 */
128 static int callbackGetState(sd_bus* bus, const char* path,
129 const char* interface, const char* property,
130 sd_bus_message* msg, void* context,
131 sd_bus_error* error);
132
133 /**
134 * Systemd bus callback for setting the pgood_timeout property
135 */
Patrick Williamsf5402192024-08-16 15:20:53 -0400136 static int callbackSetPgoodTimeout(
137 sd_bus* bus, const char* path, const char* interface,
138 const char* property, sd_bus_message* msg, void* context,
139 sd_bus_error* error);
Jim Wright19920832021-08-25 11:13:56 -0500140
141 /**
Jim Wrightccea2d22021-12-10 14:10:46 -0600142 * Systemd bus callback for the setPowerSupplyError method
143 */
144 static int callbackSetPowerSupplyError(sd_bus_message* msg, void* context,
145 sd_bus_error* error);
146
147 /**
Jim Wright19920832021-08-25 11:13:56 -0500148 * Systemd bus callback for the setPowerState method
149 */
150 static int callbackSetPowerState(sd_bus_message* msg, void* context,
151 sd_bus_error* error);
152};
153
154} // namespace phosphor::power::sequencer