blob: 254b21a0f0da073fc24648ba4d1749bb9b679c21 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#include "utils.hpp"
2
3#include "xyz/openbmc_project/Common/error.hpp"
4
5#include <array>
6#include <ctime>
7#include <iostream>
8#include <map>
Deepak Kodihallic2feac92019-04-30 17:21:19 +05309#include <phosphor-logging/log.hpp>
Sampa Misra032bd502019-03-06 05:03:22 -060010#include <stdexcept>
11#include <string>
12#include <vector>
13
14namespace pldm
15{
16using namespace phosphor::logging;
17
18constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
19constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
20constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
21
22namespace responder
23{
24
25std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
26 const std::string& interface)
27{
28 using DbusInterfaceList = std::vector<std::string>;
29 std::map<std::string, std::vector<std::string>> mapperResponse;
30
31 try
32 {
33 auto mapper = bus.new_method_call(mapperBusName, mapperPath,
34 mapperInterface, "GetObject");
35 mapper.append(path, DbusInterfaceList({interface}));
36
37 auto mapperResponseMsg = bus.call(mapper);
38 mapperResponseMsg.read(mapperResponse);
39 }
40 catch (std::exception& e)
41 {
42 log<level::ERR>("Error in mapper call", entry("ERROR=%s", e.what()),
43 entry("PATH=%s", path.c_str()),
44 entry("INTERFACE=%s", interface.c_str()));
45 throw;
46 }
47 return mapperResponse.begin()->first;
48}
49
50} // namespace responder
51} // namespace pldm