James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel 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 | */ |
| 16 | |
| 17 | #include <unistd.h> |
| 18 | |
| 19 | #include <TachSensor.hpp> |
| 20 | #include <Utils.hpp> |
| 21 | #include <boost/algorithm/string/predicate.hpp> |
| 22 | #include <boost/algorithm/string/replace.hpp> |
| 23 | #include <boost/date_time/posix_time/posix_time.hpp> |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 24 | #include <fstream> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 25 | #include <iostream> |
| 26 | #include <limits> |
| 27 | #include <sdbusplus/asio/connection.hpp> |
| 28 | #include <sdbusplus/asio/object_server.hpp> |
| 29 | #include <string> |
| 30 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 31 | static constexpr unsigned int pwmPollMs = 500; |
| 32 | static constexpr size_t warnAfterErrorCount = 10; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 33 | |
| 34 | TachSensor::TachSensor(const std::string &path, |
| 35 | sdbusplus::asio::object_server &objectServer, |
| 36 | std::shared_ptr<sdbusplus::asio::connection> &conn, |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 37 | std::unique_ptr<PresenceSensor> &&presence, |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 38 | std::unique_ptr<RedundancySensor> &redundancy, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 39 | boost::asio::io_service &io, const std::string &fanName, |
| 40 | std::vector<thresholds::Threshold> &&_thresholds, |
| 41 | const std::string &sensorConfiguration) : |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 42 | Sensor(boost::replace_all_copy(fanName, " ", "_"), path, |
| 43 | std::move(_thresholds)), |
| 44 | objServer(objectServer), dbusConnection(conn), |
| 45 | presence(std::move(presence)), redundancy(redundancy), |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 46 | configuration(sensorConfiguration), |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 47 | inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), errCount(0), |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 48 | // todo, get these from config |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 49 | maxValue(25000), minValue(0) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 50 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 51 | sensorInterface = objectServer.add_interface( |
| 52 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 53 | "xyz.openbmc_project.Sensor.Value"); |
| 54 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 55 | if (thresholds::hasWarningInterface(thresholds)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 56 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 57 | thresholdInterfaceWarning = objectServer.add_interface( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 58 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 59 | "xyz.openbmc_project.Sensor.Threshold.Warning"); |
| 60 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 61 | if (thresholds::hasCriticalInterface(thresholds)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 62 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 63 | thresholdInterfaceCritical = objectServer.add_interface( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 64 | "/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 65 | "xyz.openbmc_project.Sensor.Threshold.Critical"); |
| 66 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 67 | setInitialProperties(conn); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 68 | isPowerOn(dbusConnection); // first call initializes |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 69 | setupRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | TachSensor::~TachSensor() |
| 73 | { |
| 74 | // close the input dev to cancel async operations |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 75 | inputDev.close(); |
| 76 | waitTimer.cancel(); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 77 | objServer.remove_interface(thresholdInterfaceWarning); |
| 78 | objServer.remove_interface(thresholdInterfaceCritical); |
| 79 | objServer.remove_interface(sensorInterface); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 82 | void TachSensor::setupRead(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 83 | { |
| 84 | boost::asio::async_read_until( |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 85 | inputDev, readBuf, '\n', |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 86 | [&](const boost::system::error_code &ec, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 87 | std::size_t /*bytes_transfered*/) { handleResponse(ec); }); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 90 | void TachSensor::handleResponse(const boost::system::error_code &err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 91 | { |
| 92 | if (err == boost::system::errc::bad_file_descriptor) |
| 93 | { |
| 94 | return; // we're being destroyed |
| 95 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 96 | bool missing = false; |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 97 | size_t pollTime = pwmPollMs; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 98 | if (presence) |
| 99 | { |
| 100 | if (!presence->getValue()) |
| 101 | { |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 102 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 103 | missing = true; |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 104 | pollTime = sensorFailedPollTimeMs; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 107 | std::istream responseStream(&readBuf); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 108 | if (!missing) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 109 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 110 | if (!err) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 111 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 112 | std::string response; |
| 113 | try |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 114 | { |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 115 | std::getline(responseStream, response); |
| 116 | float nvalue = std::stof(response); |
| 117 | responseStream.clear(); |
| 118 | if (nvalue != value) |
| 119 | { |
| 120 | updateValue(nvalue); |
| 121 | } |
| 122 | errCount = 0; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 123 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 124 | catch (const std::invalid_argument &) |
| 125 | { |
| 126 | errCount++; |
| 127 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 128 | } |
| 129 | else |
| 130 | { |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 131 | pollTime = sensorFailedPollTimeMs; |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 132 | errCount++; |
| 133 | } |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 134 | if (errCount >= warnAfterErrorCount) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 135 | { |
| 136 | // only an error if power is on |
| 137 | if (isPowerOn(dbusConnection)) |
| 138 | { |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 139 | // only print once |
| 140 | if (errCount == warnAfterErrorCount) |
| 141 | { |
| 142 | std::cerr << "Failure to read sensor " << name << " at " |
| 143 | << path << " ec:" << err << "\n"; |
| 144 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 145 | updateValue(0); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | errCount = 0; // check power again in 10 cycles |
James Feist | 1169eb4 | 2018-10-31 10:08:47 -0700 | [diff] [blame] | 150 | updateValue(std::numeric_limits<double>::quiet_NaN()); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 151 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 154 | responseStream.clear(); |
| 155 | inputDev.close(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 156 | int fd = open(path.c_str(), O_RDONLY); |
| 157 | if (fd <= 0) |
| 158 | { |
| 159 | return; // we're no longer valid |
| 160 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 161 | inputDev.assign(fd); |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 162 | waitTimer.expires_from_now(boost::posix_time::milliseconds(pollTime)); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 163 | waitTimer.async_wait([&](const boost::system::error_code &ec) { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 164 | if (ec == boost::asio::error::operation_aborted) |
| 165 | { |
| 166 | return; // we're being canceled |
| 167 | } |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 168 | setupRead(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 169 | }); |
| 170 | } |
| 171 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 172 | void TachSensor::checkThresholds(void) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 173 | { |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 174 | bool status = thresholds::checkThresholds(this); |
| 175 | if (redundancy) |
| 176 | { |
| 177 | redundancy->update("/xyz/openbmc_project/sensors/fan_tach/" + name, |
| 178 | !status); |
| 179 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 182 | void TachSensor::updateValue(const double &newValue) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 183 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 184 | sensorInterface->set_property("Value", newValue); |
| 185 | value = newValue; |
| 186 | checkThresholds(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 189 | void TachSensor::setInitialProperties( |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 190 | std::shared_ptr<sdbusplus::asio::connection> &conn) |
| 191 | { |
| 192 | // todo, get max and min from configuration |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 193 | sensorInterface->register_property("MaxValue", maxValue); |
| 194 | sensorInterface->register_property("MinValue", minValue); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 195 | sensorInterface->register_property("Value", value); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 196 | |
| 197 | for (auto &threshold : thresholds) |
| 198 | { |
| 199 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface; |
| 200 | std::string level; |
| 201 | std::string alarm; |
| 202 | if (threshold.level == thresholds::Level::CRITICAL) |
| 203 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 204 | iface = thresholdInterfaceCritical; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 205 | if (threshold.direction == thresholds::Direction::HIGH) |
| 206 | { |
| 207 | level = "CriticalHigh"; |
| 208 | alarm = "CriticalAlarmHigh"; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | level = "CriticalLow"; |
| 213 | alarm = "CriticalAlarmLow"; |
| 214 | } |
| 215 | } |
| 216 | else if (threshold.level == thresholds::Level::WARNING) |
| 217 | { |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 218 | iface = thresholdInterfaceWarning; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 219 | if (threshold.direction == thresholds::Direction::HIGH) |
| 220 | { |
| 221 | level = "WarningHigh"; |
| 222 | alarm = "WarningAlarmHigh"; |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | level = "WarningLow"; |
| 227 | alarm = "WarningAlarmLow"; |
| 228 | } |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | std::cerr << "Unknown threshold level" << threshold.level << "\n"; |
| 233 | continue; |
| 234 | } |
| 235 | if (!iface) |
| 236 | { |
| 237 | std::cout << "trying to set uninitialized interface\n"; |
| 238 | continue; |
| 239 | } |
| 240 | iface->register_property( |
| 241 | level, threshold.value, |
| 242 | [&](const double &request, double &oldValue) { |
| 243 | oldValue = request; // todo, just let the config do this? |
| 244 | threshold.value = request; |
| 245 | thresholds::persistThreshold( |
| 246 | configuration, |
| 247 | "xyz.openbmc_project.Configuration.AspeedFan", threshold, |
| 248 | conn); |
| 249 | return 1; |
| 250 | }); |
| 251 | iface->register_property(alarm, false); |
| 252 | } |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 253 | if (!sensorInterface->initialize()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 254 | { |
| 255 | std::cerr << "error initializing value interface\n"; |
| 256 | } |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 257 | if (thresholdInterfaceWarning && !thresholdInterfaceWarning->initialize()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 258 | { |
| 259 | std::cerr << "error initializing warning threshold interface\n"; |
| 260 | } |
| 261 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 262 | if (thresholdInterfaceCritical && !thresholdInterfaceCritical->initialize()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 263 | { |
| 264 | std::cerr << "error initializing critical threshold interface\n"; |
| 265 | } |
| 266 | } |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 267 | |
| 268 | PresenceSensor::PresenceSensor(const size_t index, bool inverted, |
| 269 | boost::asio::io_service &io) : |
| 270 | inverted(inverted), |
| 271 | inputDev(io) |
| 272 | { |
| 273 | // todo: use gpiodaemon |
| 274 | std::string device = gpioPath + std::string("gpio") + std::to_string(index); |
| 275 | fd = open((device + "/value").c_str(), O_RDONLY); |
| 276 | if (fd < 0) |
| 277 | { |
| 278 | std::cerr << "Error opening gpio " << index << "\n"; |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | std::ofstream deviceFile(device + "/edge"); |
| 283 | if (!deviceFile.good()) |
| 284 | { |
| 285 | std::cerr << "Error setting edge " << device << "\n"; |
| 286 | return; |
| 287 | } |
| 288 | deviceFile << "both"; |
| 289 | deviceFile.close(); |
| 290 | |
| 291 | inputDev.assign(boost::asio::ip::tcp::v4(), fd); |
| 292 | monitorPresence(); |
| 293 | read(); |
| 294 | } |
| 295 | |
| 296 | PresenceSensor::~PresenceSensor() |
| 297 | { |
| 298 | inputDev.close(); |
| 299 | close(fd); |
| 300 | } |
| 301 | |
| 302 | void PresenceSensor::monitorPresence(void) |
| 303 | { |
| 304 | inputDev.async_wait(boost::asio::ip::tcp::socket::wait_error, |
| 305 | [this](const boost::system::error_code &ec) { |
| 306 | if (ec == boost::system::errc::bad_file_descriptor) |
| 307 | { |
| 308 | return; // we're being destroyed |
| 309 | } |
| 310 | else if (ec) |
| 311 | { |
| 312 | std::cerr |
| 313 | << "Error on presence sensor socket\n"; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | read(); |
| 318 | } |
| 319 | monitorPresence(); |
| 320 | }); |
| 321 | } |
| 322 | |
| 323 | void PresenceSensor::read(void) |
| 324 | { |
| 325 | constexpr size_t readSize = sizeof("0"); |
| 326 | std::string readBuf; |
| 327 | readBuf.resize(readSize); |
| 328 | lseek(fd, 0, SEEK_SET); |
| 329 | size_t r = ::read(fd, readBuf.data(), readSize); |
| 330 | if (r != 1) |
| 331 | { |
| 332 | std::cerr << "Error reading gpio\n"; |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | bool value = std::stoi(readBuf); |
| 337 | if (inverted) |
| 338 | { |
| 339 | value = !value; |
| 340 | } |
| 341 | status = value; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | bool PresenceSensor::getValue(void) |
| 346 | { |
| 347 | return status; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame^] | 348 | } |
| 349 | |
| 350 | RedundancySensor::RedundancySensor( |
| 351 | size_t count, const std::vector<std::string> &children, |
| 352 | sdbusplus::asio::object_server &objectServer) : |
| 353 | count(count), |
| 354 | iface(objectServer.add_interface( |
| 355 | "/xyz/openbmc_project/control/FanRedundancy/Tach", |
| 356 | "xyz.openbmc_project.control.FanRedundancy")), |
| 357 | objectServer(objectServer) |
| 358 | { |
| 359 | iface->register_property("Collection", children); |
| 360 | iface->register_property("Status", std::string("Full")); |
| 361 | iface->register_property("AllowedFailures", static_cast<uint8_t>(count)); |
| 362 | iface->initialize(); |
| 363 | } |
| 364 | RedundancySensor::~RedundancySensor() |
| 365 | { |
| 366 | objectServer.remove_interface(iface); |
| 367 | } |
| 368 | void RedundancySensor::update(const std::string &name, bool failed) |
| 369 | { |
| 370 | statuses[name] = failed; |
| 371 | size_t failedCount = 0; |
| 372 | |
| 373 | std::string state = "Full"; |
| 374 | for (const auto &status : statuses) |
| 375 | { |
| 376 | if (status.second) |
| 377 | { |
| 378 | failedCount++; |
| 379 | } |
| 380 | if (failedCount > count) |
| 381 | { |
| 382 | state = "Failed"; |
| 383 | break; |
| 384 | } |
| 385 | else if (failedCount) |
| 386 | { |
| 387 | state = "Degraded"; |
| 388 | } |
| 389 | } |
| 390 | iface->set_property("Status", state); |
| 391 | } |