1 #include "common/instance_id.hpp" 2 #include "common/utils.hpp" 3 #include "softoff.hpp" 4 5 #include <phosphor-logging/lg2.hpp> 6 7 PHOSPHOR_LOG2_USING; 8 main()9int main() 10 { 11 // 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 17 // Obtain the instance database 18 pldm::InstanceIdDb instanceIdDb; 19 20 // Attach the bus to sd_event to service user requests 21 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 22 23 pldm::SoftPowerOff softPower(bus, event.get(), instanceIdDb); 24 25 if (softPower.isError()) 26 { 27 error( 28 "Failure in gracefully shutdown by remote terminus, exiting pldm-softpoweroff app"); 29 return -1; 30 } 31 32 if (softPower.isCompleted()) 33 { 34 error( 35 "Remote terminus current state is not Running, exiting pldm-softpoweroff app"); 36 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 { 43 error( 44 "Failure in sending soft off request to the remote terminus. Exiting pldm-softpoweroff app"); 45 return -1; 46 } 47 48 if (softPower.isTimerExpired() && softPower.isReceiveResponse()) 49 { 50 pldm::utils::reportError( 51 "pldm soft off: Waiting for the host soft off timeout"); 52 error( 53 "ERROR! Waiting for the host soft off timeout. Exit the pldm-softpoweroff"); 54 return -1; 55 } 56 57 return 0; 58 } 59