blob: 792138c6e327ca68b73bf72cf6b77adb5eb92af8 [file] [log] [blame]
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06001#include "dump_utils.hpp"
2
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05003#include <phosphor-logging/lg2.hpp>
Jayanth Othayothd31be2c2020-02-04 02:56:45 -06004
5namespace phosphor
6{
7namespace dump
8{
9
Patrick Williams9b18bf22022-07-22 19:26:55 -050010std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060011 const std::string& interface)
12{
13 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
14 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060015
16 auto method = bus.new_method_call(objectMapperName, objectMapperPath,
17 objectMapperName, "GetObject");
18
19 method.append(path);
20 method.append(std::vector<std::string>({interface}));
21
22 std::vector<std::pair<std::string, std::vector<std::string>>> response;
23
24 try
25 {
26 auto reply = bus.call(method);
27 reply.read(response);
28 if (response.empty())
29 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050030 lg2::error(
31 "Error in mapper response for getting service name, PATH: "
32 "{PATH}, INTERFACE: {INTERFACE}",
33 "PATH", path, "INTERFACE", interface);
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060034 return std::string{};
35 }
36 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050037 catch (const sdbusplus::exception_t& e)
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060038 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050039 lg2::error("Error in mapper method call, errormsg: {ERROR}, "
40 "PATH: {PATH}, INTERFACE: {INTERFACE}",
41 "ERROR", e, "PATH", path, "INTERFACE", interface);
Dhruvaraj Subhashchandran3a25e5b2022-03-22 08:06:20 -050042 throw;
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060043 }
44 return response[0].first;
45}
46
Jayanth Othayothd31be2c2020-02-04 02:56:45 -060047} // namespace dump
48} // namespace phosphor