1 #include "common/utils.hpp" 2 #include "softoff.hpp" 3 4 #include <phosphor-logging/lg2.hpp> 5 6 PHOSPHOR_LOG2_USING; 7 8 int main() 9 { 10 // 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 { 23 error( 24 "Host failed to gracefully shutdown, exiting pldm-softpoweroff app"); 25 return -1; 26 } 27 28 if (softPower.isCompleted()) 29 { 30 error( 31 "Host current state is not Running, exiting pldm-softpoweroff app"); 32 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 { 39 error( 40 "pldm-softpoweroff:Failure in sending soft off request to the host. Exiting pldm-softpoweroff app"); 41 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"); 48 error( 49 "PLDM host soft off: ERROR! Wait for the host soft off timeout. Exit the pldm-softpoweroff"); 50 return -1; 51 } 52 53 return 0; 54 } 55