blob: 64bf47ef887d671471e660e4030102e0e03423da [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(
28 "Host failed to gracefully shutdown, 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(
35 "Host 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(
44 "pldm-softpoweroff:Failure in sending soft off request to the host. 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(
Pavithra Barithayad28f08c2021-12-15 03:37:14 -060051 "xyz.openbmc_project.PLDM.Error.SoftPowerOff.HostSoftOffTimeOut");
Riya Dixit49cfb132023-03-02 04:26:53 -060052 error(
53 "PLDM host soft off: ERROR! Wait 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}