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