Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 1 | #include "dump_utils.hpp" |
| 2 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 3 | #include "dump_types.hpp" |
| 4 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 6 | |
| 7 | namespace phosphor |
| 8 | { |
| 9 | namespace dump |
| 10 | { |
| 11 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 12 | std::string getService(sdbusplus::bus_t& bus, const std::string& path, |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 13 | const std::string& interface) |
| 14 | { |
| 15 | constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; |
| 16 | constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 17 | |
| 18 | auto method = bus.new_method_call(objectMapperName, objectMapperPath, |
| 19 | objectMapperName, "GetObject"); |
| 20 | |
| 21 | method.append(path); |
| 22 | method.append(std::vector<std::string>({interface})); |
| 23 | |
| 24 | std::vector<std::pair<std::string, std::vector<std::string>>> response; |
| 25 | |
| 26 | try |
| 27 | { |
| 28 | auto reply = bus.call(method); |
| 29 | reply.read(response); |
| 30 | if (response.empty()) |
| 31 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 32 | lg2::error( |
| 33 | "Error in mapper response for getting service name, PATH: " |
| 34 | "{PATH}, INTERFACE: {INTERFACE}", |
| 35 | "PATH", path, "INTERFACE", interface); |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 36 | return std::string{}; |
| 37 | } |
| 38 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 39 | catch (const sdbusplus::exception_t& e) |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 40 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 41 | lg2::error("Error in mapper method call, errormsg: {ERROR}, " |
| 42 | "PATH: {PATH}, INTERFACE: {INTERFACE}", |
| 43 | "ERROR", e, "PATH", path, "INTERFACE", interface); |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 44 | throw; |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 45 | } |
| 46 | return response[0].first; |
| 47 | } |
| 48 | |
Jayanth Othayoth | d31be2c | 2020-02-04 02:56:45 -0600 | [diff] [blame] | 49 | } // namespace dump |
| 50 | } // namespace phosphor |