Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 1 | #include <string> |
| 2 | #include <sdbusplus/bus.hpp> |
| 3 | #include <phosphor-logging/elog-errors.hpp> |
| 4 | #include <xyz/openbmc_project/Common/error.hpp> |
| 5 | namespace open_power |
| 6 | { |
| 7 | namespace occ |
| 8 | { |
| 9 | |
| 10 | // For throwing exceptions |
| 11 | using namespace phosphor::logging; |
| 12 | using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: |
| 13 | Error::InternalFailure; |
| 14 | |
| 15 | std::string getService(sdbusplus::bus::bus& bus, |
Vishwanatha Subbanna | 18dc128 | 2017-08-29 14:09:35 +0530 | [diff] [blame] | 16 | const std::string& path, |
| 17 | const std::string& intf) |
Vishwanatha Subbanna | 30e329a | 2017-07-24 23:13:14 +0530 | [diff] [blame] | 18 | { |
| 19 | auto mapperCall = bus.new_method_call("xyz.openbmc_project.ObjectMapper", |
| 20 | "/xyz/openbmc_project/object_mapper", |
| 21 | "xyz.openbmc_project.ObjectMapper", |
| 22 | "GetObject"); |
| 23 | |
| 24 | mapperCall.append(path); |
| 25 | mapperCall.append(std::vector<std::string>({intf})); |
| 26 | |
| 27 | auto mapperResponseMsg = bus.call(mapperCall); |
| 28 | |
| 29 | if (mapperResponseMsg.is_method_error()) |
| 30 | { |
| 31 | log<level::ERR>("ERROR in getting service", |
| 32 | entry("PATH=%s",path.c_str()), |
| 33 | entry("INTERFACE=%s",intf.c_str())); |
| 34 | |
| 35 | elog<InternalFailure>(); |
| 36 | } |
| 37 | |
| 38 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 39 | mapperResponseMsg.read(mapperResponse); |
| 40 | |
| 41 | if (mapperResponse.begin() == mapperResponse.end()) |
| 42 | { |
| 43 | log<level::ERR>("ERROR reading mapper response", |
| 44 | entry("PATH=%s",path.c_str()), |
| 45 | entry("INTERFACE=%s",intf.c_str())); |
| 46 | |
| 47 | elog<InternalFailure>(); |
| 48 | } |
| 49 | return mapperResponse.begin()->first; |
| 50 | } |
| 51 | |
| 52 | } // namespace occ |
| 53 | } // namespace open_power |