1 #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 
11 namespace phosphor::power::sequencer
12 {
13 
14 /**
15  * @class PowerControl
16  * This class provides the org.openbmc.control.Power D-Bus interface.
17  */
18 class 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     /**
29      * @brief Constructor to put object onto bus at a dbus path.
30      * @param[in] bus D-Bus bus object
31      * @param[in] path D-Bus object path
32      */
33     PowerInterface(sdbusplus::bus::bus& bus, const char* path);
34 
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
47      * @param[in] property the property that changed
48      */
49     void emitPropertyChangedSignal(const char* property);
50 
51     /**
52      * Returns the power good of the chassis
53      * @return power good
54      */
55     virtual int getPgood() const = 0;
56 
57     /**
58      * Returns the power good timeout
59      * @return power good timeout
60      */
61     virtual int getPgoodTimeout() const = 0;
62 
63     /**
64      * Returns the value of the last requested power state
65      * @return power state. A power on request is value 1. Power off is 0.
66      */
67     virtual int getState() const = 0;
68 
69     /**
70      * Sets the power good timeout
71      * @param[in] timeout power good timeout
72      */
73     virtual void setPgoodTimeout(int timeout) = 0;
74 
75     /**
76      * Initiates a chassis power state change
77      * @param[in] state power state. Request power on with a value of 1. Request
78      * power off with a value of 0. Other values will be rejected.
79      */
80     virtual void setState(int state) = 0;
81 
82   private:
83     /**
84      * Holder for the instance of this interface to be on dbus
85      */
86     sdbusplus::server::interface::interface _serverInterface;
87 
88     /**
89      * Systemd vtable structure that contains all the
90      * methods, signals, and properties of this interface with their
91      * respective systemd attributes
92      */
93     static const sdbusplus::vtable::vtable_t _vtable[];
94 
95     /**
96      * Systemd bus callback for getting the pgood property
97      */
98     static int callbackGetPgood(sd_bus* bus, const char* path,
99                                 const char* interface, const char* property,
100                                 sd_bus_message* msg, void* context,
101                                 sd_bus_error* ret_error);
102 
103     /**
104      * Systemd bus callback for getting the pgood_timeout property
105      */
106     static int callbackGetPgoodTimeout(sd_bus* bus, const char* path,
107                                        const char* interface,
108                                        const char* property,
109                                        sd_bus_message* msg, void* context,
110                                        sd_bus_error* error);
111 
112     /**
113      * Systemd bus callback for the getPowerState method
114      */
115     static int callbackGetPowerState(sd_bus_message* msg, void* context,
116                                      sd_bus_error* error);
117 
118     /**
119      * Systemd bus callback for getting the state property
120      */
121     static int callbackGetState(sd_bus* bus, const char* path,
122                                 const char* interface, const char* property,
123                                 sd_bus_message* msg, void* context,
124                                 sd_bus_error* error);
125 
126     /**
127      * Systemd bus callback for setting the pgood_timeout property
128      */
129     static int callbackSetPgoodTimeout(sd_bus* bus, const char* path,
130                                        const char* interface,
131                                        const char* property,
132                                        sd_bus_message* msg, void* context,
133                                        sd_bus_error* error);
134 
135     /**
136      * Systemd bus callback for the setPowerState method
137      */
138     static int callbackSetPowerState(sd_bus_message* msg, void* context,
139                                      sd_bus_error* error);
140 };
141 
142 } // namespace phosphor::power::sequencer
143