Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Manojkiran Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 3 | #include "common/instance_id.hpp" |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 4 | #include "common/transport.hpp" |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 5 | #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 | |
| 13 | namespace pldm |
| 14 | { |
| 15 | |
| 16 | /** @class SoftPowerOff |
| 17 | * @brief Responsible for coordinating Host SoftPowerOff operation |
| 18 | */ |
| 19 | class 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 Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 26 | * @param[in] instanceDb - pldm instance database |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 27 | */ |
Manojkiran Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 28 | SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event, |
| 29 | InstanceIdDb& instanceIdDb); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 30 | |
| 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 87 | void hostSoftOffComplete(sdbusplus::message_t& msg); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 88 | |
| 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 138 | sdbusplus::bus_t& bus; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 139 | |
| 140 | /** @brief Reference to Timer object */ |
Patrick Williams | 35535cf | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 141 | sdbusplus::Timer timer; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 142 | |
| 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 Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 148 | |
| 149 | /** @brief Reference to the instance database |
| 150 | */ |
| 151 | InstanceIdDb& instanceIdDb; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | } // namespace pldm |