blob: d3faed33e32ebd67df9d0bf1c8df2a64e422b1e6 [file] [log] [blame]
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -05001#include "utils.hpp"
2
Jayashankar Padatha0135602019-04-22 16:22:58 +05303#include <phosphor-logging/log.hpp>
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -05004
Jayashankar Padatha0135602019-04-22 16:22:58 +05305namespace utils
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -05006{
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -05007
Jayashankar Padatha0135602019-04-22 16:22:58 +05308using namespace phosphor::logging;
9
10std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
11 const std::string& interface)
12{
13 auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
14 MAPPER_BUSNAME, "GetObject");
15
16 method.append(path);
17 method.append(std::vector<std::string>({interface}));
18
19 std::vector<std::pair<std::string, std::vector<std::string>>> response;
20
21 try
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -050022 {
Jayashankar Padatha0135602019-04-22 16:22:58 +053023 auto reply = bus.call(method);
24 reply.read(response);
25 if (response.empty())
26 {
27 log<level::ERR>("Error in mapper response for getting service name",
28 entry("PATH=%s", path.c_str()),
29 entry("INTERFACE=%s", interface.c_str()));
30 return std::string{};
31 }
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -050032 }
Jayashankar Padatha0135602019-04-22 16:22:58 +053033 catch (const sdbusplus::exception::SdBusError& e)
34 {
35 log<level::ERR>("Error in mapper method call",
36 entry("ERROR=%s", e.what()),
37 entry("PATH=%s", path.c_str()),
38 entry("INTERFACE=%s", interface.c_str()));
39 return std::string{};
40 }
41 return response[0].first;
Adriana Kobylak5ed9b2d2018-09-06 13:15:34 -050042}
43
Jayashankar Padatha0135602019-04-22 16:22:58 +053044} // namespace utils