blob: b0137068d7cd4f9b9f55ff2b7de51d4e89bebc4c [file] [log] [blame]
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06001#include "dump_utils.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace phosphor
6{
7namespace dump
8{
9
10std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
11 const std::string& interface)
12{
13 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
14 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
15 using namespace phosphor::logging;
16
17 auto method = bus.new_method_call(objectMapperName, objectMapperPath,
18 objectMapperName, "GetObject");
19
20 method.append(path);
21 method.append(std::vector<std::string>({interface}));
22
23 std::vector<std::pair<std::string, std::vector<std::string>>> response;
24
25 try
26 {
27 auto reply = bus.call(method);
28 reply.read(response);
29 if (response.empty())
30 {
31 log<level::ERR>("Error in mapper response for getting service name",
32 entry("PATH=%s", path.c_str()),
33 entry("INTERFACE=%s", interface.c_str()));
34 return std::string{};
35 }
36 }
37 catch (const sdbusplus::exception::SdBusError& e)
38 {
39 log<level::ERR>("Error in mapper method call",
40 entry("ERROR=%s", e.what()),
41 entry("PATH=%s", path.c_str()),
42 entry("INTERFACE=%s", interface.c_str()));
43 return std::string{};
44 }
45 return response[0].first;
46}
47
48} // namespace dump
49} // namespace phosphor