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 /** 52*22318a32SJim Wright * Returns the power good of the chassis 531992083aSJim Wright * @return power good 541992083aSJim Wright */ 55*22318a32SJim Wright virtual int getPgood() const = 0; 561992083aSJim Wright 571992083aSJim Wright /** 58*22318a32SJim Wright * Returns the power good timeout 591992083aSJim Wright * @return power good timeout 601992083aSJim Wright */ 61*22318a32SJim Wright virtual int getPgoodTimeout() const = 0; 621992083aSJim Wright 631992083aSJim Wright /** 64*22318a32SJim 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 */ 67*22318a32SJim Wright virtual int getState() const = 0; 681992083aSJim Wright 691992083aSJim Wright /** 70*22318a32SJim 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 /** 76*22318a32SJim 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 821992083aSJim Wright private: 831992083aSJim Wright /** 841992083aSJim Wright * Holder for the instance of this interface to be on dbus 851992083aSJim Wright */ 861992083aSJim Wright sdbusplus::server::interface::interface _serverInterface; 871992083aSJim Wright 881992083aSJim Wright /** 891992083aSJim Wright * Systemd vtable structure that contains all the 901992083aSJim Wright * methods, signals, and properties of this interface with their 911992083aSJim Wright * respective systemd attributes 921992083aSJim Wright */ 931992083aSJim Wright static const sdbusplus::vtable::vtable_t _vtable[]; 941992083aSJim Wright 951992083aSJim Wright /** 961992083aSJim Wright * Systemd bus callback for getting the pgood property 971992083aSJim Wright */ 981992083aSJim Wright static int callbackGetPgood(sd_bus* bus, const char* path, 991992083aSJim Wright const char* interface, const char* property, 1001992083aSJim Wright sd_bus_message* msg, void* context, 1011992083aSJim Wright sd_bus_error* ret_error); 1021992083aSJim Wright 1031992083aSJim Wright /** 1041992083aSJim Wright * Systemd bus callback for getting the pgood_timeout property 1051992083aSJim Wright */ 1061992083aSJim Wright static int callbackGetPgoodTimeout(sd_bus* bus, const char* path, 1071992083aSJim Wright const char* interface, 1081992083aSJim Wright const char* property, 1091992083aSJim Wright sd_bus_message* msg, void* context, 1101992083aSJim Wright sd_bus_error* error); 1111992083aSJim Wright 1121992083aSJim Wright /** 1131992083aSJim Wright * Systemd bus callback for the getPowerState method 1141992083aSJim Wright */ 1151992083aSJim Wright static int callbackGetPowerState(sd_bus_message* msg, void* context, 1161992083aSJim Wright sd_bus_error* error); 1171992083aSJim Wright 1181992083aSJim Wright /** 1191992083aSJim Wright * Systemd bus callback for getting the state property 1201992083aSJim Wright */ 1211992083aSJim Wright static int callbackGetState(sd_bus* bus, const char* path, 1221992083aSJim Wright const char* interface, const char* property, 1231992083aSJim Wright sd_bus_message* msg, void* context, 1241992083aSJim Wright sd_bus_error* error); 1251992083aSJim Wright 1261992083aSJim Wright /** 1271992083aSJim Wright * Systemd bus callback for setting the pgood_timeout property 1281992083aSJim Wright */ 1291992083aSJim Wright static int callbackSetPgoodTimeout(sd_bus* bus, const char* path, 1301992083aSJim Wright const char* interface, 1311992083aSJim Wright const char* property, 1321992083aSJim Wright sd_bus_message* msg, void* context, 1331992083aSJim Wright sd_bus_error* error); 1341992083aSJim Wright 1351992083aSJim Wright /** 1361992083aSJim Wright * Systemd bus callback for the setPowerState method 1371992083aSJim Wright */ 1381992083aSJim Wright static int callbackSetPowerState(sd_bus_message* msg, void* context, 1391992083aSJim Wright sd_bus_error* error); 1401992083aSJim Wright }; 1411992083aSJim Wright 1421992083aSJim Wright } // namespace phosphor::power::sequencer 143