Tom Joseph | 19b4f40 | 2017-08-02 17:59:30 +0530 | [diff] [blame^] | 1 | #include <phosphor-logging/elog-errors.hpp> |
| 2 | #include <phosphor-logging/log.hpp> |
| 3 | #include "xyz/openbmc_project/Common/error.hpp" |
| 4 | #include "settings.hpp" |
| 5 | |
| 6 | namespace settings |
| 7 | { |
| 8 | |
| 9 | using namespace phosphor::logging; |
| 10 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 11 | |
| 12 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
| 13 | constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 14 | constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; |
| 15 | |
| 16 | Objects::Objects(sdbusplus::bus::bus& bus, |
| 17 | const std::vector<Interface>& filter): |
| 18 | bus(bus) |
| 19 | { |
| 20 | auto depth = 0; |
| 21 | |
| 22 | auto mapperCall = bus.new_method_call(mapperService, |
| 23 | mapperPath, |
| 24 | mapperIntf, |
| 25 | "GetSubTree"); |
| 26 | mapperCall.append(root); |
| 27 | mapperCall.append(depth); |
| 28 | mapperCall.append(filter); |
| 29 | auto response = bus.call(mapperCall); |
| 30 | if (response.is_method_error()) |
| 31 | { |
| 32 | log<level::ERR>("Error in mapper GetSubTree"); |
| 33 | elog<InternalFailure>(); |
| 34 | } |
| 35 | |
| 36 | using Interfaces = std::vector<Interface>; |
| 37 | using MapperResponse = std::map<Path, std::map<Service, Interfaces>>; |
| 38 | MapperResponse result; |
| 39 | response.read(result); |
| 40 | if (result.empty()) |
| 41 | { |
| 42 | log<level::ERR>("Invalid response from mapper"); |
| 43 | elog<InternalFailure>(); |
| 44 | } |
| 45 | |
| 46 | for (auto& iter : result) |
| 47 | { |
| 48 | const auto& path = iter.first; |
| 49 | auto& interface = iter.second.begin()->second[0]; |
| 50 | map.emplace(std::move(interface), path); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | Service Objects::service(const Path& path, const Interface& interface) const |
| 55 | { |
| 56 | using Interfaces = std::vector<Interface>; |
| 57 | auto mapperCall = bus.new_method_call(mapperService, |
| 58 | mapperPath, |
| 59 | mapperIntf, |
| 60 | "GetObject"); |
| 61 | mapperCall.append(path); |
| 62 | mapperCall.append(Interfaces({interface})); |
| 63 | |
| 64 | auto response = bus.call(mapperCall); |
| 65 | if (response.is_method_error()) |
| 66 | { |
| 67 | log<level::ERR>("Error in mapper GetObject"); |
| 68 | elog<InternalFailure>(); |
| 69 | } |
| 70 | |
| 71 | std::map<Service, Interfaces> result; |
| 72 | response.read(result); |
| 73 | if (result.empty()) |
| 74 | { |
| 75 | log<level::ERR>("Invalid response from mapper"); |
| 76 | elog<InternalFailure>(); |
| 77 | } |
| 78 | |
| 79 | return result.begin()->first; |
| 80 | } |
| 81 | |
| 82 | } // namespace settings |