blob: e5f61d2205b3fc935f91ac1d5a20916a360be266 [file] [log] [blame]
Chicago Duan184f6022020-04-17 11:30:49 +08001#include "common/utils.hpp"
2#include "softoff.hpp"
George Liu4c1a3fd2020-03-10 08:25:21 +08003
Riya Dixit49cfb132023-03-02 04:26:53 -06004#include <phosphor-logging/lg2.hpp>
5
Riya Dixit49cfb132023-03-02 04:26:53 -06006PHOSPHOR_LOG2_USING;
7
George Liu4c1a3fd2020-03-10 08:25:21 +08008int main()
9{
Chicago Duan184f6022020-04-17 11:30:49 +080010 // 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 Dixit49cfb132023-03-02 04:26:53 -060023 error(
24 "Host failed to gracefully shutdown, exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080025 return -1;
26 }
27
28 if (softPower.isCompleted())
29 {
Riya Dixit49cfb132023-03-02 04:26:53 -060030 error(
31 "Host current state is not Running, exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080032 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 Dixit49cfb132023-03-02 04:26:53 -060039 error(
40 "pldm-softpoweroff:Failure in sending soft off request to the host. Exiting pldm-softpoweroff app");
Chicago Duan184f6022020-04-17 11:30:49 +080041 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 Dixit49cfb132023-03-02 04:26:53 -060048 error(
49 "PLDM host soft off: ERROR! Wait for the host soft off timeout. Exit the pldm-softpoweroff");
Chicago Duan184f6022020-04-17 11:30:49 +080050 return -1;
51 }
52
George Liu4c1a3fd2020-03-10 08:25:21 +080053 return 0;
54}