blob: fca99bf89923f64794b0e19c872b2d8ecde1ac70 [file] [log] [blame]
Tom Josephbe703f72017-03-09 12:34:35 +05301#include "utils.hpp"
2
3namespace ipmi
4{
5
6std::string getService(sdbusplus::bus::bus& bus,
7 const std::string& intf,
8 const std::string& path)
9{
10 auto mapperCall = bus.new_method_call("xyz.openbmc_project.ObjectMapper",
Leonel Gonzalezd15e6c92017-03-16 13:47:58 -050011 "/xyz/openbmc_project/object_mapper",
Tom Josephbe703f72017-03-09 12:34:35 +053012 "xyz.openbmc_project.ObjectMapper",
13 "GetObject");
14
15 mapperCall.append(path);
16 mapperCall.append(std::vector<std::string>({intf}));
17
18 auto mapperResponseMsg = bus.call(mapperCall);
19
20 if (mapperResponseMsg.is_method_error())
21 {
22 throw std::runtime_error("ERROR in mapper call");
23 }
24
25 std::map<std::string, std::vector<std::string>> mapperResponse;
26 mapperResponseMsg.read(mapperResponse);
27
28 if (mapperResponse.begin() == mapperResponse.end())
29 {
30 throw std::runtime_error("ERROR in reading the mapper response");
31 }
32
33 return mapperResponse.begin()->first;
34}
35
36} // namespace ipmi
37
38