blob: 81b1cc395c3d26c06928bcc0b8c5e5275f8bd20d [file] [log] [blame]
#include "dump_utils.hpp"
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <format>
#include <fstream>
#include <string>
namespace openpower::dump::util
{
using namespace phosphor::logging;
std::string getService(sdbusplus::bus::bus& bus, const std::string& intf,
const std::string& path)
{
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
try
{
auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetObject");
mapper.append(path, std::vector<std::string>({intf}));
auto mapperResponseMsg = bus.call(mapper);
std::map<std::string, std::vector<std::string>> mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
lg2::error(
"Empty mapper response for GetObject interface({INTERFACE}), "
"path({PATH})",
"INTERFACE", intf, "PATH", path);
throw std::runtime_error("Empty mapper response for GetObject");
}
return mapperResponse.begin()->first;
}
catch (const sdbusplus::exception::exception& ex)
{
lg2::error(
"Mapper call failed for GetObject errorMsg({ERROR}), path({PATH}),"
"interface({INTERFACE})",
"ERROR", ex, "PATH", path, "INTERFACE", intf);
throw;
}
}
} // namespace openpower::dump::util