blob: fca99bf89923f64794b0e19c872b2d8ecde1ac70 [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/object_mapper",
"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