13fcfaa12SManojkiran Eda #include "common/instance_id.hpp" 2184f6026SChicago Duan #include "common/utils.hpp" 3184f6026SChicago Duan #include "softoff.hpp" 44c1a3fdaSGeorge Liu 549cfb138SRiya Dixit #include <phosphor-logging/lg2.hpp> 649cfb138SRiya Dixit 749cfb138SRiya Dixit PHOSPHOR_LOG2_USING; 849cfb138SRiya Dixit main()94c1a3fdaSGeorge Liuint main() 104c1a3fdaSGeorge Liu { 11184f6026SChicago Duan // Get a default event loop 12184f6026SChicago Duan auto event = sdeventplus::Event::get_default(); 13184f6026SChicago Duan 14184f6026SChicago Duan // Get a handle to system D-Bus. 15184f6026SChicago Duan auto& bus = pldm::utils::DBusHandler::getBus(); 16184f6026SChicago Duan 173fcfaa12SManojkiran Eda // Obtain the instance database 183fcfaa12SManojkiran Eda pldm::InstanceIdDb instanceIdDb; 193fcfaa12SManojkiran Eda 20184f6026SChicago Duan // Attach the bus to sd_event to service user requests 21184f6026SChicago Duan bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 22184f6026SChicago Duan 233fcfaa12SManojkiran Eda pldm::SoftPowerOff softPower(bus, event.get(), instanceIdDb); 24184f6026SChicago Duan 25184f6026SChicago Duan if (softPower.isError()) 26184f6026SChicago Duan { 2749cfb138SRiya Dixit error( 28087a751fSRiya Dixit "Failure in gracefully shutdown by remote terminus, exiting pldm-softpoweroff app"); 29184f6026SChicago Duan return -1; 30184f6026SChicago Duan } 31184f6026SChicago Duan 32184f6026SChicago Duan if (softPower.isCompleted()) 33184f6026SChicago Duan { 3449cfb138SRiya Dixit error( 35087a751fSRiya Dixit "Remote terminus current state is not Running, exiting pldm-softpoweroff app"); 36184f6026SChicago Duan return 0; 37184f6026SChicago Duan } 38184f6026SChicago Duan 39184f6026SChicago Duan // Send the gracefully shutdown request to the host and 40184f6026SChicago Duan // wait the host gracefully shutdown. 41184f6026SChicago Duan if (softPower.hostSoftOff(event)) 42184f6026SChicago Duan { 4349cfb138SRiya Dixit error( 44087a751fSRiya Dixit "Failure in sending soft off request to the remote terminus. Exiting pldm-softpoweroff app"); 45184f6026SChicago Duan return -1; 46184f6026SChicago Duan } 47184f6026SChicago Duan 48184f6026SChicago Duan if (softPower.isTimerExpired() && softPower.isReceiveResponse()) 49184f6026SChicago Duan { 50184f6026SChicago Duan pldm::utils::reportError( 51*99991367SSagar Srinivas "xyz.openbmc_project.PLDM.Error.SoftPowerOff.HostSoftOffTimeOut"); 5249cfb138SRiya Dixit error( 53087a751fSRiya Dixit "ERROR! Waiting for the host soft off timeout. Exit the pldm-softpoweroff"); 54184f6026SChicago Duan return -1; 55184f6026SChicago Duan } 56184f6026SChicago Duan 574c1a3fdaSGeorge Liu return 0; 584c1a3fdaSGeorge Liu } 59