Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -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 | |
| 16 | Objects::Objects() |
| 17 | { |
| 18 | auto bus = sdbusplus::bus::new_default(); |
| 19 | std::vector<std::string> settingsIntfs = |
Lei YU | debe1d8 | 2017-10-13 13:21:37 +0800 | [diff] [blame] | 20 | {timeOwnerIntf, timeSyncIntf, hostStateIntf}; |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 21 | auto depth = 0; |
| 22 | |
| 23 | auto mapperCall = bus.new_method_call(mapperService, |
| 24 | mapperPath, |
| 25 | mapperIntf, |
| 26 | "GetSubTree"); |
| 27 | mapperCall.append(root); |
| 28 | mapperCall.append(depth); |
| 29 | mapperCall.append(settingsIntfs); |
| 30 | auto response = bus.call(mapperCall); |
| 31 | if (response.is_method_error()) |
| 32 | { |
| 33 | log<level::ERR>("Error in mapper GetSubTree"); |
| 34 | elog<InternalFailure>(); |
| 35 | } |
| 36 | |
| 37 | using Interfaces = std::vector<Interface>; |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 38 | using MapperResponse = std::vector< |
| 39 | std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>; |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 40 | MapperResponse result; |
| 41 | response.read(result); |
| 42 | if (result.empty()) |
| 43 | { |
| 44 | log<level::ERR>("Invalid response from mapper"); |
| 45 | elog<InternalFailure>(); |
| 46 | } |
| 47 | |
| 48 | for (const auto& iter : result) |
| 49 | { |
| 50 | const Path& path = iter.first; |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 51 | for (const auto& service_iter: iter.second) |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 52 | { |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 53 | for (const Interface& interface: service_iter.second) |
| 54 | { |
| 55 | if (timeOwnerIntf == interface) |
| 56 | { |
| 57 | timeOwner = path; |
| 58 | } |
| 59 | else if (timeSyncIntf == interface) |
| 60 | { |
| 61 | timeSyncMethod = path; |
| 62 | } |
| 63 | else if (hostStateIntf == interface) |
| 64 | { |
| 65 | hostState = path; |
| 66 | } |
| 67 | } |
Lei YU | debe1d8 | 2017-10-13 13:21:37 +0800 | [diff] [blame] | 68 | } |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | Service Objects::service(const Path& path, const Interface& interface) const |
| 73 | { |
| 74 | auto bus = sdbusplus::bus::new_default(); |
| 75 | using Interfaces = std::vector<Interface>; |
| 76 | auto mapperCall = bus.new_method_call(mapperService, |
| 77 | mapperPath, |
| 78 | mapperIntf, |
| 79 | "GetObject"); |
| 80 | mapperCall.append(path); |
| 81 | mapperCall.append(Interfaces({interface})); |
| 82 | |
| 83 | auto response = bus.call(mapperCall); |
| 84 | if (response.is_method_error()) |
| 85 | { |
| 86 | log<level::ERR>("Error in mapper GetObject"); |
| 87 | elog<InternalFailure>(); |
| 88 | } |
| 89 | |
| 90 | std::map<Service, Interfaces> result; |
| 91 | response.read(result); |
| 92 | if (result.empty()) |
| 93 | { |
| 94 | log<level::ERR>("Invalid response from mapper"); |
| 95 | elog<InternalFailure>(); |
| 96 | } |
| 97 | |
| 98 | return result.begin()->first; |
| 99 | } |
| 100 | |
| 101 | } // namespace settings |