Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 1 | #include "settings.hpp" |
| 2 | |
| 3 | #include "xyz/openbmc_project/Common/error.hpp" |
| 4 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/elog-errors.hpp> |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 7 | #include <sdbusplus/exception.hpp> |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 8 | |
| 9 | namespace settings |
| 10 | { |
| 11 | |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 12 | PHOSPHOR_LOG2_USING; |
| 13 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 14 | using namespace phosphor::logging; |
| 15 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 16 | |
| 17 | constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper"; |
| 18 | constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper"; |
| 19 | constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper"; |
| 20 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 21 | Objects::Objects(sdbusplus::bus_t& bus, const Path& root) : bus(bus) |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 22 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 23 | std::vector<std::string> settingsIntfs = {autoRebootIntf, powerRestoreIntf}; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 24 | auto depth = 0; |
| 25 | |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 26 | auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf, |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 27 | "GetSubTree"); |
| 28 | mapperCall.append(root); |
| 29 | mapperCall.append(depth); |
| 30 | mapperCall.append(settingsIntfs); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 31 | |
| 32 | using Interfaces = std::vector<Interface>; |
| 33 | using MapperResponse = std::map<Path, std::map<Service, Interfaces>>; |
| 34 | MapperResponse result; |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 35 | |
| 36 | try |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 37 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 38 | auto response = bus.call(mapperCall); |
| 39 | |
| 40 | response.read(result); |
| 41 | if (result.empty()) |
| 42 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 43 | error("Invalid response from mapper"); |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 44 | elog<InternalFailure>(); |
| 45 | } |
| 46 | } |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 47 | catch (const sdbusplus::exception_t& e) |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 48 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 49 | error("Error in mapper GetSubTree: {ERROR}", "ERROR", e); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 50 | elog<InternalFailure>(); |
| 51 | } |
| 52 | |
| 53 | for (const auto& iter : result) |
| 54 | { |
| 55 | const Path& path = iter.first; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 56 | |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 57 | for (const auto& serviceIter : iter.second) |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 58 | { |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 59 | for (const auto& interface : serviceIter.second) |
| 60 | { |
| 61 | if (autoRebootIntf == interface) |
| 62 | { |
Andrew Geissler | e87db70 | 2020-10-22 19:33:26 -0500 | [diff] [blame] | 63 | /* There are two implementations of the AutoReboot |
| 64 | * Interface. A persistent user setting and a one-time |
| 65 | * setting which is only valid for one boot of the system. |
| 66 | * The one-time setting will have "one_time" in its |
| 67 | * object path. |
| 68 | */ |
| 69 | if (path.find("one_time") != std::string::npos) |
| 70 | { |
| 71 | autoRebootOneTime = path; |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | autoReboot = path; |
| 76 | } |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 77 | } |
| 78 | else if (powerRestoreIntf == interface) |
| 79 | { |
Andrew Geissler | 35ca2e3 | 2021-02-09 13:54:26 -0600 | [diff] [blame] | 80 | /* There are two implementations of the PowerRestorePolicy |
| 81 | * Interface. A persistent user setting and a one-time |
| 82 | * setting which is only valid for one boot of the system. |
| 83 | * The one-time setting will have "one_time" in its |
| 84 | * object path. |
| 85 | */ |
| 86 | if (path.find("one_time") != std::string::npos) |
| 87 | { |
| 88 | powerRestorePolicyOneTime = path; |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | powerRestorePolicy = path; |
| 93 | } |
Matt Spinler | 14e14cd | 2018-09-07 15:04:16 -0500 | [diff] [blame] | 94 | } |
| 95 | } |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | Service Objects::service(const Path& path, const Interface& interface) const |
| 101 | { |
| 102 | using Interfaces = std::vector<Interface>; |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 103 | auto mapperCall = |
| 104 | bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 105 | mapperCall.append(path); |
| 106 | mapperCall.append(Interfaces({interface})); |
| 107 | |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 108 | std::map<Service, Interfaces> result; |
| 109 | |
| 110 | try |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 111 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 112 | auto response = bus.call(mapperCall); |
| 113 | response.read(result); |
| 114 | } |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 115 | catch (const sdbusplus::exception_t& e) |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 116 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 117 | error("Error in mapper GetObject: {ERROR}", "ERROR", e); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 118 | elog<InternalFailure>(); |
| 119 | } |
| 120 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 121 | if (result.empty()) |
| 122 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 123 | error("Invalid response from mapper"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 124 | elog<InternalFailure>(); |
| 125 | } |
| 126 | |
| 127 | return result.begin()->first; |
| 128 | } |
| 129 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 130 | HostObjects::HostObjects(sdbusplus::bus_t& bus, size_t id) : |
Potin Lai | c328a4c | 2022-03-18 23:49:37 +0800 | [diff] [blame] | 131 | Objects(bus, Path("/xyz/openbmc_project/control/host") + std::to_string(id)) |
| 132 | {} |
| 133 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 134 | } // namespace settings |