main.cpp (184f60263a0e4c3dda934d94ecb2a904ef835299) main.cpp (49cfb138af156020599361584b20c9ed591eeeb6)
1#include "common/utils.hpp"
2#include "softoff.hpp"
3
1#include "common/utils.hpp"
2#include "softoff.hpp"
3
4#include <phosphor-logging/lg2.hpp>
5
4#include <iostream>
5
6#include <iostream>
7
8PHOSPHOR_LOG2_USING;
9
6int main()
7{
8 // Get a default event loop
9 auto event = sdeventplus::Event::get_default();
10
11 // Get a handle to system D-Bus.
12 auto& bus = pldm::utils::DBusHandler::getBus();
13
14 // Attach the bus to sd_event to service user requests
15 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
16
17 pldm::SoftPowerOff softPower(bus, event.get());
18
19 if (softPower.isError())
20 {
10int main()
11{
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 {
21 std::cerr << "Host failed to gracefully shutdown, exiting "
22 "pldm-softpoweroff app\n";
25 error(
26 "Host failed to gracefully shutdown, exiting pldm-softpoweroff app");
23 return -1;
24 }
25
26 if (softPower.isCompleted())
27 {
27 return -1;
28 }
29
30 if (softPower.isCompleted())
31 {
28 std::cerr << "Host current state is not Running, exiting "
29 "pldm-softpoweroff app\n";
32 error(
33 "Host current state is not Running, exiting pldm-softpoweroff app");
30 return 0;
31 }
32
33 // Send the gracefully shutdown request to the host and
34 // wait the host gracefully shutdown.
35 if (softPower.hostSoftOff(event))
36 {
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 {
37 std::cerr << "pldm-softpoweroff:Failure in sending soft off request to "
38 "the host. Exiting pldm-softpoweroff app\n";
39
41 error(
42 "pldm-softpoweroff:Failure in sending soft off request to the host. Exiting pldm-softpoweroff app");
40 return -1;
41 }
42
43 if (softPower.isTimerExpired() && softPower.isReceiveResponse())
44 {
45 pldm::utils::reportError(
46 "pldm soft off: Waiting for the host soft off timeout");
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");
47 std::cerr
48 << "PLDM host soft off: ERROR! Wait for the host soft off timeout."
49 << "Exit the pldm-softpoweroff "
50 << "\n";
50 error(
51 "PLDM host soft off: ERROR! Wait for the host soft off timeout. Exit the pldm-softpoweroff");
51 return -1;
52 }
53
54 return 0;
55}
52 return -1;
53 }
54
55 return 0;
56}