Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 3 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 4 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 5 | namespace utils |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 6 | { |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 7 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 8 | using namespace phosphor::logging; |
| 9 | |
| 10 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, |
| 11 | const std::string& interface) |
| 12 | { |
| 13 | auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 14 | MAPPER_BUSNAME, "GetObject"); |
| 15 | |
| 16 | method.append(path); |
| 17 | method.append(std::vector<std::string>({interface})); |
| 18 | |
| 19 | std::vector<std::pair<std::string, std::vector<std::string>>> response; |
| 20 | |
| 21 | try |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 22 | { |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 23 | auto reply = bus.call(method); |
| 24 | reply.read(response); |
| 25 | if (response.empty()) |
| 26 | { |
| 27 | log<level::ERR>("Error in mapper response for getting service name", |
| 28 | entry("PATH=%s", path.c_str()), |
| 29 | entry("INTERFACE=%s", interface.c_str())); |
| 30 | return std::string{}; |
| 31 | } |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 32 | } |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 33 | catch (const sdbusplus::exception::SdBusError& e) |
| 34 | { |
| 35 | log<level::ERR>("Error in mapper method call", |
| 36 | entry("ERROR=%s", e.what()), |
| 37 | entry("PATH=%s", path.c_str()), |
| 38 | entry("INTERFACE=%s", interface.c_str())); |
| 39 | return std::string{}; |
| 40 | } |
| 41 | return response[0].first; |
Adriana Kobylak | 5ed9b2d | 2018-09-06 13:15:34 -0500 | [diff] [blame] | 42 | } |
| 43 | |
Jayashankar Padath | a013560 | 2019-04-22 16:22:58 +0530 | [diff] [blame] | 44 | } // namespace utils |