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