Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 16 | #include "json_parser.hpp" |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 17 | |
| 18 | #include "anyof.hpp" |
| 19 | #include "fallback.hpp" |
| 20 | #include "gpio.hpp" |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 21 | #include "json_config.hpp" |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 22 | #include "sdbusplus.hpp" |
| 23 | #include "tach.hpp" |
| 24 | |
Matthew Barth | 0961fae | 2019-11-15 09:00:27 -0600 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
| 26 | #include <phosphor-logging/log.hpp> |
Matthew Barth | 5060b10 | 2019-12-16 10:46:35 -0600 | [diff] [blame] | 27 | #include <sdbusplus/bus.hpp> |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 28 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
| 29 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 30 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 31 | #include <filesystem> |
| 32 | #include <fstream> |
| 33 | #include <string> |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 34 | |
| 35 | namespace phosphor |
| 36 | { |
| 37 | namespace fan |
| 38 | { |
| 39 | namespace presence |
| 40 | { |
| 41 | |
Matthew Barth | 0961fae | 2019-11-15 09:00:27 -0600 | [diff] [blame] | 42 | using json = nlohmann::json; |
| 43 | namespace fs = std::filesystem; |
| 44 | using namespace phosphor::logging; |
| 45 | |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 46 | policies JsonConfig::_policies; |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 47 | const std::map<std::string, methodHandler> JsonConfig::_methods = { |
| 48 | {"tach", method::getTach}, {"gpio", method::getGpio}}; |
| 49 | const std::map<std::string, rpolicyHandler> JsonConfig::_rpolicies = { |
| 50 | {"anyof", rpolicy::getAnyof}, {"fallback", rpolicy::getFallback}}; |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 51 | |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 52 | const auto loggingPath = "/xyz/openbmc_project/logging"; |
| 53 | const auto loggingCreateIface = "xyz.openbmc_project.Logging.Create"; |
| 54 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 55 | JsonConfig::JsonConfig(sdbusplus::bus::bus& bus) : _bus(bus) |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 56 | {} |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 57 | |
Matthew Barth | 5b83991 | 2021-06-21 14:46:34 -0500 | [diff] [blame] | 58 | void JsonConfig::start() |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 59 | { |
Matthew Barth | 5b83991 | 2021-06-21 14:46:34 -0500 | [diff] [blame] | 60 | using config = fan::JsonConfig; |
| 61 | |
| 62 | process(config::load(config::getConfFile(_bus, confAppName, confFileName))); |
Matt Spinler | 0daedd1 | 2021-01-25 14:46:03 -0600 | [diff] [blame] | 63 | |
| 64 | for (auto& p : _policies) |
| 65 | { |
| 66 | p->monitor(); |
| 67 | } |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | const policies& JsonConfig::get() |
| 71 | { |
| 72 | return _policies; |
| 73 | } |
| 74 | |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 75 | void JsonConfig::sighupHandler(sdeventplus::source::Signal& sigSrc, |
| 76 | const struct signalfd_siginfo* sigInfo) |
| 77 | { |
| 78 | try |
| 79 | { |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 80 | using config = fan::JsonConfig; |
| 81 | |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 82 | _reporter.reset(); |
| 83 | |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 84 | // Load and process the json configuration |
Jolie Ku | 1a56865 | 2020-08-24 16:32:15 +0800 | [diff] [blame] | 85 | process( |
| 86 | config::load(config::getConfFile(_bus, confAppName, confFileName))); |
| 87 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 88 | for (auto& p : _policies) |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 89 | { |
| 90 | p->monitor(); |
| 91 | } |
| 92 | log<level::INFO>("Configuration loaded successfully"); |
| 93 | } |
Patrick Williams | ddb773b | 2021-10-06 11:24:49 -0500 | [diff] [blame^] | 94 | catch (const std::runtime_error& re) |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 95 | { |
| 96 | log<level::ERR>("Error loading config, no config changes made", |
| 97 | entry("LOAD_ERROR=%s", re.what())); |
| 98 | } |
| 99 | } |
| 100 | |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 101 | void JsonConfig::process(const json& jsonConf) |
| 102 | { |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 103 | policies policies; |
| 104 | std::vector<fanPolicy> fans; |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 105 | // Set the expected number of fan entries |
| 106 | // to be size of the list of fan json config entries |
| 107 | // (Must be done to eliminate vector reallocation of fan references) |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 108 | fans.reserve(jsonConf.size()); |
| 109 | for (auto& member : jsonConf) |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 110 | { |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 111 | if (!member.contains("name") || !member.contains("path") || |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 112 | !member.contains("methods") || !member.contains("rpolicy")) |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 113 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 114 | log<level::ERR>("Missing required fan presence properties", |
| 115 | entry("REQUIRED_PROPERTIES=%s", |
| 116 | "{name, path, methods, rpolicy}")); |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 117 | throw std::runtime_error( |
| 118 | "Missing required fan presence properties"); |
| 119 | } |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 120 | |
| 121 | // Loop thru the configured methods of presence detection |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 122 | std::vector<std::unique_ptr<PresenceSensor>> sensors; |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 123 | for (auto& method : member["methods"].items()) |
| 124 | { |
| 125 | if (!method.value().contains("type")) |
| 126 | { |
| 127 | log<level::ERR>( |
| 128 | "Missing required fan presence method type", |
| 129 | entry("FAN_NAME=%s", |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 130 | member["name"].get<std::string>().c_str())); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 131 | throw std::runtime_error( |
| 132 | "Missing required fan presence method type"); |
| 133 | } |
| 134 | // The method type of fan presence detection |
| 135 | // (Must have a supported function within the method namespace) |
| 136 | auto type = method.value()["type"].get<std::string>(); |
| 137 | std::transform(type.begin(), type.end(), type.begin(), tolower); |
| 138 | auto func = _methods.find(type); |
| 139 | if (func != _methods.end()) |
| 140 | { |
| 141 | // Call function for method type |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 142 | auto sensor = func->second(fans.size(), method.value()); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 143 | if (sensor) |
| 144 | { |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 145 | sensors.emplace_back(std::move(sensor)); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | else |
| 149 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 150 | log<level::ERR>( |
| 151 | "Invalid fan presence method type", |
| 152 | entry("FAN_NAME=%s", |
| 153 | member["name"].get<std::string>().c_str()), |
| 154 | entry("METHOD_TYPE=%s", type.c_str())); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 155 | throw std::runtime_error("Invalid fan presence method type"); |
| 156 | } |
| 157 | } |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 158 | |
| 159 | // Get the amount of time a fan must be not present before |
| 160 | // creating an error. |
| 161 | std::optional<size_t> timeUntilError; |
| 162 | if (member.contains("fan_missing_error_time")) |
| 163 | { |
| 164 | timeUntilError = member["fan_missing_error_time"].get<size_t>(); |
| 165 | } |
| 166 | |
| 167 | auto fan = |
| 168 | std::make_tuple(member["name"], member["path"], timeUntilError); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 169 | // Create a fan object |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 170 | fans.emplace_back(std::make_tuple(fan, std::move(sensors))); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 171 | |
| 172 | // Add fan presence policy |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 173 | auto policy = getPolicy(member["rpolicy"], fans.back()); |
| 174 | if (policy) |
| 175 | { |
| 176 | policies.emplace_back(std::move(policy)); |
| 177 | } |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 178 | } |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 179 | |
| 180 | // Success, refresh fans and policies lists |
| 181 | _fans.clear(); |
| 182 | _fans.swap(fans); |
| 183 | |
| 184 | _policies.clear(); |
| 185 | _policies.swap(policies); |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 186 | |
| 187 | // Create the error reporter class if necessary |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 188 | if (std::any_of(_fans.begin(), _fans.end(), [](const auto& fan) { |
| 189 | return std::get<std::optional<size_t>>(std::get<Fan>(fan)) != |
| 190 | std::nullopt; |
| 191 | })) |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 192 | { |
Matt Spinler | 9e9f599 | 2020-09-30 08:29:24 -0500 | [diff] [blame] | 193 | _reporter = std::make_unique<ErrorReporter>(_bus, _fans); |
Matt Spinler | e812239 | 2020-09-24 13:22:18 -0500 | [diff] [blame] | 194 | } |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 195 | } |
| 196 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 197 | std::unique_ptr<RedundancyPolicy> |
| 198 | JsonConfig::getPolicy(const json& rpolicy, const fanPolicy& fpolicy) |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 199 | { |
| 200 | if (!rpolicy.contains("type")) |
| 201 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 202 | log<level::ERR>( |
| 203 | "Missing required fan presence policy type", |
| 204 | entry("FAN_NAME=%s", |
| 205 | std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)).c_str()), |
| 206 | entry("REQUIRED_PROPERTIES=%s", "{type}")); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 207 | throw std::runtime_error("Missing required fan presence policy type"); |
| 208 | } |
| 209 | |
| 210 | // The redundancy policy type for fan presence detection |
| 211 | // (Must have a supported function within the rpolicy namespace) |
| 212 | auto type = rpolicy["type"].get<std::string>(); |
| 213 | std::transform(type.begin(), type.end(), type.begin(), tolower); |
| 214 | auto func = _rpolicies.find(type); |
| 215 | if (func != _rpolicies.end()) |
| 216 | { |
Matthew Barth | f3e7047 | 2019-12-03 13:33:20 -0600 | [diff] [blame] | 217 | // Call function for redundancy policy type and return the policy |
| 218 | return func->second(fpolicy); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 219 | } |
| 220 | else |
| 221 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 222 | log<level::ERR>( |
| 223 | "Invalid fan presence policy type", |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 224 | entry("FAN_NAME=%s", |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 225 | std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)).c_str()), |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 226 | entry("RPOLICY_TYPE=%s", type.c_str())); |
| 227 | throw std::runtime_error("Invalid fan presence methods policy type"); |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 231 | /** |
| 232 | * Methods of fan presence detection function definitions |
| 233 | */ |
| 234 | namespace method |
| 235 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 236 | // Get a constructed presence sensor for fan presence detection by tach |
| 237 | std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, const json& method) |
| 238 | { |
| 239 | if (!method.contains("sensors") || method["sensors"].size() == 0) |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 240 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 241 | log<level::ERR>("Missing required tach method properties", |
| 242 | entry("FAN_ENTRY=%d", fanIndex), |
| 243 | entry("REQUIRED_PROPERTIES=%s", "{sensors}")); |
| 244 | throw std::runtime_error("Missing required tach method properties"); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 245 | } |
| 246 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 247 | std::vector<std::string> sensors; |
| 248 | for (auto& sensor : method["sensors"]) |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 249 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 250 | sensors.emplace_back(sensor.get<std::string>()); |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 251 | } |
| 252 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 253 | return std::make_unique<PolicyAccess<Tach, JsonConfig>>(fanIndex, |
| 254 | std::move(sensors)); |
| 255 | } |
| 256 | |
| 257 | // Get a constructed presence sensor for fan presence detection by gpio |
| 258 | std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, const json& method) |
| 259 | { |
| 260 | if (!method.contains("physpath") || !method.contains("devpath") || |
| 261 | !method.contains("key")) |
| 262 | { |
| 263 | log<level::ERR>( |
| 264 | "Missing required gpio method properties", |
| 265 | entry("FAN_ENTRY=%d", fanIndex), |
| 266 | entry("REQUIRED_PROPERTIES=%s", "{physpath, devpath, key}")); |
| 267 | throw std::runtime_error("Missing required gpio method properties"); |
| 268 | } |
| 269 | |
| 270 | auto physpath = method["physpath"].get<std::string>(); |
| 271 | auto devpath = method["devpath"].get<std::string>(); |
| 272 | auto key = method["key"].get<unsigned int>(); |
| 273 | |
Mike Capps | a35a890 | 2021-06-10 10:20:14 -0400 | [diff] [blame] | 274 | try |
| 275 | { |
| 276 | return std::make_unique<PolicyAccess<Gpio, JsonConfig>>( |
| 277 | fanIndex, physpath, devpath, key); |
| 278 | } |
| 279 | catch (const sdbusplus::exception_t& e) |
| 280 | { |
| 281 | namespace sdlogging = sdbusplus::xyz::openbmc_project::Logging::server; |
| 282 | |
| 283 | log<level::ERR>( |
| 284 | fmt::format( |
| 285 | "Error creating Gpio device bridge, hardware not detected: {}", |
| 286 | e.what()) |
| 287 | .c_str()); |
| 288 | |
| 289 | auto severity = |
| 290 | sdlogging::convertForMessage(sdlogging::Entry::Level::Error); |
| 291 | |
| 292 | std::map<std::string, std::string> additionalData{ |
| 293 | {"PHYSPATH", physpath}, |
| 294 | {"DEVPATH", devpath}, |
| 295 | {"FANINDEX", std::to_string(fanIndex)}}; |
| 296 | |
| 297 | try |
| 298 | { |
| 299 | |
| 300 | util::SDBusPlus::lookupAndCallMethod( |
| 301 | loggingPath, loggingCreateIface, "Create", |
| 302 | "xyz.openbmc_project.Fan.Presence.Error.GPIODeviceUnavailable", |
| 303 | severity, additionalData); |
| 304 | } |
| 305 | catch (const util::DBusError& e) |
| 306 | { |
| 307 | log<level::ERR>(fmt::format("Call to create an error log for " |
| 308 | "presence-sensor failure failed: {}", |
| 309 | e.what()) |
| 310 | .c_str()); |
| 311 | } |
| 312 | |
| 313 | return std::make_unique<PolicyAccess<NullGpio, JsonConfig>>(); |
| 314 | } |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 317 | } // namespace method |
| 318 | |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 319 | /** |
| 320 | * Redundancy policies for fan presence detection function definitions |
| 321 | */ |
| 322 | namespace rpolicy |
| 323 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 324 | // Get an `Anyof` redundancy policy for the fan |
| 325 | std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan) |
| 326 | { |
| 327 | std::vector<std::reference_wrapper<PresenceSensor>> pSensors; |
| 328 | for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan)) |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 329 | { |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 330 | pSensors.emplace_back(*fanSensor); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 331 | } |
| 332 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 333 | return std::make_unique<AnyOf>(std::get<fanPolicyFanPos>(fan), pSensors); |
| 334 | } |
Matthew Barth | 26ad44a | 2019-11-22 15:37:14 -0600 | [diff] [blame] | 335 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 336 | // Get a `Fallback` redundancy policy for the fan |
| 337 | std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan) |
| 338 | { |
| 339 | std::vector<std::reference_wrapper<PresenceSensor>> pSensors; |
| 340 | for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan)) |
| 341 | { |
| 342 | // Place in the order given to fallback correctly |
| 343 | pSensors.emplace_back(*fanSensor); |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 344 | } |
| 345 | |
Matthew Barth | 2d2caa3 | 2020-05-26 11:07:24 -0500 | [diff] [blame] | 346 | return std::make_unique<Fallback>(std::get<fanPolicyFanPos>(fan), pSensors); |
| 347 | } |
| 348 | |
| 349 | } // namespace rpolicy |
Matthew Barth | aa8d81d | 2019-11-21 14:07:31 -0600 | [diff] [blame] | 350 | |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 351 | } // namespace presence |
| 352 | } // namespace fan |
| 353 | } // namespace phosphor |