Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 3 | #include "common/transport.hpp" |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 4 | #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 | |
| 12 | namespace pldm |
| 13 | { |
| 14 | |
| 15 | /** @class SoftPowerOff |
| 16 | * @brief Responsible for coordinating Host SoftPowerOff operation |
| 17 | */ |
| 18 | class 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 26 | SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 27 | |
| 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 84 | void hostSoftOffComplete(sdbusplus::message_t& msg); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 85 | |
| 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 135 | sdbusplus::bus_t& bus; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 136 | |
| 137 | /** @brief Reference to Timer object */ |
| 138 | phosphor::Timer timer; |
| 139 | |
| 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 |