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