Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
| 3 | namespace ipmi |
| 4 | { |
| 5 | |
| 6 | std::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", |
| 11 | "/xyz/openbmc_project/ObjectMapper", |
| 12 | "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 | |