1d31be2ccSJayanth Othayoth #include "dump_utils.hpp" 2d31be2ccSJayanth Othayoth 3858fbb2eSGeorge Liu #include <fmt/core.h> 4858fbb2eSGeorge Liu 5d31be2ccSJayanth Othayoth #include <phosphor-logging/log.hpp> 6d31be2ccSJayanth Othayoth 7d31be2ccSJayanth Othayoth namespace phosphor 8d31be2ccSJayanth Othayoth { 9d31be2ccSJayanth Othayoth namespace dump 10d31be2ccSJayanth Othayoth { 11d31be2ccSJayanth Othayoth 122279386bSRamesh Iyyar using namespace phosphor::logging; 132279386bSRamesh Iyyar 14*9b18bf2dSPatrick Williams std::string getService(sdbusplus::bus_t& bus, const std::string& path, 15d31be2ccSJayanth Othayoth const std::string& interface) 16d31be2ccSJayanth Othayoth { 17d31be2ccSJayanth Othayoth constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; 18d31be2ccSJayanth Othayoth constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; 19d31be2ccSJayanth Othayoth 20d31be2ccSJayanth Othayoth auto method = bus.new_method_call(objectMapperName, objectMapperPath, 21d31be2ccSJayanth Othayoth objectMapperName, "GetObject"); 22d31be2ccSJayanth Othayoth 23d31be2ccSJayanth Othayoth method.append(path); 24d31be2ccSJayanth Othayoth method.append(std::vector<std::string>({interface})); 25d31be2ccSJayanth Othayoth 26d31be2ccSJayanth Othayoth std::vector<std::pair<std::string, std::vector<std::string>>> response; 27d31be2ccSJayanth Othayoth 28d31be2ccSJayanth Othayoth try 29d31be2ccSJayanth Othayoth { 30d31be2ccSJayanth Othayoth auto reply = bus.call(method); 31d31be2ccSJayanth Othayoth reply.read(response); 32d31be2ccSJayanth Othayoth if (response.empty()) 33d31be2ccSJayanth Othayoth { 34858fbb2eSGeorge Liu log<level::ERR>(fmt::format("Error in mapper response for getting " 35858fbb2eSGeorge Liu "service name, PATH({}), INTERFACE({})", 36858fbb2eSGeorge Liu path, interface) 37858fbb2eSGeorge Liu .c_str()); 38d31be2ccSJayanth Othayoth return std::string{}; 39d31be2ccSJayanth Othayoth } 40d31be2ccSJayanth Othayoth } 41*9b18bf2dSPatrick Williams catch (const sdbusplus::exception_t& e) 42d31be2ccSJayanth Othayoth { 43858fbb2eSGeorge Liu log<level::ERR>(fmt::format("Error in mapper method call, " 44858fbb2eSGeorge Liu "errormsg({}), PATH({}), INTERFACE({})", 45858fbb2eSGeorge Liu e.what(), path, interface) 46858fbb2eSGeorge Liu .c_str()); 47d31be2ccSJayanth Othayoth return std::string{}; 48d31be2ccSJayanth Othayoth } 49d31be2ccSJayanth Othayoth return response[0].first; 50d31be2ccSJayanth Othayoth } 51d31be2ccSJayanth Othayoth 522279386bSRamesh Iyyar BootProgress getBootProgress() 532279386bSRamesh Iyyar { 542279386bSRamesh Iyyar constexpr auto bootProgressInterface = 552279386bSRamesh Iyyar "xyz.openbmc_project.State.Boot.Progress"; 562279386bSRamesh Iyyar // TODO Need to change host instance if multiple instead "0" 572279386bSRamesh Iyyar constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; 582279386bSRamesh Iyyar 592279386bSRamesh Iyyar BootProgress bootProgessStage; 602279386bSRamesh Iyyar 612279386bSRamesh Iyyar try 622279386bSRamesh Iyyar { 632279386bSRamesh Iyyar auto bus = sdbusplus::bus::new_default(); 642279386bSRamesh Iyyar auto service = getService(bus, hostStateObjPath, bootProgressInterface); 652279386bSRamesh Iyyar 662279386bSRamesh Iyyar auto method = 672279386bSRamesh Iyyar bus.new_method_call(service.c_str(), hostStateObjPath, 682279386bSRamesh Iyyar "org.freedesktop.DBus.Properties", "Get"); 692279386bSRamesh Iyyar 702279386bSRamesh Iyyar method.append(bootProgressInterface, "BootProgress"); 712279386bSRamesh Iyyar 722279386bSRamesh Iyyar auto reply = bus.call(method); 732279386bSRamesh Iyyar 742279386bSRamesh Iyyar using DBusValue_t = 752279386bSRamesh Iyyar std::variant<std::string, bool, std::vector<uint8_t>, 762279386bSRamesh Iyyar std::vector<std::string>>; 772279386bSRamesh Iyyar DBusValue_t propertyVal; 782279386bSRamesh Iyyar 792279386bSRamesh Iyyar reply.read(propertyVal); 802279386bSRamesh Iyyar 812279386bSRamesh Iyyar // BootProgress property type is string 822279386bSRamesh Iyyar std::string bootPgs(std::get<std::string>(propertyVal)); 832279386bSRamesh Iyyar 842279386bSRamesh Iyyar bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot:: 852279386bSRamesh Iyyar server::Progress::convertProgressStagesFromString(bootPgs); 862279386bSRamesh Iyyar } 87*9b18bf2dSPatrick Williams catch (const sdbusplus::exception_t& e) 882279386bSRamesh Iyyar { 89858fbb2eSGeorge Liu log<level::ERR>(fmt::format("D-Bus call exception, OBJPATH({}), " 90858fbb2eSGeorge Liu "INTERFACE({}), EXCEPTION({})", 91858fbb2eSGeorge Liu hostStateObjPath, bootProgressInterface, 92858fbb2eSGeorge Liu e.what()) 93858fbb2eSGeorge Liu .c_str()); 942279386bSRamesh Iyyar throw std::runtime_error("Failed to get BootProgress stage"); 952279386bSRamesh Iyyar } 962279386bSRamesh Iyyar catch (const std::bad_variant_access& e) 972279386bSRamesh Iyyar { 982279386bSRamesh Iyyar log<level::ERR>( 99858fbb2eSGeorge Liu fmt::format("Exception raised while read BootProgress property " 100858fbb2eSGeorge Liu "value, OBJPATH({}), INTERFACE({}), EXCEPTION({})", 101858fbb2eSGeorge Liu hostStateObjPath, bootProgressInterface, e.what()) 102858fbb2eSGeorge Liu .c_str()); 1032279386bSRamesh Iyyar throw std::runtime_error("Failed to get BootProgress stage"); 1042279386bSRamesh Iyyar } 1052279386bSRamesh Iyyar 1062279386bSRamesh Iyyar return bootProgessStage; 1072279386bSRamesh Iyyar } 1086a54d9afSDhruvaraj Subhashchandran 1096a54d9afSDhruvaraj Subhashchandran bool isHostRunning() 1106a54d9afSDhruvaraj Subhashchandran { 1116a54d9afSDhruvaraj Subhashchandran // TODO #ibm-openbmc/dev/2858 Revisit the method for finding whether host 1126a54d9afSDhruvaraj Subhashchandran // is running. 1136a54d9afSDhruvaraj Subhashchandran BootProgress bootProgressStatus = phosphor::dump::getBootProgress(); 1146a54d9afSDhruvaraj Subhashchandran if ((bootProgressStatus == BootProgress::SystemInitComplete) || 1156a54d9afSDhruvaraj Subhashchandran (bootProgressStatus == BootProgress::OSStart) || 1166a54d9afSDhruvaraj Subhashchandran (bootProgressStatus == BootProgress::OSRunning)) 1176a54d9afSDhruvaraj Subhashchandran { 1186a54d9afSDhruvaraj Subhashchandran return true; 1196a54d9afSDhruvaraj Subhashchandran } 1206a54d9afSDhruvaraj Subhashchandran return false; 1216a54d9afSDhruvaraj Subhashchandran } 122d31be2ccSJayanth Othayoth } // namespace dump 123d31be2ccSJayanth Othayoth } // namespace phosphor 124