blob: 2bf39686732a2bea9180dbb0c41aadc6651037ef [file] [log] [blame]
Chicago Duan184f6022020-04-17 11:30:49 +08001#pragma once
2
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10003#include "common/transport.hpp"
Chicago Duan184f6022020-04-17 11:30:49 +08004#include "common/types.hpp"
5
6#include <sdbusplus/bus.hpp>
7#include <sdbusplus/server.hpp>
8#include <sdbusplus/server/object.hpp>
9#include <sdbusplus/timer.hpp>
10#include <sdeventplus/event.hpp>
11
12namespace pldm
13{
14
15/** @class SoftPowerOff
16 * @brief Responsible for coordinating Host SoftPowerOff operation
17 */
18class SoftPowerOff
19{
20 public:
21 /** @brief Constructs SoftPowerOff object.
22 *
23 * @param[in] bus - system D-Bus handler
24 * @param[in] event - sd_event handler
25 */
Patrick Williams84b790c2022-07-22 19:26:56 -050026 SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event);
Chicago Duan184f6022020-04-17 11:30:49 +080027
28 /** @brief Is the pldm-softpoweroff has error.
29 * if hasError is true, that means the pldm-softpoweroff failed to
30 * trigger the host soft off,so the pldm-softpoweroff will exit.
31 */
32 inline bool isError()
33 {
34 return hasError;
35 }
36
37 /** @brief Is the timer expired.
38 */
39 inline bool isTimerExpired()
40 {
41 return timer.isExpired();
42 }
43
44 /** @brief Is the host soft off completed.
45 */
46 inline bool isCompleted()
47 {
48 return completed;
49 }
50
51 /** @brief Is receive the response for the PLDM request msg.
52 */
53 inline bool isReceiveResponse()
54 {
55 return responseReceived;
56 }
57
58 /** @brief Send PLDM Set State Effecter States command and
59 * wait the host gracefully shutdown.
60 *
61 * @param[in] event - The event loop.
62 *
63 * @return PLDM_SUCCESS or PLDM_ERROR.
64 */
65 int hostSoftOff(sdeventplus::Event& event);
66
67 private:
68 /** @brief Getting the host current state.
69 */
70 int getHostState();
71
72 /** @brief Stop the timer.
73 */
74 inline auto stopTimer()
75 {
76 return timer.stop();
77 }
78
79 /** @brief When host soft off completed, stop the timer and
80 * set the completed to true.
81 *
82 * @param[in] msg - Data associated with subscribed signal
83 */
Patrick Williams84b790c2022-07-22 19:26:56 -050084 void hostSoftOffComplete(sdbusplus::message_t& msg);
Chicago Duan184f6022020-04-17 11:30:49 +080085
86 /** @brief Start the timer.
87 *
88 * @param[in] usec - Time to wait for the Host to gracefully shutdown.
89 *
90 * @return Success or exception thrown
91 */
92 int startTimer(const std::chrono::microseconds& usec);
93
94 /** @brief Get effecterID from PDRs.
95 *
96 * @return PLDM_SUCCESS or PLDM_ERROR
97 */
98 int getEffecterID();
99
100 /** @brief Get VMM/SystemFirmware Sensor info from PDRs.
101 *
102 * @return PLDM_SUCCESS or PLDM_ERROR
103 */
104 int getSensorInfo();
105
106 /** @brief effecterID
107 */
108 uint16_t effecterID;
109
110 /** @brief sensorID.
111 */
112 pldm::pdr::SensorID sensorID;
113
114 /** @brief sensorOffset.
115 */
116 pldm::pdr::SensorOffset sensorOffset;
117
118 /** @brief Failed to send host soft off command flag.
119 */
120 bool hasError = false;
121
122 /** @brief Host soft off completed flag.
123 */
124 bool completed = false;
125
126 /** @brief The response for the PLDM request msg is received flag.
127 */
128 bool responseReceived = false;
129
130 /** @brief Is the Virtual Machine Manager/VMM state effecter available.
131 */
132 bool VMMPdrExist = true;
133
134 /* @brief sdbusplus handle */
Patrick Williams84b790c2022-07-22 19:26:56 -0500135 sdbusplus::bus_t& bus;
Chicago Duan184f6022020-04-17 11:30:49 +0800136
137 /** @brief Reference to Timer object */
Patrick Williams35535cf2023-12-05 12:45:02 -0600138 sdbusplus::Timer timer;
Chicago Duan184f6022020-04-17 11:30:49 +0800139
140 /** @brief Used to subscribe to dbus pldm StateSensorEvent signal
141 * When the host soft off is complete, it sends an platform event message
142 * to BMC's pldmd, and the pldmd will emit the StateSensorEvent signal.
143 **/
144 std::unique_ptr<sdbusplus::bus::match_t> pldmEventSignal;
145};
146
147} // namespace pldm