1 #include <phosphor-logging/elog-errors.hpp>
2 #include <sdbusplus/bus.hpp>
3 #include <string>
4 #include <xyz/openbmc_project/Common/error.hpp>
5 namespace open_power
6 {
7 namespace occ
8 {
9 
10 // For throwing exceptions
11 using namespace phosphor::logging;
12 using InternalFailure =
13     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
14 
15 std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
16                        const std::string& intf)
17 {
18     auto mapperCall =
19         bus.new_method_call("xyz.openbmc_project.ObjectMapper",
20                             "/xyz/openbmc_project/object_mapper",
21                             "xyz.openbmc_project.ObjectMapper", "GetObject");
22 
23     mapperCall.append(path);
24     mapperCall.append(std::vector<std::string>({intf}));
25 
26     auto mapperResponseMsg = bus.call(mapperCall);
27 
28     if (mapperResponseMsg.is_method_error())
29     {
30         log<level::ERR>("ERROR in getting service",
31                         entry("PATH=%s", path.c_str()),
32                         entry("INTERFACE=%s", intf.c_str()));
33 
34         elog<InternalFailure>();
35     }
36 
37     std::map<std::string, std::vector<std::string>> mapperResponse;
38     mapperResponseMsg.read(mapperResponse);
39 
40     if (mapperResponse.begin() == mapperResponse.end())
41     {
42         log<level::ERR>("ERROR reading mapper response",
43                         entry("PATH=%s", path.c_str()),
44                         entry("INTERFACE=%s", intf.c_str()));
45 
46         elog<InternalFailure>();
47     }
48     return mapperResponse.begin()->first;
49 }
50 
51 } // namespace occ
52 } // namespace open_power
53