James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2017 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 | |
Patrick Venture | ca44b2f | 2019-10-31 11:02:26 -0700 | [diff] [blame^] | 17 | #include "PwmSensor.hpp" |
| 18 | #include "TachSensor.hpp" |
| 19 | #include "Utils.hpp" |
| 20 | #include "VariantVisitors.hpp" |
| 21 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 22 | #include <boost/algorithm/string/predicate.hpp> |
| 23 | #include <boost/algorithm/string/replace.hpp> |
| 24 | #include <boost/container/flat_set.hpp> |
| 25 | #include <boost/lexical_cast.hpp> |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 26 | #include <filesystem> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 27 | #include <fstream> |
| 28 | #include <regex> |
| 29 | #include <sdbusplus/asio/connection.hpp> |
| 30 | #include <sdbusplus/asio/object_server.hpp> |
| 31 | |
| 32 | static constexpr bool DEBUG = false; |
| 33 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 34 | namespace fs = std::filesystem; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 35 | |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 36 | static constexpr std::array<const char*, 3> sensorTypes = { |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 37 | "xyz.openbmc_project.Configuration.AspeedFan", |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 38 | "xyz.openbmc_project.Configuration.I2CFan", |
| 39 | "xyz.openbmc_project.Configuration.NuvotonFan"}; |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 40 | constexpr const char* redundancyConfiguration = |
| 41 | "xyz.openbmc_project.Configuration.FanRedundancy"; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 42 | static std::regex inputRegex(R"(fan(\d+)_input)"); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 43 | |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 44 | enum class FanTypes |
| 45 | { |
| 46 | aspeed, |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 47 | i2c, |
| 48 | nuvoton |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 51 | // todo: power supply fan redundancy |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 52 | std::optional<RedundancySensor> systemRedundancy; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 53 | |
| 54 | FanTypes getFanType(const fs::path& parentPath) |
| 55 | { |
| 56 | fs::path linkPath = parentPath / "device"; |
| 57 | std::string canonical = fs::read_symlink(linkPath); |
| 58 | if (boost::ends_with(canonical, "1e786000.pwm-tacho-controller")) |
| 59 | { |
| 60 | return FanTypes::aspeed; |
| 61 | } |
Peter Lundgren | 8843b62 | 2019-09-12 10:33:41 -0700 | [diff] [blame] | 62 | else if (boost::ends_with(canonical, "f0103000.pwm-fan-controller")) |
| 63 | { |
| 64 | return FanTypes::nuvoton; |
| 65 | } |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 66 | // todo: will we need to support other types? |
| 67 | return FanTypes::i2c; |
| 68 | } |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 69 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 70 | void createSensors( |
| 71 | boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, |
| 72 | boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>& |
| 73 | tachSensors, |
| 74 | boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>& |
| 75 | pwmSensors, |
| 76 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
| 77 | const std::unique_ptr<boost::container::flat_set<std::string>>& |
| 78 | sensorsChanged) |
| 79 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 80 | |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 81 | auto getter = std::make_shared<GetSensorConfiguration>( |
| 82 | dbusConnection, |
| 83 | std::move([&io, &objectServer, &tachSensors, &pwmSensors, |
| 84 | &dbusConnection, &sensorsChanged]( |
| 85 | const ManagedObjectType& sensorConfigurations) { |
| 86 | bool firstScan = sensorsChanged == nullptr; |
| 87 | std::vector<fs::path> paths; |
| 88 | if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", |
| 89 | paths)) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 90 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 91 | std::cerr << "No temperature sensors in system\n"; |
| 92 | return; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 93 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 94 | |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 95 | std::vector<std::pair<uint8_t, std::string>> pwmNumbers; |
| 96 | |
| 97 | // iterate through all found fan sensors, and try to match them with |
| 98 | // configuration |
| 99 | for (const auto& path : paths) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 100 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 101 | std::smatch match; |
| 102 | std::string pathStr = path.string(); |
| 103 | |
| 104 | std::regex_search(pathStr, match, inputRegex); |
| 105 | std::string indexStr = *(match.begin() + 1); |
| 106 | |
| 107 | auto directory = path.parent_path(); |
| 108 | FanTypes fanType = getFanType(directory); |
| 109 | size_t bus = 0; |
| 110 | size_t address = 0; |
| 111 | if (fanType == FanTypes::i2c) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 112 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 113 | std::string link = |
| 114 | fs::read_symlink(directory / "device").filename(); |
| 115 | |
| 116 | size_t findDash = link.find("-"); |
| 117 | if (findDash == std::string::npos || |
| 118 | link.size() <= findDash + 1) |
| 119 | { |
| 120 | std::cerr << "Error finding device from symlink"; |
| 121 | } |
| 122 | bus = std::stoi(link.substr(0, findDash)); |
| 123 | address = std::stoi(link.substr(findDash + 1), nullptr, 16); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 124 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 125 | // convert to 0 based |
| 126 | size_t index = std::stoul(indexStr) - 1; |
| 127 | |
| 128 | const char* baseType; |
| 129 | const SensorData* sensorData = nullptr; |
| 130 | const std::string* interfacePath = nullptr; |
| 131 | const SensorBaseConfiguration* baseConfiguration = nullptr; |
| 132 | for (const std::pair<sdbusplus::message::object_path, |
| 133 | SensorData>& sensor : sensorConfigurations) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 134 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 135 | // find the base of the configuration to see if indexes |
| 136 | // match |
| 137 | for (const char* type : sensorTypes) |
| 138 | { |
| 139 | auto sensorBaseFind = sensor.second.find(type); |
| 140 | if (sensorBaseFind != sensor.second.end()) |
| 141 | { |
| 142 | baseConfiguration = &(*sensorBaseFind); |
| 143 | interfacePath = &(sensor.first.str); |
| 144 | baseType = type; |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | if (baseConfiguration == nullptr) |
| 149 | { |
| 150 | continue; |
| 151 | } |
| 152 | auto findIndex = baseConfiguration->second.find("Index"); |
| 153 | if (findIndex == baseConfiguration->second.end()) |
| 154 | { |
| 155 | std::cerr << baseConfiguration->first |
| 156 | << " missing index\n"; |
| 157 | continue; |
| 158 | } |
| 159 | unsigned int configIndex = std::visit( |
| 160 | VariantToUnsignedIntVisitor(), findIndex->second); |
| 161 | if (configIndex != index) |
| 162 | { |
| 163 | continue; |
| 164 | } |
| 165 | if (fanType == FanTypes::aspeed || |
| 166 | fanType == FanTypes::nuvoton) |
| 167 | { |
| 168 | // there will be only 1 aspeed or nuvoton sensor object |
| 169 | // in sysfs, we found the fan |
| 170 | sensorData = &(sensor.second); |
| 171 | break; |
| 172 | } |
| 173 | else if (baseType == |
| 174 | std::string( |
| 175 | "xyz.openbmc_project.Configuration.I2CFan")) |
| 176 | { |
| 177 | auto findBus = baseConfiguration->second.find("Bus"); |
| 178 | auto findAddress = |
| 179 | baseConfiguration->second.find("Address"); |
| 180 | if (findBus == baseConfiguration->second.end() || |
| 181 | findAddress == baseConfiguration->second.end()) |
| 182 | { |
| 183 | std::cerr << baseConfiguration->first |
| 184 | << " missing bus or address\n"; |
| 185 | continue; |
| 186 | } |
| 187 | unsigned int configBus = std::visit( |
| 188 | VariantToUnsignedIntVisitor(), findBus->second); |
| 189 | unsigned int configAddress = std::visit( |
| 190 | VariantToUnsignedIntVisitor(), findAddress->second); |
| 191 | |
| 192 | if (configBus == bus && configAddress == address) |
| 193 | { |
| 194 | sensorData = &(sensor.second); |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | if (sensorData == nullptr) |
| 200 | { |
| 201 | std::cerr << "failed to find match for " << path.string() |
| 202 | << "\n"; |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 203 | continue; |
| 204 | } |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 205 | |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 206 | auto findSensorName = baseConfiguration->second.find("Name"); |
| 207 | if (findSensorName == baseConfiguration->second.end()) |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 208 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 209 | std::cerr << "could not determine configuration name for " |
| 210 | << path.string() << "\n"; |
| 211 | continue; |
| 212 | } |
| 213 | std::string sensorName = |
| 214 | std::get<std::string>(findSensorName->second); |
| 215 | // on rescans, only update sensors we were signaled by |
| 216 | auto findSensor = tachSensors.find(sensorName); |
| 217 | if (!firstScan && findSensor != tachSensors.end()) |
| 218 | { |
| 219 | bool found = false; |
| 220 | for (auto it = sensorsChanged->begin(); |
| 221 | it != sensorsChanged->end(); it++) |
| 222 | { |
| 223 | if (boost::ends_with(*it, findSensor->second->name)) |
| 224 | { |
| 225 | sensorsChanged->erase(it); |
| 226 | findSensor->second = nullptr; |
| 227 | found = true; |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | if (!found) |
| 232 | { |
| 233 | continue; |
| 234 | } |
| 235 | } |
| 236 | std::vector<thresholds::Threshold> sensorThresholds; |
| 237 | if (!parseThresholdsFromConfig(*sensorData, sensorThresholds)) |
| 238 | { |
| 239 | std::cerr << "error populating thresholds for " |
| 240 | << sensorName << "\n"; |
| 241 | } |
| 242 | |
| 243 | auto presenceConfig = |
| 244 | sensorData->find(baseType + std::string(".Presence")); |
| 245 | |
| 246 | std::unique_ptr<PresenceSensor> presenceSensor(nullptr); |
| 247 | |
| 248 | // presence sensors are optional |
| 249 | if (presenceConfig != sensorData->end()) |
| 250 | { |
| 251 | auto findIndex = presenceConfig->second.find("Index"); |
| 252 | auto findPolarity = presenceConfig->second.find("Polarity"); |
| 253 | |
| 254 | if (findIndex == presenceConfig->second.end() || |
| 255 | findPolarity == presenceConfig->second.end()) |
| 256 | { |
| 257 | std::cerr << "Malformed Presence Configuration\n"; |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | size_t index = std::get<uint64_t>(findIndex->second); |
| 262 | bool inverted = std::get<std::string>( |
| 263 | findPolarity->second) == "Low"; |
| 264 | presenceSensor = std::make_unique<PresenceSensor>( |
| 265 | index, inverted, io, sensorName); |
| 266 | } |
| 267 | } |
| 268 | std::optional<RedundancySensor>* redundancy = nullptr; |
| 269 | if (fanType == FanTypes::aspeed) |
| 270 | { |
| 271 | redundancy = &systemRedundancy; |
| 272 | } |
| 273 | |
| 274 | constexpr double defaultMaxReading = 25000; |
| 275 | constexpr double defaultMinReading = 0; |
| 276 | auto limits = |
| 277 | std::make_pair(defaultMinReading, defaultMaxReading); |
| 278 | |
| 279 | findLimits(limits, baseConfiguration); |
| 280 | tachSensors[sensorName] = std::make_unique<TachSensor>( |
| 281 | path.string(), baseType, objectServer, dbusConnection, |
| 282 | std::move(presenceSensor), redundancy, io, sensorName, |
| 283 | std::move(sensorThresholds), *interfacePath, limits); |
| 284 | |
| 285 | auto connector = |
| 286 | sensorData->find(baseType + std::string(".Connector")); |
| 287 | if (connector != sensorData->end()) |
| 288 | { |
| 289 | auto findPwm = connector->second.find("Pwm"); |
| 290 | if (findPwm == connector->second.end()) |
| 291 | { |
| 292 | std::cerr << "Connector Missing PWM!\n"; |
| 293 | continue; |
| 294 | } |
| 295 | |
| 296 | size_t pwm = std::visit(VariantToUnsignedIntVisitor(), |
| 297 | findPwm->second); |
| 298 | pwmNumbers.emplace_back(pwm, *interfacePath); |
James Feist | 95b079b | 2018-11-21 09:28:00 -0800 | [diff] [blame] | 299 | } |
| 300 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 301 | std::vector<fs::path> pwms; |
| 302 | if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+$)", pwms)) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 303 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 304 | std::cerr << "No pwm in system\n"; |
| 305 | return; |
| 306 | } |
| 307 | for (const fs::path& pwm : pwms) |
| 308 | { |
| 309 | if (pwmSensors.find(pwm) != pwmSensors.end()) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 310 | { |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 311 | continue; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 312 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 313 | const std::string* path = nullptr; |
| 314 | for (const auto& [index, configPath] : pwmNumbers) |
| 315 | { |
| 316 | if (boost::ends_with(pwm.string(), |
| 317 | std::to_string(index + 1))) |
| 318 | { |
| 319 | path = &configPath; |
| 320 | break; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | if (path == nullptr) |
| 325 | { |
| 326 | continue; |
| 327 | } |
| 328 | |
| 329 | // only add new elements |
| 330 | const std::string& sysPath = pwm.string(); |
| 331 | const std::string& pwmName = |
| 332 | "Pwm_" + sysPath.substr(sysPath.find_last_of("pwm") + 1); |
| 333 | pwmSensors.insert( |
| 334 | std::pair<std::string, std::unique_ptr<PwmSensor>>( |
| 335 | sysPath, std::make_unique<PwmSensor>( |
| 336 | pwmName, sysPath, objectServer, *path))); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 337 | } |
James Feist | de5e970 | 2019-09-18 16:13:02 -0700 | [diff] [blame] | 338 | })); |
| 339 | getter->getConfiguration( |
| 340 | std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()}); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 341 | } |
| 342 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 343 | void createRedundancySensor( |
| 344 | const boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>& |
| 345 | sensors, |
| 346 | std::shared_ptr<sdbusplus::asio::connection> conn, |
| 347 | sdbusplus::asio::object_server& objectServer) |
| 348 | { |
| 349 | |
| 350 | conn->async_method_call( |
| 351 | [&objectServer, &sensors](boost::system::error_code& ec, |
| 352 | const ManagedObjectType managedObj) { |
| 353 | if (ec) |
| 354 | { |
| 355 | std::cerr << "Error calling entity manager \n"; |
| 356 | return; |
| 357 | } |
| 358 | for (const auto& pathPair : managedObj) |
| 359 | { |
| 360 | for (const auto& interfacePair : pathPair.second) |
| 361 | { |
| 362 | if (interfacePair.first == redundancyConfiguration) |
| 363 | { |
| 364 | // currently only support one |
| 365 | auto findCount = |
| 366 | interfacePair.second.find("AllowedFailures"); |
| 367 | if (findCount == interfacePair.second.end()) |
| 368 | { |
| 369 | std::cerr << "Malformed redundancy record \n"; |
| 370 | return; |
| 371 | } |
| 372 | std::vector<std::string> sensorList; |
| 373 | |
| 374 | for (const auto& sensor : sensors) |
| 375 | { |
| 376 | sensorList.push_back( |
| 377 | "/xyz/openbmc_project/sensors/fan_tach/" + |
| 378 | sensor.second->name); |
| 379 | } |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 380 | systemRedundancy.reset(); |
| 381 | systemRedundancy.emplace(RedundancySensor( |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 382 | std::get<uint64_t>(findCount->second), sensorList, |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 383 | objectServer, pathPair.first)); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 384 | |
| 385 | return; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | }, |
| 390 | "xyz.openbmc_project.EntityManager", "/", |
| 391 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
| 392 | } |
| 393 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 394 | int main() |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 395 | { |
| 396 | boost::asio::io_service io; |
| 397 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
| 398 | systemBus->request_name("xyz.openbmc_project.FanSensor"); |
| 399 | sdbusplus::asio::object_server objectServer(systemBus); |
| 400 | boost::container::flat_map<std::string, std::unique_ptr<TachSensor>> |
| 401 | tachSensors; |
| 402 | boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>> |
| 403 | pwmSensors; |
| 404 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches; |
| 405 | std::unique_ptr<boost::container::flat_set<std::string>> sensorsChanged = |
| 406 | std::make_unique<boost::container::flat_set<std::string>>(); |
| 407 | |
| 408 | io.post([&]() { |
| 409 | createSensors(io, objectServer, tachSensors, pwmSensors, systemBus, |
| 410 | nullptr); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 411 | createRedundancySensor(tachSensors, systemBus, objectServer); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 412 | }); |
| 413 | |
| 414 | boost::asio::deadline_timer filterTimer(io); |
| 415 | std::function<void(sdbusplus::message::message&)> eventHandler = |
| 416 | [&](sdbusplus::message::message& message) { |
| 417 | if (message.is_method_error()) |
| 418 | { |
| 419 | std::cerr << "callback method error\n"; |
| 420 | return; |
| 421 | } |
| 422 | sensorsChanged->insert(message.get_path()); |
| 423 | // this implicitly cancels the timer |
| 424 | filterTimer.expires_from_now(boost::posix_time::seconds(1)); |
| 425 | |
| 426 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 427 | if (ec == boost::asio::error::operation_aborted) |
| 428 | { |
| 429 | /* we were canceled*/ |
| 430 | return; |
| 431 | } |
| 432 | else if (ec) |
| 433 | { |
| 434 | std::cerr << "timer error\n"; |
| 435 | return; |
| 436 | } |
| 437 | createSensors(io, objectServer, tachSensors, pwmSensors, |
| 438 | systemBus, sensorsChanged); |
| 439 | }); |
| 440 | }; |
| 441 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 442 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 443 | { |
| 444 | auto match = std::make_unique<sdbusplus::bus::match::match>( |
| 445 | static_cast<sdbusplus::bus::bus&>(*systemBus), |
| 446 | "type='signal',member='PropertiesChanged',path_namespace='" + |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 447 | std::string(inventoryPath) + "',arg0namespace='" + type + "'", |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 448 | eventHandler); |
| 449 | matches.emplace_back(std::move(match)); |
| 450 | } |
| 451 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 452 | // redundancy sensor |
| 453 | std::function<void(sdbusplus::message::message&)> redundancyHandler = |
| 454 | [&tachSensors, &systemBus, |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 455 | &objectServer](sdbusplus::message::message&) { |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 456 | createRedundancySensor(tachSensors, systemBus, objectServer); |
| 457 | }; |
| 458 | auto match = std::make_unique<sdbusplus::bus::match::match>( |
| 459 | static_cast<sdbusplus::bus::bus&>(*systemBus), |
| 460 | "type='signal',member='PropertiesChanged',path_namespace='" + |
| 461 | std::string(inventoryPath) + "',arg0namespace='" + |
| 462 | redundancyConfiguration + "'", |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 463 | std::move(redundancyHandler)); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 464 | matches.emplace_back(std::move(match)); |
| 465 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 466 | io.run(); |
| 467 | } |