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 | { |
George Liu | 0a70452 | 2020-04-13 14:51:40 +0800 | [diff] [blame] | 20 | std::vector<std::string> settingsIntfs = {timeSyncIntf}; |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 21 | auto depth = 0; |
| 22 | |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 23 | auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 24 | "GetSubTree"); |
| 25 | mapperCall.append(root); |
| 26 | mapperCall.append(depth); |
| 27 | mapperCall.append(settingsIntfs); |
| 28 | auto response = bus.call(mapperCall); |
| 29 | if (response.is_method_error()) |
| 30 | { |
| 31 | log<level::ERR>("Error in mapper GetSubTree"); |
| 32 | elog<InternalFailure>(); |
| 33 | } |
| 34 | |
| 35 | using Interfaces = std::vector<Interface>; |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 36 | using MapperResponse = std::vector< |
| 37 | std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>; |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 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 (const auto& iter : result) |
| 47 | { |
| 48 | const Path& path = iter.first; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 49 | for (const auto& service_iter : iter.second) |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 50 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 51 | for (const Interface& interface : service_iter.second) |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 52 | { |
George Liu | 3c2f449 | 2020-04-12 11:35:57 +0800 | [diff] [blame] | 53 | if (timeSyncIntf == interface) |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 54 | { |
| 55 | timeSyncMethod = path; |
| 56 | } |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 57 | } |
Lei YU | debe1d8 | 2017-10-13 13:21:37 +0800 | [diff] [blame] | 58 | } |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | Service Objects::service(const Path& path, const Interface& interface) const |
| 63 | { |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 64 | using Interfaces = std::vector<Interface>; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 65 | auto mapperCall = |
| 66 | bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 67 | mapperCall.append(path); |
| 68 | mapperCall.append(Interfaces({interface})); |
| 69 | |
| 70 | auto response = bus.call(mapperCall); |
| 71 | if (response.is_method_error()) |
| 72 | { |
| 73 | log<level::ERR>("Error in mapper GetObject"); |
| 74 | elog<InternalFailure>(); |
| 75 | } |
| 76 | |
| 77 | std::map<Service, Interfaces> result; |
| 78 | response.read(result); |
| 79 | if (result.empty()) |
| 80 | { |
| 81 | log<level::ERR>("Invalid response from mapper"); |
| 82 | elog<InternalFailure>(); |
| 83 | } |
| 84 | |
| 85 | return result.begin()->first; |
| 86 | } |
| 87 | |
| 88 | } // namespace settings |