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