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