blob: da703ece0a555b08422d4d28b6c83dd3bb85e607 [file] [log] [blame]
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06001#include "dump_utils.hpp"
2
Dhruvaraj Subhashchandran36047102023-06-29 03:46:25 -05003#include "dump_types.hpp"
4
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05005#include <phosphor-logging/lg2.hpp>
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06006
7namespace phosphor
8{
9namespace dump
10{
11
Patrick Williams9b18bf22022-07-22 19:26:55 -050012std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060013 const std::string& interface)
14{
15 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
16 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060017
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 Subhashchandrand1f670f2023-06-05 22:19:25 -050032 lg2::error(
33 "Error in mapper response for getting service name, PATH: "
34 "{PATH}, INTERFACE: {INTERFACE}",
35 "PATH", path, "INTERFACE", interface);
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060036 return std::string{};
37 }
38 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050039 catch (const sdbusplus::exception_t& e)
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060040 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050041 lg2::error("Error in mapper method call, errormsg: {ERROR}, "
42 "PATH: {PATH}, INTERFACE: {INTERFACE}",
43 "ERROR", e, "PATH", path, "INTERFACE", interface);
Dhruvaraj Subhashchandran3a25e5b2022-03-22 08:06:20 -050044 throw;
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060045 }
46 return response[0].first;
47}
48
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060049} // namespace dump
50} // namespace phosphor