11992083aSJim Wright #pragma once
21992083aSJim Wright 
31992083aSJim Wright #include <systemd/sd-bus.h>
41992083aSJim Wright 
51992083aSJim Wright #include <sdbusplus/sdbus.hpp>
61992083aSJim Wright #include <sdbusplus/server/interface.hpp>
71992083aSJim Wright #include <sdbusplus/vtable.hpp>
81992083aSJim Wright 
91992083aSJim Wright #include <string>
101992083aSJim Wright 
111992083aSJim Wright namespace phosphor::power::sequencer
121992083aSJim Wright {
131992083aSJim Wright 
141992083aSJim Wright /**
151992083aSJim Wright  * @class PowerControl
161992083aSJim Wright  * This class provides the org.openbmc.control.Power D-Bus interface.
171992083aSJim Wright  */
181992083aSJim Wright class PowerInterface
191992083aSJim Wright {
201992083aSJim Wright   public:
211992083aSJim Wright     PowerInterface() = delete;
221992083aSJim Wright     PowerInterface(const PowerInterface&) = delete;
231992083aSJim Wright     PowerInterface& operator=(const PowerInterface&) = delete;
241992083aSJim Wright     PowerInterface(PowerInterface&&) = delete;
251992083aSJim Wright     PowerInterface& operator=(PowerInterface&&) = delete;
261992083aSJim Wright     virtual ~PowerInterface() = default;
271992083aSJim Wright 
281992083aSJim Wright     /**
291992083aSJim Wright      * @brief Constructor to put object onto bus at a dbus path.
301992083aSJim Wright      * @param[in] bus D-Bus bus object
311992083aSJim Wright      * @param[in] path D-Bus object path
321992083aSJim Wright      */
331992083aSJim Wright     PowerInterface(sdbusplus::bus::bus& bus, const char* path);
341992083aSJim Wright 
351992083aSJim Wright     /**
361992083aSJim Wright      * Emit the power good signal
371992083aSJim Wright      */
381992083aSJim Wright     void emitPowerGoodSignal();
391992083aSJim Wright 
401992083aSJim Wright     /**
411992083aSJim Wright      * Emit the power lost signal
421992083aSJim Wright      */
431992083aSJim Wright     void emitPowerLostSignal();
441992083aSJim Wright 
451992083aSJim Wright     /**
461992083aSJim Wright      * Emit the property changed signal
471992083aSJim Wright      * @param[in] property the property that changed
481992083aSJim Wright      */
491992083aSJim Wright     void emitPropertyChangedSignal(const char* property);
501992083aSJim Wright 
511992083aSJim Wright     /**
5222318a32SJim Wright      * Returns the power good of the chassis
531992083aSJim Wright      * @return power good
541992083aSJim Wright      */
5522318a32SJim Wright     virtual int getPgood() const = 0;
561992083aSJim Wright 
571992083aSJim Wright     /**
5822318a32SJim Wright      * Returns the power good timeout
591992083aSJim Wright      * @return power good timeout
601992083aSJim Wright      */
6122318a32SJim Wright     virtual int getPgoodTimeout() const = 0;
621992083aSJim Wright 
631992083aSJim Wright     /**
6422318a32SJim Wright      * Returns the value of the last requested power state
651992083aSJim Wright      * @return power state. A power on request is value 1. Power off is 0.
661992083aSJim Wright      */
6722318a32SJim Wright     virtual int getState() const = 0;
681992083aSJim Wright 
691992083aSJim Wright     /**
7022318a32SJim Wright      * Sets the power good timeout
711992083aSJim Wright      * @param[in] timeout power good timeout
721992083aSJim Wright      */
731992083aSJim Wright     virtual void setPgoodTimeout(int timeout) = 0;
741992083aSJim Wright 
751992083aSJim Wright     /**
7622318a32SJim Wright      * Initiates a chassis power state change
771992083aSJim Wright      * @param[in] state power state. Request power on with a value of 1. Request
781992083aSJim Wright      * power off with a value of 0. Other values will be rejected.
791992083aSJim Wright      */
801992083aSJim Wright     virtual void setState(int state) = 0;
811992083aSJim Wright 
82*ccea2d2bSJim Wright     /**
83*ccea2d2bSJim Wright      * Sets the power supply error. The error should be of great enough severity
84*ccea2d2bSJim Wright      * that a power good failure may occur and will be issued in preference to
85*ccea2d2bSJim Wright      * the power good error.
86*ccea2d2bSJim Wright      * @param[in] error power supply error. The value should be a message
87*ccea2d2bSJim Wright      * argument for a phosphor-logging Create call, e.g.
88*ccea2d2bSJim Wright      * "xyz.openbmc_project.Power.PowerSupply.Error.PSKillFault"
89*ccea2d2bSJim Wright      */
90*ccea2d2bSJim Wright     virtual void setPowerSupplyError(const std::string& error) = 0;
91*ccea2d2bSJim Wright 
921992083aSJim Wright   private:
931992083aSJim Wright     /**
941992083aSJim Wright      * Holder for the instance of this interface to be on dbus
951992083aSJim Wright      */
961992083aSJim Wright     sdbusplus::server::interface::interface _serverInterface;
971992083aSJim Wright 
981992083aSJim Wright     /**
991992083aSJim Wright      * Systemd vtable structure that contains all the
1001992083aSJim Wright      * methods, signals, and properties of this interface with their
1011992083aSJim Wright      * respective systemd attributes
1021992083aSJim Wright      */
1031992083aSJim Wright     static const sdbusplus::vtable::vtable_t _vtable[];
1041992083aSJim Wright 
1051992083aSJim Wright     /**
1061992083aSJim Wright      * Systemd bus callback for getting the pgood property
1071992083aSJim Wright      */
1081992083aSJim Wright     static int callbackGetPgood(sd_bus* bus, const char* path,
1091992083aSJim Wright                                 const char* interface, const char* property,
1101992083aSJim Wright                                 sd_bus_message* msg, void* context,
1111992083aSJim Wright                                 sd_bus_error* ret_error);
1121992083aSJim Wright 
1131992083aSJim Wright     /**
1141992083aSJim Wright      * Systemd bus callback for getting the pgood_timeout property
1151992083aSJim Wright      */
1161992083aSJim Wright     static int callbackGetPgoodTimeout(sd_bus* bus, const char* path,
1171992083aSJim Wright                                        const char* interface,
1181992083aSJim Wright                                        const char* property,
1191992083aSJim Wright                                        sd_bus_message* msg, void* context,
1201992083aSJim Wright                                        sd_bus_error* error);
1211992083aSJim Wright 
1221992083aSJim Wright     /**
1231992083aSJim Wright      * Systemd bus callback for the getPowerState method
1241992083aSJim Wright      */
1251992083aSJim Wright     static int callbackGetPowerState(sd_bus_message* msg, void* context,
1261992083aSJim Wright                                      sd_bus_error* error);
1271992083aSJim Wright 
1281992083aSJim Wright     /**
1291992083aSJim Wright      * Systemd bus callback for getting the state property
1301992083aSJim Wright      */
1311992083aSJim Wright     static int callbackGetState(sd_bus* bus, const char* path,
1321992083aSJim Wright                                 const char* interface, const char* property,
1331992083aSJim Wright                                 sd_bus_message* msg, void* context,
1341992083aSJim Wright                                 sd_bus_error* error);
1351992083aSJim Wright 
1361992083aSJim Wright     /**
1371992083aSJim Wright      * Systemd bus callback for setting the pgood_timeout property
1381992083aSJim Wright      */
1391992083aSJim Wright     static int callbackSetPgoodTimeout(sd_bus* bus, const char* path,
1401992083aSJim Wright                                        const char* interface,
1411992083aSJim Wright                                        const char* property,
1421992083aSJim Wright                                        sd_bus_message* msg, void* context,
1431992083aSJim Wright                                        sd_bus_error* error);
1441992083aSJim Wright 
1451992083aSJim Wright     /**
146*ccea2d2bSJim Wright      * Systemd bus callback for the setPowerSupplyError method
147*ccea2d2bSJim Wright      */
148*ccea2d2bSJim Wright     static int callbackSetPowerSupplyError(sd_bus_message* msg, void* context,
149*ccea2d2bSJim Wright                                            sd_bus_error* error);
150*ccea2d2bSJim Wright 
151*ccea2d2bSJim Wright     /**
1521992083aSJim Wright      * Systemd bus callback for the setPowerState method
1531992083aSJim Wright      */
1541992083aSJim Wright     static int callbackSetPowerState(sd_bus_message* msg, void* context,
1551992083aSJim Wright                                      sd_bus_error* error);
1561992083aSJim Wright };
1571992083aSJim Wright 
1581992083aSJim Wright } // namespace phosphor::power::sequencer
159