blob: c68913d4bf2a607f61db5c6de859f1af19fdd47f [file] [log] [blame]
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05301#include <phosphor-logging/elog-errors.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -05002#include <sdbusplus/bus.hpp>
3#include <string>
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +05304#include <xyz/openbmc_project/Common/error.hpp>
5namespace open_power
6{
7namespace occ
8{
9
10// For throwing exceptions
11using namespace phosphor::logging;
Gunnar Mills94df8c92018-09-14 14:50:03 -050012using InternalFailure =
13 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053014
Gunnar Mills94df8c92018-09-14 14:50:03 -050015std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
Vishwanatha Subbanna18dc1282017-08-29 14:09:35 +053016 const std::string& intf)
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053017{
Gunnar Mills94df8c92018-09-14 14:50:03 -050018 auto mapperCall =
19 bus.new_method_call("xyz.openbmc_project.ObjectMapper",
20 "/xyz/openbmc_project/object_mapper",
21 "xyz.openbmc_project.ObjectMapper", "GetObject");
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053022
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",
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 entry("PATH=%s", path.c_str()),
32 entry("INTERFACE=%s", intf.c_str()));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053033
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",
Gunnar Mills94df8c92018-09-14 14:50:03 -050043 entry("PATH=%s", path.c_str()),
44 entry("INTERFACE=%s", intf.c_str()));
Vishwanatha Subbanna30e329a2017-07-24 23:13:14 +053045
46 elog<InternalFailure>();
47 }
48 return mapperResponse.begin()->first;
49}
50
51} // namespace occ
52} // namespace open_power