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