blob: 182381953a2545a5243e335a6391bba5c8c6b877 [file] [log] [blame]
#include "utils.hpp"
namespace ipmi
{
std::string getService(sdbusplus::bus::bus& bus,
const std::string& intf,
const std::string& path)
{
auto mapperCall = bus.new_method_call("xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/ObjectMapper",
"xyz.openbmc_project.ObjectMapper",
"GetObject");
mapperCall.append(path);
mapperCall.append(std::vector<std::string>({intf}));
auto mapperResponseMsg = bus.call(mapperCall);
if (mapperResponseMsg.is_method_error())
{
throw std::runtime_error("ERROR in mapper call");
}
std::map<std::string, std::vector<std::string>> mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.begin() == mapperResponse.end())
{
throw std::runtime_error("ERROR in reading the mapper response");
}
return mapperResponse.begin()->first;
}
} // namespace ipmi