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 | |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 7 | #include <nlohmann/json.hpp> |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/server.hpp> |
| 10 | #include <sdbusplus/server/object.hpp> |
| 11 | #include <sdbusplus/timer.hpp> |
| 12 | #include <sdeventplus/event.hpp> |
| 13 | |
| 14 | namespace pldm |
| 15 | { |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 16 | using Json = nlohmann::json; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 17 | |
| 18 | /** @class SoftPowerOff |
| 19 | * @brief Responsible for coordinating Host SoftPowerOff operation |
| 20 | */ |
| 21 | class SoftPowerOff |
| 22 | { |
| 23 | public: |
| 24 | /** @brief Constructs SoftPowerOff object. |
| 25 | * |
| 26 | * @param[in] bus - system D-Bus handler |
| 27 | * @param[in] event - sd_event handler |
Manojkiran Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 28 | * @param[in] instanceDb - pldm instance database |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 29 | */ |
Manojkiran Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 30 | SoftPowerOff(sdbusplus::bus_t& bus, sd_event* event, |
| 31 | InstanceIdDb& instanceIdDb); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 32 | |
| 33 | /** @brief Is the pldm-softpoweroff has error. |
| 34 | * if hasError is true, that means the pldm-softpoweroff failed to |
| 35 | * trigger the host soft off,so the pldm-softpoweroff will exit. |
| 36 | */ |
| 37 | inline bool isError() |
| 38 | { |
| 39 | return hasError; |
| 40 | } |
| 41 | |
| 42 | /** @brief Is the timer expired. |
| 43 | */ |
| 44 | inline bool isTimerExpired() |
| 45 | { |
| 46 | return timer.isExpired(); |
| 47 | } |
| 48 | |
| 49 | /** @brief Is the host soft off completed. |
| 50 | */ |
| 51 | inline bool isCompleted() |
| 52 | { |
| 53 | return completed; |
| 54 | } |
| 55 | |
| 56 | /** @brief Is receive the response for the PLDM request msg. |
| 57 | */ |
| 58 | inline bool isReceiveResponse() |
| 59 | { |
| 60 | return responseReceived; |
| 61 | } |
| 62 | |
| 63 | /** @brief Send PLDM Set State Effecter States command and |
| 64 | * wait the host gracefully shutdown. |
| 65 | * |
| 66 | * @param[in] event - The event loop. |
| 67 | * |
| 68 | * @return PLDM_SUCCESS or PLDM_ERROR. |
| 69 | */ |
| 70 | int hostSoftOff(sdeventplus::Event& event); |
| 71 | |
| 72 | private: |
| 73 | /** @brief Getting the host current state. |
| 74 | */ |
| 75 | int getHostState(); |
| 76 | |
| 77 | /** @brief Stop the timer. |
| 78 | */ |
| 79 | inline auto stopTimer() |
| 80 | { |
| 81 | return timer.stop(); |
| 82 | } |
| 83 | |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 84 | /** @brief method to parse the config Json file for softoff |
| 85 | * |
| 86 | * @return Json - Json object of |
| 87 | */ |
| 88 | Json parseConfig(); |
| 89 | |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 90 | /** @brief When host soft off completed, stop the timer and |
| 91 | * set the completed to true. |
| 92 | * |
| 93 | * @param[in] msg - Data associated with subscribed signal |
| 94 | */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 95 | void hostSoftOffComplete(sdbusplus::message_t& msg); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 96 | |
| 97 | /** @brief Start the timer. |
| 98 | * |
| 99 | * @param[in] usec - Time to wait for the Host to gracefully shutdown. |
| 100 | * |
| 101 | * @return Success or exception thrown |
| 102 | */ |
| 103 | int startTimer(const std::chrono::microseconds& usec); |
| 104 | |
| 105 | /** @brief Get effecterID from PDRs. |
| 106 | * |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 107 | * @param[in] entityType - entity type of the entity hosting |
| 108 | * hosting softoff PDR |
| 109 | * @param[in] stateSetId - state set ID of the softoff PDR |
| 110 | * |
| 111 | * @return true or false |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 112 | */ |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 113 | bool getEffecterID(pldm::pdr::EntityType& entityType, |
| 114 | pldm::pdr::StateSetId& stateSetId); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 115 | |
| 116 | /** @brief Get VMM/SystemFirmware Sensor info from PDRs. |
| 117 | * |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 118 | * @param[in] entityType - entity type of the entity hosting |
| 119 | * hosting softoff PDR |
| 120 | * @param[in] stateSetId - state set ID of the softoff PDR |
| 121 | * |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 122 | * @return PLDM_SUCCESS or PLDM_ERROR |
| 123 | */ |
Sagar Srinivas | 4d99c31 | 2024-03-28 06:50:13 -0500 | [diff] [blame^] | 124 | int getSensorInfo(pldm::pdr::EntityType& entityType, |
| 125 | pldm::pdr::StateSetId& stateSetId); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 126 | |
| 127 | /** @brief effecterID |
| 128 | */ |
| 129 | uint16_t effecterID; |
| 130 | |
| 131 | /** @brief sensorID. |
| 132 | */ |
| 133 | pldm::pdr::SensorID sensorID; |
| 134 | |
| 135 | /** @brief sensorOffset. |
| 136 | */ |
| 137 | pldm::pdr::SensorOffset sensorOffset; |
| 138 | |
| 139 | /** @brief Failed to send host soft off command flag. |
| 140 | */ |
| 141 | bool hasError = false; |
| 142 | |
| 143 | /** @brief Host soft off completed flag. |
| 144 | */ |
| 145 | bool completed = false; |
| 146 | |
| 147 | /** @brief The response for the PLDM request msg is received flag. |
| 148 | */ |
| 149 | bool responseReceived = false; |
| 150 | |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 151 | /* @brief sdbusplus handle */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 152 | sdbusplus::bus_t& bus; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 153 | |
| 154 | /** @brief Reference to Timer object */ |
Patrick Williams | 35535cf | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 155 | sdbusplus::Timer timer; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 156 | |
| 157 | /** @brief Used to subscribe to dbus pldm StateSensorEvent signal |
| 158 | * When the host soft off is complete, it sends an platform event message |
| 159 | * to BMC's pldmd, and the pldmd will emit the StateSensorEvent signal. |
| 160 | **/ |
| 161 | std::unique_ptr<sdbusplus::bus::match_t> pldmEventSignal; |
Manojkiran Eda | 3fcfaa1 | 2024-02-26 15:17:58 +0530 | [diff] [blame] | 162 | |
| 163 | /** @brief Reference to the instance database |
| 164 | */ |
| 165 | InstanceIdDb& instanceIdDb; |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | } // namespace pldm |