blob: d3faed33e32ebd67df9d0bf1c8df2a64e422b1e6 [file] [log] [blame]
#include "utils.hpp"
#include <phosphor-logging/log.hpp>
namespace utils
{
using namespace phosphor::logging;
std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
const std::string& interface)
{
auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_BUSNAME, "GetObject");
method.append(path);
method.append(std::vector<std::string>({interface}));
std::vector<std::pair<std::string, std::vector<std::string>>> response;
try
{
auto reply = bus.call(method);
reply.read(response);
if (response.empty())
{
log<level::ERR>("Error in mapper response for getting service name",
entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", interface.c_str()));
return std::string{};
}
}
catch (const sdbusplus::exception::SdBusError& e)
{
log<level::ERR>("Error in mapper method call",
entry("ERROR=%s", e.what()),
entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", interface.c_str()));
return std::string{};
}
return response[0].first;
}
} // namespace utils