diff options
Diffstat (limited to 'utils.cpp')
-rw-r--r-- | utils.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -10,6 +10,10 @@ namespace time namespace // anonymous { +constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; +constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; +constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; + /** @brief The map that maps the string to Mode */ const std::map<std::string, Mode> modeMap = { @@ -32,6 +36,41 @@ namespace utils using namespace phosphor::logging; +std::string getService(sdbusplus::bus::bus& bus, + const char* path, + const char* interface) +{ + auto mapper = bus.new_method_call(MAPPER_BUSNAME, + MAPPER_PATH, + MAPPER_INTERFACE, + "GetObject"); + + mapper.append(path, std::vector<std::string>({interface})); + auto mapperResponseMsg = bus.call(mapper); + + if (mapperResponseMsg.is_method_error()) + { + // TODO: define repo specific errors and use elog report() + log<level::ERR>("Error in mapper call", + entry("PATH=%s", path), + entry("INTERFACE=%s", interface)); + return {}; + } + + std::map<std::string, std::vector<std::string>> mapperResponse; + mapperResponseMsg.read(mapperResponse); + if (mapperResponse.empty()) + { + // TODO: define repo specific errors and use elog report() + log<level::ERR>("Error reading mapper response", + entry("PATH=%s", path), + entry("INTERFACE=%s", interface)); + return {}; + } + + return mapperResponse.begin()->first; +} + Mode strToMode(const std::string& mode) { auto it = modeMap.find(mode); |