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 /** 29*213ffe99SJim Wright * Constructor to put object onto bus at a dbus path. 30*213ffe99SJim Wright * @param bus D-Bus bus object 31*213ffe99SJim Wright * @param 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 47*213ffe99SJim Wright * @param 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 71*213ffe99SJim Wright * @param 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 77*213ffe99SJim Wright * @param 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 82ccea2d2bSJim Wright /** 83*213ffe99SJim Wright * Sets the power supply error. 84*213ffe99SJim Wright * @param error power supply error. The value should be a message 85ccea2d2bSJim Wright * argument for a phosphor-logging Create call, e.g. 86ccea2d2bSJim Wright * "xyz.openbmc_project.Power.PowerSupply.Error.PSKillFault" 87ccea2d2bSJim Wright */ 88ccea2d2bSJim Wright virtual void setPowerSupplyError(const std::string& error) = 0; 89ccea2d2bSJim Wright 901992083aSJim Wright private: 911992083aSJim Wright /** 921992083aSJim Wright * Holder for the instance of this interface to be on dbus 931992083aSJim Wright */ 94*213ffe99SJim Wright sdbusplus::server::interface::interface serverInterface; 951992083aSJim Wright 961992083aSJim Wright /** 971992083aSJim Wright * Systemd vtable structure that contains all the 981992083aSJim Wright * methods, signals, and properties of this interface with their 991992083aSJim Wright * respective systemd attributes 1001992083aSJim Wright */ 101*213ffe99SJim Wright static const sdbusplus::vtable::vtable_t vtable[]; 1021992083aSJim Wright 1031992083aSJim Wright /** 1041992083aSJim Wright * Systemd bus callback for getting the pgood property 1051992083aSJim Wright */ 1061992083aSJim Wright static int callbackGetPgood(sd_bus* bus, const char* path, 1071992083aSJim Wright const char* interface, const char* property, 1081992083aSJim Wright sd_bus_message* msg, void* context, 1091992083aSJim Wright sd_bus_error* ret_error); 1101992083aSJim Wright 1111992083aSJim Wright /** 1121992083aSJim Wright * Systemd bus callback for getting the pgood_timeout property 1131992083aSJim Wright */ 1141992083aSJim Wright static int callbackGetPgoodTimeout(sd_bus* bus, const char* path, 1151992083aSJim Wright const char* interface, 1161992083aSJim Wright const char* property, 1171992083aSJim Wright sd_bus_message* msg, void* context, 1181992083aSJim Wright sd_bus_error* error); 1191992083aSJim Wright 1201992083aSJim Wright /** 1211992083aSJim Wright * Systemd bus callback for the getPowerState method 1221992083aSJim Wright */ 1231992083aSJim Wright static int callbackGetPowerState(sd_bus_message* msg, void* context, 1241992083aSJim Wright sd_bus_error* error); 1251992083aSJim Wright 1261992083aSJim Wright /** 1271992083aSJim Wright * Systemd bus callback for getting the state property 1281992083aSJim Wright */ 1291992083aSJim Wright static int callbackGetState(sd_bus* bus, const char* path, 1301992083aSJim Wright const char* interface, const char* property, 1311992083aSJim Wright sd_bus_message* msg, void* context, 1321992083aSJim Wright sd_bus_error* error); 1331992083aSJim Wright 1341992083aSJim Wright /** 1351992083aSJim Wright * Systemd bus callback for setting the pgood_timeout property 1361992083aSJim Wright */ 1371992083aSJim Wright static int callbackSetPgoodTimeout(sd_bus* bus, const char* path, 1381992083aSJim Wright const char* interface, 1391992083aSJim Wright const char* property, 1401992083aSJim Wright sd_bus_message* msg, void* context, 1411992083aSJim Wright sd_bus_error* error); 1421992083aSJim Wright 1431992083aSJim Wright /** 144ccea2d2bSJim Wright * Systemd bus callback for the setPowerSupplyError method 145ccea2d2bSJim Wright */ 146ccea2d2bSJim Wright static int callbackSetPowerSupplyError(sd_bus_message* msg, void* context, 147ccea2d2bSJim Wright sd_bus_error* error); 148ccea2d2bSJim Wright 149ccea2d2bSJim Wright /** 1501992083aSJim Wright * Systemd bus callback for the setPowerState method 1511992083aSJim Wright */ 1521992083aSJim Wright static int callbackSetPowerState(sd_bus_message* msg, void* context, 1531992083aSJim Wright sd_bus_error* error); 1541992083aSJim Wright }; 1551992083aSJim Wright 1561992083aSJim Wright } // namespace phosphor::power::sequencer 157