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> |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.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 | |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 18 | Objects::Objects(sdbusplus::bus_t& 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); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 28 | |
| 29 | using Interfaces = std::vector<Interface>; |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 30 | using MapperResponse = std::vector< |
| 31 | std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>; |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 32 | MapperResponse result; |
George Liu | f344f84 | 2022-07-01 16:09:41 +0800 | [diff] [blame] | 33 | |
| 34 | try |
| 35 | { |
| 36 | auto response = bus.call(mapperCall); |
| 37 | response.read(result); |
| 38 | } |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 39 | catch (const sdbusplus::exception_t& ex) |
George Liu | f344f84 | 2022-07-01 16:09:41 +0800 | [diff] [blame] | 40 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 41 | lg2::error("Failed to invoke GetSubTree method: {ERROR}", "ERROR", ex); |
George Liu | f344f84 | 2022-07-01 16:09:41 +0800 | [diff] [blame] | 42 | } |
| 43 | |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 44 | if (result.empty()) |
| 45 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 46 | lg2::error("Invalid response from mapper"); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | for (const auto& iter : result) |
| 50 | { |
| 51 | const Path& path = iter.first; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 52 | for (const auto& service_iter : iter.second) |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 53 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 54 | for (const Interface& interface : service_iter.second) |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 55 | { |
George Liu | 3c2f449 | 2020-04-12 11:35:57 +0800 | [diff] [blame] | 56 | if (timeSyncIntf == interface) |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 57 | { |
| 58 | timeSyncMethod = path; |
| 59 | } |
Ed Tanous | 7aa715b | 2018-05-09 17:28:05 -0700 | [diff] [blame] | 60 | } |
Lei YU | debe1d8 | 2017-10-13 13:21:37 +0800 | [diff] [blame] | 61 | } |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | Service Objects::service(const Path& path, const Interface& interface) const |
| 66 | { |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 67 | using Interfaces = std::vector<Interface>; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 68 | auto mapperCall = |
| 69 | bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 70 | mapperCall.append(path); |
| 71 | mapperCall.append(Interfaces({interface})); |
| 72 | |
George Liu | f344f84 | 2022-07-01 16:09:41 +0800 | [diff] [blame] | 73 | std::map<Service, Interfaces> result; |
| 74 | try |
| 75 | { |
| 76 | auto response = bus.call(mapperCall); |
| 77 | response.read(result); |
| 78 | } |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 79 | catch (const sdbusplus::exception_t& ex) |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 80 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 81 | lg2::error("Error in mapper GetObject: {ERROR}", "ERROR", ex); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 84 | if (result.empty()) |
| 85 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 86 | lg2::error("Invalid response from mapper"); |
Deepak Kodihalli | 20ed79e | 2017-07-25 05:48:58 -0500 | [diff] [blame] | 87 | elog<InternalFailure>(); |
| 88 | } |
| 89 | |
| 90 | return result.begin()->first; |
| 91 | } |
| 92 | |
| 93 | } // namespace settings |