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