Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [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 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 16 | Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus) |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 17 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 18 | std::vector<std::string> settingsIntfs = {autoRebootIntf, powerRestoreIntf}; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 19 | auto depth = 0; |
| 20 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 21 | auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 22 | "GetSubTree"); |
| 23 | mapperCall.append(root); |
| 24 | mapperCall.append(depth); |
| 25 | mapperCall.append(settingsIntfs); |
| 26 | auto response = bus.call(mapperCall); |
| 27 | if (response.is_method_error()) |
| 28 | { |
| 29 | log<level::ERR>("Error in mapper GetSubTree"); |
| 30 | elog<InternalFailure>(); |
| 31 | } |
| 32 | |
| 33 | using Interfaces = std::vector<Interface>; |
| 34 | using MapperResponse = std::map<Path, std::map<Service, Interfaces>>; |
| 35 | MapperResponse result; |
| 36 | response.read(result); |
| 37 | if (result.empty()) |
| 38 | { |
| 39 | log<level::ERR>("Invalid response from mapper"); |
| 40 | elog<InternalFailure>(); |
| 41 | } |
| 42 | |
| 43 | for (const auto& iter : result) |
| 44 | { |
| 45 | const Path& path = iter.first; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 46 | |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 47 | for (const auto& serviceIter : iter.second) |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 48 | { |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 49 | for (const auto& interface : serviceIter.second) |
| 50 | { |
| 51 | if (autoRebootIntf == interface) |
| 52 | { |
| 53 | autoReboot = path; |
| 54 | } |
| 55 | else if (powerRestoreIntf == interface) |
| 56 | { |
| 57 | powerRestorePolicy = path; |
| 58 | } |
| 59 | } |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | Service Objects::service(const Path& path, const Interface& interface) const |
| 65 | { |
| 66 | using Interfaces = std::vector<Interface>; |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 67 | auto mapperCall = |
| 68 | bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 69 | mapperCall.append(path); |
| 70 | mapperCall.append(Interfaces({interface})); |
| 71 | |
| 72 | auto response = bus.call(mapperCall); |
| 73 | if (response.is_method_error()) |
| 74 | { |
| 75 | log<level::ERR>("Error in mapper GetObject"); |
| 76 | elog<InternalFailure>(); |
| 77 | } |
| 78 | |
| 79 | std::map<Service, Interfaces> result; |
| 80 | response.read(result); |
| 81 | if (result.empty()) |
| 82 | { |
| 83 | log<level::ERR>("Invalid response from mapper"); |
| 84 | elog<InternalFailure>(); |
| 85 | } |
| 86 | |
| 87 | return result.begin()->first; |
| 88 | } |
| 89 | |
| 90 | } // namespace settings |