Dhruvaraj Subhashchandran | 858d1aa | 2021-10-27 03:26:06 -0500 | [diff] [blame^] | 1 | #include "dump_utils.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/elog-errors.hpp> |
| 4 | #include <phosphor-logging/elog.hpp> |
| 5 | #include <phosphor-logging/lg2.hpp> |
| 6 | #include <phosphor-logging/log.hpp> |
| 7 | #include <xyz/openbmc_project/Common/File/error.hpp> |
| 8 | |
| 9 | #include <format> |
| 10 | #include <fstream> |
| 11 | #include <string> |
| 12 | |
| 13 | namespace openpower::dump::util |
| 14 | { |
| 15 | using namespace phosphor::logging; |
| 16 | |
| 17 | std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, |
| 18 | const std::string& path) |
| 19 | { |
| 20 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 21 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 22 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 23 | try |
| 24 | { |
| 25 | auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 26 | MAPPER_INTERFACE, "GetObject"); |
| 27 | |
| 28 | mapper.append(path, std::vector<std::string>({intf})); |
| 29 | |
| 30 | auto mapperResponseMsg = bus.call(mapper); |
| 31 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 32 | mapperResponseMsg.read(mapperResponse); |
| 33 | |
| 34 | if (mapperResponse.empty()) |
| 35 | { |
| 36 | lg2::error( |
| 37 | "Empty mapper response for GetObject interface({INTERFACE}), " |
| 38 | "path({PATH})", |
| 39 | "INTERFACE", intf, "PATH", path); |
| 40 | |
| 41 | throw std::runtime_error("Empty mapper response for GetObject"); |
| 42 | } |
| 43 | return mapperResponse.begin()->first; |
| 44 | } |
| 45 | catch (const sdbusplus::exception::exception& ex) |
| 46 | { |
| 47 | lg2::error( |
| 48 | "Mapper call failed for GetObject errorMsg({ERROR}), path({PATH})," |
| 49 | "interface({INTERFACE})", |
| 50 | "ERROR", ex, "PATH", path, "INTERFACE", intf); |
| 51 | |
| 52 | throw; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | } // namespace openpower::dump::util |