Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 1 | #include "common/utils.hpp" |
| 2 | #include "softoff.hpp" |
George Liu | 4c1a3fd | 2020-03-10 08:25:21 +0800 | [diff] [blame] | 3 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 4 | #include <phosphor-logging/lg2.hpp> |
| 5 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 6 | PHOSPHOR_LOG2_USING; |
| 7 | |
George Liu | 4c1a3fd | 2020-03-10 08:25:21 +0800 | [diff] [blame] | 8 | int main() |
| 9 | { |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 10 | // Get a default event loop |
| 11 | auto event = sdeventplus::Event::get_default(); |
| 12 | |
| 13 | // Get a handle to system D-Bus. |
| 14 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 15 | |
| 16 | // Attach the bus to sd_event to service user requests |
| 17 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 18 | |
| 19 | pldm::SoftPowerOff softPower(bus, event.get()); |
| 20 | |
| 21 | if (softPower.isError()) |
| 22 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 23 | error( |
| 24 | "Host failed to gracefully shutdown, exiting pldm-softpoweroff app"); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 25 | return -1; |
| 26 | } |
| 27 | |
| 28 | if (softPower.isCompleted()) |
| 29 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 30 | error( |
| 31 | "Host current state is not Running, exiting pldm-softpoweroff app"); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | // Send the gracefully shutdown request to the host and |
| 36 | // wait the host gracefully shutdown. |
| 37 | if (softPower.hostSoftOff(event)) |
| 38 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 39 | error( |
| 40 | "pldm-softpoweroff:Failure in sending soft off request to the host. Exiting pldm-softpoweroff app"); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 41 | return -1; |
| 42 | } |
| 43 | |
| 44 | if (softPower.isTimerExpired() && softPower.isReceiveResponse()) |
| 45 | { |
| 46 | pldm::utils::reportError( |
| 47 | "pldm soft off: Waiting for the host soft off timeout"); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 48 | error( |
| 49 | "PLDM host soft off: ERROR! Wait for the host soft off timeout. Exit the pldm-softpoweroff"); |
Chicago Duan | 184f602 | 2020-04-17 11:30:49 +0800 | [diff] [blame] | 50 | return -1; |
| 51 | } |
| 52 | |
George Liu | 4c1a3fd | 2020-03-10 08:25:21 +0800 | [diff] [blame] | 53 | return 0; |
| 54 | } |