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