| Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include "utils.hpp" | 
 | 2 |  | 
 | 3 | #include "xyz/openbmc_project/Common/error.hpp" | 
 | 4 |  | 
 | 5 | #include <array> | 
 | 6 | #include <ctime> | 
 | 7 | #include <iostream> | 
 | 8 | #include <map> | 
| Deepak Kodihalli | c2feac9 | 2019-04-30 17:21:19 +0530 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> | 
| Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 10 | #include <stdexcept> | 
 | 11 | #include <string> | 
 | 12 | #include <vector> | 
 | 13 |  | 
 | 14 | namespace pldm | 
 | 15 | { | 
 | 16 | using namespace phosphor::logging; | 
 | 17 |  | 
 | 18 | constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper"; | 
 | 19 | constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; | 
 | 20 | constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper"; | 
 | 21 |  | 
 | 22 | namespace responder | 
 | 23 | { | 
 | 24 |  | 
 | 25 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, | 
 | 26 |                        const std::string& interface) | 
 | 27 | { | 
 | 28 |     using DbusInterfaceList = std::vector<std::string>; | 
 | 29 |     std::map<std::string, std::vector<std::string>> mapperResponse; | 
 | 30 |  | 
 | 31 |     try | 
 | 32 |     { | 
 | 33 |         auto mapper = bus.new_method_call(mapperBusName, mapperPath, | 
 | 34 |                                           mapperInterface, "GetObject"); | 
 | 35 |         mapper.append(path, DbusInterfaceList({interface})); | 
 | 36 |  | 
 | 37 |         auto mapperResponseMsg = bus.call(mapper); | 
 | 38 |         mapperResponseMsg.read(mapperResponse); | 
 | 39 |     } | 
 | 40 |     catch (std::exception& e) | 
 | 41 |     { | 
 | 42 |         log<level::ERR>("Error in mapper call", entry("ERROR=%s", e.what()), | 
 | 43 |                         entry("PATH=%s", path.c_str()), | 
 | 44 |                         entry("INTERFACE=%s", interface.c_str())); | 
 | 45 |         throw; | 
 | 46 |     } | 
 | 47 |     return mapperResponse.begin()->first; | 
 | 48 | } | 
 | 49 |  | 
 | 50 | } // namespace responder | 
 | 51 | } // namespace pldm |