blob: ae81814f107f5e4b16a7b5963d21f0fcc3e3d805 [file] [log] [blame]
Manojkiran Eda3fcfaa12024-02-26 15:17:58 +05301#include "common/instance_id.hpp"
Chicago Duan184f6022020-04-17 11:30:49 +08002#include "common/utils.hpp"
3#include "softoff.hpp"
George Liu4c1a3fd2020-03-10 08:25:21 +08004
Riya Dixit49cfb132023-03-02 04:26:53 -06005#include <phosphor-logging/lg2.hpp>
6
Riya Dixit49cfb132023-03-02 04:26:53 -06007PHOSPHOR_LOG2_USING;
8
George Liu4c1a3fd2020-03-10 08:25:21 +08009int main()
10{
Chicago Duan184f6022020-04-17 11:30:49 +080011 // 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 Eda3fcfaa12024-02-26 15:17:58 +053017 // Obtain the instance database
18 pldm::InstanceIdDb instanceIdDb;
19
Chicago Duan184f6022020-04-17 11:30:49 +080020 // Attach the bus to sd_event to service user requests
21 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
22
Manojkiran Eda3fcfaa12024-02-26 15:17:58 +053023 pldm::SoftPowerOff softPower(bus, event.get(), instanceIdDb);
Chicago Duan184f6022020-04-17 11:30:49 +080024
25 if (softPower.isError())
26 {
Riya Dixit49cfb132023-03-02 04:26:53 -060027 error(
Riya Dixit087a7512024-04-06 14:28:08 -050028 "Failure in gracefully shutdown by remote terminus, exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080029 return -1;
30 }
31
32 if (softPower.isCompleted())
33 {
Riya Dixit49cfb132023-03-02 04:26:53 -060034 error(
Riya Dixit087a7512024-04-06 14:28:08 -050035 "Remote terminus current state is not Running, exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080036 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 Dixit49cfb132023-03-02 04:26:53 -060043 error(
Riya Dixit087a7512024-04-06 14:28:08 -050044 "Failure in sending soft off request to the remote terminus. Exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080045 return -1;
46 }
47
48 if (softPower.isTimerExpired() && softPower.isReceiveResponse())
49 {
50 pldm::utils::reportError(
Manojkiran Eda92fb0b52024-04-17 10:48:17 +053051 "pldm soft off: Waiting for the host soft off timeout");
Riya Dixit49cfb132023-03-02 04:26:53 -060052 error(
Riya Dixit087a7512024-04-06 14:28:08 -050053 "ERROR! Waiting for the host soft off timeout. Exit the pldm-softpoweroff");
Chicago Duan184f6022020-04-17 11:30:49 +080054 return -1;
55 }
56
George Liu4c1a3fd2020-03-10 08:25:21 +080057 return 0;
58}