1d31be2ccSJayanth Othayoth #include "dump_utils.hpp" 2d31be2ccSJayanth Othayoth 3d31be2ccSJayanth Othayoth #include <phosphor-logging/log.hpp> 4d31be2ccSJayanth Othayoth 5d31be2ccSJayanth Othayoth namespace phosphor 6d31be2ccSJayanth Othayoth { 7d31be2ccSJayanth Othayoth namespace dump 8d31be2ccSJayanth Othayoth { 9d31be2ccSJayanth Othayoth 10*2279386bSRamesh Iyyar using namespace phosphor::logging; 11*2279386bSRamesh Iyyar 12d31be2ccSJayanth Othayoth std::string getService(sdbusplus::bus::bus& bus, const std::string& path, 13d31be2ccSJayanth Othayoth const std::string& interface) 14d31be2ccSJayanth Othayoth { 15d31be2ccSJayanth Othayoth constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; 16d31be2ccSJayanth Othayoth constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; 17d31be2ccSJayanth Othayoth 18d31be2ccSJayanth Othayoth auto method = bus.new_method_call(objectMapperName, objectMapperPath, 19d31be2ccSJayanth Othayoth objectMapperName, "GetObject"); 20d31be2ccSJayanth Othayoth 21d31be2ccSJayanth Othayoth method.append(path); 22d31be2ccSJayanth Othayoth method.append(std::vector<std::string>({interface})); 23d31be2ccSJayanth Othayoth 24d31be2ccSJayanth Othayoth std::vector<std::pair<std::string, std::vector<std::string>>> response; 25d31be2ccSJayanth Othayoth 26d31be2ccSJayanth Othayoth try 27d31be2ccSJayanth Othayoth { 28d31be2ccSJayanth Othayoth auto reply = bus.call(method); 29d31be2ccSJayanth Othayoth reply.read(response); 30d31be2ccSJayanth Othayoth if (response.empty()) 31d31be2ccSJayanth Othayoth { 32d31be2ccSJayanth Othayoth log<level::ERR>("Error in mapper response for getting service name", 33d31be2ccSJayanth Othayoth entry("PATH=%s", path.c_str()), 34d31be2ccSJayanth Othayoth entry("INTERFACE=%s", interface.c_str())); 35d31be2ccSJayanth Othayoth return std::string{}; 36d31be2ccSJayanth Othayoth } 37d31be2ccSJayanth Othayoth } 38d31be2ccSJayanth Othayoth catch (const sdbusplus::exception::SdBusError& e) 39d31be2ccSJayanth Othayoth { 40d31be2ccSJayanth Othayoth log<level::ERR>("Error in mapper method call", 41d31be2ccSJayanth Othayoth entry("ERROR=%s", e.what()), 42d31be2ccSJayanth Othayoth entry("PATH=%s", path.c_str()), 43d31be2ccSJayanth Othayoth entry("INTERFACE=%s", interface.c_str())); 44d31be2ccSJayanth Othayoth return std::string{}; 45d31be2ccSJayanth Othayoth } 46d31be2ccSJayanth Othayoth return response[0].first; 47d31be2ccSJayanth Othayoth } 48d31be2ccSJayanth Othayoth 49*2279386bSRamesh Iyyar BootProgress getBootProgress() 50*2279386bSRamesh Iyyar { 51*2279386bSRamesh Iyyar constexpr auto bootProgressInterface = 52*2279386bSRamesh Iyyar "xyz.openbmc_project.State.Boot.Progress"; 53*2279386bSRamesh Iyyar // TODO Need to change host instance if multiple instead "0" 54*2279386bSRamesh Iyyar constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; 55*2279386bSRamesh Iyyar 56*2279386bSRamesh Iyyar BootProgress bootProgessStage; 57*2279386bSRamesh Iyyar 58*2279386bSRamesh Iyyar try 59*2279386bSRamesh Iyyar { 60*2279386bSRamesh Iyyar auto bus = sdbusplus::bus::new_default(); 61*2279386bSRamesh Iyyar auto service = getService(bus, hostStateObjPath, bootProgressInterface); 62*2279386bSRamesh Iyyar 63*2279386bSRamesh Iyyar auto method = 64*2279386bSRamesh Iyyar bus.new_method_call(service.c_str(), hostStateObjPath, 65*2279386bSRamesh Iyyar "org.freedesktop.DBus.Properties", "Get"); 66*2279386bSRamesh Iyyar 67*2279386bSRamesh Iyyar method.append(bootProgressInterface, "BootProgress"); 68*2279386bSRamesh Iyyar 69*2279386bSRamesh Iyyar auto reply = bus.call(method); 70*2279386bSRamesh Iyyar 71*2279386bSRamesh Iyyar using DBusValue_t = 72*2279386bSRamesh Iyyar std::variant<std::string, bool, std::vector<uint8_t>, 73*2279386bSRamesh Iyyar std::vector<std::string>>; 74*2279386bSRamesh Iyyar DBusValue_t propertyVal; 75*2279386bSRamesh Iyyar 76*2279386bSRamesh Iyyar reply.read(propertyVal); 77*2279386bSRamesh Iyyar 78*2279386bSRamesh Iyyar // BootProgress property type is string 79*2279386bSRamesh Iyyar std::string bootPgs(std::get<std::string>(propertyVal)); 80*2279386bSRamesh Iyyar 81*2279386bSRamesh Iyyar bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot:: 82*2279386bSRamesh Iyyar server::Progress::convertProgressStagesFromString(bootPgs); 83*2279386bSRamesh Iyyar } 84*2279386bSRamesh Iyyar catch (const sdbusplus::exception::SdBusError& e) 85*2279386bSRamesh Iyyar { 86*2279386bSRamesh Iyyar log<level::ERR>("D-Bus call exception", 87*2279386bSRamesh Iyyar entry("OBJPATH=%s", hostStateObjPath), 88*2279386bSRamesh Iyyar entry("INTERFACE=%s", bootProgressInterface), 89*2279386bSRamesh Iyyar entry("EXCEPTION=%s", e.what())); 90*2279386bSRamesh Iyyar throw std::runtime_error("Failed to get BootProgress stage"); 91*2279386bSRamesh Iyyar } 92*2279386bSRamesh Iyyar catch (const std::bad_variant_access& e) 93*2279386bSRamesh Iyyar { 94*2279386bSRamesh Iyyar log<level::ERR>( 95*2279386bSRamesh Iyyar "Exception raised while read BootProgress property value", 96*2279386bSRamesh Iyyar entry("OBJPATH=%s", hostStateObjPath), 97*2279386bSRamesh Iyyar entry("INTERFACE=%s", bootProgressInterface), 98*2279386bSRamesh Iyyar entry("EXCEPTION=%s", e.what())); 99*2279386bSRamesh Iyyar throw std::runtime_error("Failed to get BootProgress stage"); 100*2279386bSRamesh Iyyar } 101*2279386bSRamesh Iyyar 102*2279386bSRamesh Iyyar return bootProgessStage; 103*2279386bSRamesh Iyyar } 104d31be2ccSJayanth Othayoth } // namespace dump 105d31be2ccSJayanth Othayoth } // namespace phosphor 106