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> |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 8 | #include <xyz/openbmc_project/ObjectMapper/client.hpp> |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 9 | |
| 10 | namespace settings |
| 11 | { |
| 12 | |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 13 | PHOSPHOR_LOG2_USING; |
| 14 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 15 | using namespace phosphor::logging; |
| 16 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 17 | |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 18 | using ObjectMapper = sdbusplus::client::xyz::openbmc_project::ObjectMapper<>; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 19 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 20 | Objects::Objects(sdbusplus::bus_t& bus, const Path& root) : bus(bus) |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 21 | { |
Andrew Geissler | 58a1801 | 2018-01-19 19:36:05 -0800 | [diff] [blame] | 22 | std::vector<std::string> settingsIntfs = {autoRebootIntf, powerRestoreIntf}; |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 23 | auto depth = 0; |
| 24 | |
Patrick Williams | 9a286db | 2024-01-17 06:29:47 -0600 | [diff] [blame] | 25 | auto mapperCall = bus.new_method_call( |
| 26 | ObjectMapper::default_service, ObjectMapper::instance_path, |
| 27 | ObjectMapper::interface, "GetSubTree"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 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>; |
Patrick Williams | 1b2c3c0 | 2024-08-16 15:20:29 -0400 | [diff] [blame] | 103 | auto mapperCall = bus.new_method_call( |
| 104 | ObjectMapper::default_service, ObjectMapper::instance_path, |
| 105 | ObjectMapper::interface, "GetObject"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 106 | mapperCall.append(path); |
| 107 | mapperCall.append(Interfaces({interface})); |
| 108 | |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 109 | std::map<Service, Interfaces> result; |
| 110 | |
| 111 | try |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 112 | { |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 113 | auto response = bus.call(mapperCall); |
| 114 | response.read(result); |
| 115 | } |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 116 | catch (const sdbusplus::exception_t& e) |
Anthony Wilson | 32c532e | 2018-10-25 21:56:07 -0500 | [diff] [blame] | 117 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 118 | error("Error in mapper GetObject: {ERROR}", "ERROR", e); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 119 | elog<InternalFailure>(); |
| 120 | } |
| 121 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 122 | if (result.empty()) |
| 123 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame] | 124 | error("Invalid response from mapper"); |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 125 | elog<InternalFailure>(); |
| 126 | } |
| 127 | |
| 128 | return result.begin()->first; |
| 129 | } |
| 130 | |
Patrick Williams | f053e6f | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 131 | HostObjects::HostObjects(sdbusplus::bus_t& bus, size_t id) : |
Potin Lai | c328a4c | 2022-03-18 23:49:37 +0800 | [diff] [blame] | 132 | Objects(bus, Path("/xyz/openbmc_project/control/host") + std::to_string(id)) |
| 133 | {} |
| 134 | |
Deepak Kodihalli | a646edd | 2017-07-25 07:28:45 -0500 | [diff] [blame] | 135 | } // namespace settings |