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 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 17 | #include <HwmonTempSensor.hpp> |
| 18 | #include <Utils.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 19 | #include <boost/algorithm/string/predicate.hpp> |
| 20 | #include <boost/algorithm/string/replace.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 21 | #include <boost/container/flat_map.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 22 | #include <boost/container/flat_set.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 23 | #include <sdbusplus/asio/connection.hpp> |
| 24 | #include <sdbusplus/asio/object_server.hpp> |
| 25 | #include <sdbusplus/bus/match.hpp> |
| 26 | |
| 27 | #include <array> |
James Feist | 24f02f2 | 2019-04-15 11:05:39 -0700 | [diff] [blame] | 28 | #include <filesystem> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 29 | #include <fstream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 30 | #include <functional> |
| 31 | #include <memory> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 32 | #include <regex> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 33 | #include <stdexcept> |
| 34 | #include <string> |
| 35 | #include <utility> |
| 36 | #include <variant> |
| 37 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 38 | |
Jeff Lin | 87bc67f | 2020-12-04 20:58:01 +0800 | [diff] [blame] | 39 | static constexpr float pollRateDefault = 0.5; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 40 | |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 41 | namespace fs = std::filesystem; |
Oskar Senft | 5770a6f | 2021-09-07 13:42:47 -0400 | [diff] [blame] | 42 | static constexpr std::array<const char*, 17> sensorTypes = { |
Gilbert Chen | 381636e | 2020-11-03 01:39:56 +0800 | [diff] [blame] | 43 | "xyz.openbmc_project.Configuration.EMC1412", |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 44 | "xyz.openbmc_project.Configuration.EMC1413", |
Gilbert Chen | 381636e | 2020-11-03 01:39:56 +0800 | [diff] [blame] | 45 | "xyz.openbmc_project.Configuration.EMC1414", |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 46 | "xyz.openbmc_project.Configuration.MAX31725", |
| 47 | "xyz.openbmc_project.Configuration.MAX31730", |
Jason Ling | 16e7af1 | 2020-06-05 17:41:01 -0700 | [diff] [blame] | 48 | "xyz.openbmc_project.Configuration.MAX6581", |
Josh Lehan | 3840d0a | 2020-05-13 16:13:45 -0700 | [diff] [blame] | 49 | "xyz.openbmc_project.Configuration.MAX6654", |
Oskar Senft | 5770a6f | 2021-09-07 13:42:47 -0400 | [diff] [blame] | 50 | "xyz.openbmc_project.Configuration.NCT7802", |
Josh Lehan | 8fb0a01 | 2020-06-26 19:28:16 -0700 | [diff] [blame] | 51 | "xyz.openbmc_project.Configuration.SBTSI", |
Konstantin Aladyshev | 5a3b3f8 | 2021-04-01 17:27:48 +0300 | [diff] [blame] | 52 | "xyz.openbmc_project.Configuration.LM95234", |
John Wang | 55ab2af | 2019-04-18 14:22:31 +0800 | [diff] [blame] | 53 | "xyz.openbmc_project.Configuration.TMP112", |
Patrick Venture | 3546adb | 2019-08-14 18:35:29 -0700 | [diff] [blame] | 54 | "xyz.openbmc_project.Configuration.TMP175", |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 55 | "xyz.openbmc_project.Configuration.TMP421", |
| 56 | "xyz.openbmc_project.Configuration.TMP441", |
Konstantin Aladyshev | 34fc75a | 2021-04-01 17:19:17 +0300 | [diff] [blame] | 57 | "xyz.openbmc_project.Configuration.LM75A", |
Zev Weiss | 7ea918f | 2021-03-24 22:46:02 +0000 | [diff] [blame] | 58 | "xyz.openbmc_project.Configuration.TMP75", |
| 59 | "xyz.openbmc_project.Configuration.W83773G"}; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 60 | |
| 61 | void createSensors( |
| 62 | boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer, |
Yong Li | f3fd191 | 2020-03-25 21:35:23 +0800 | [diff] [blame] | 63 | boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>& |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 64 | sensors, |
| 65 | std::shared_ptr<sdbusplus::asio::connection>& dbusConnection, |
James Feist | 5591cf08 | 2020-07-15 16:44:54 -0700 | [diff] [blame] | 66 | const std::shared_ptr<boost::container::flat_set<std::string>>& |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 67 | sensorsChanged) |
| 68 | { |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 69 | auto getter = std::make_shared<GetSensorConfiguration>( |
| 70 | dbusConnection, |
Ed Tanous | 8a17c30 | 2021-09-02 15:07:11 -0700 | [diff] [blame] | 71 | [&io, &objectServer, &sensors, &dbusConnection, |
| 72 | sensorsChanged](const ManagedObjectType& sensorConfigurations) { |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 73 | bool firstScan = sensorsChanged == nullptr; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 74 | |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 75 | std::vector<fs::path> paths; |
| 76 | if (!findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", |
| 77 | paths)) |
James Feist | 37266ca | 2018-10-15 15:56:28 -0700 | [diff] [blame] | 78 | { |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 79 | std::cerr << "No temperature sensors in system\n"; |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | boost::container::flat_set<std::string> directories; |
| 84 | |
| 85 | // iterate through all found temp sensors, and try to match them |
| 86 | // with configuration |
| 87 | for (auto& path : paths) |
| 88 | { |
| 89 | std::smatch match; |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 90 | auto directory = path.parent_path(); |
| 91 | |
| 92 | auto ret = directories.insert(directory.string()); |
| 93 | if (!ret.second) |
James Feist | 37266ca | 2018-10-15 15:56:28 -0700 | [diff] [blame] | 94 | { |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 95 | continue; // already searched this path |
| 96 | } |
| 97 | |
| 98 | fs::path device = directory / "device"; |
| 99 | std::string deviceName = fs::canonical(device).stem(); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 100 | auto findHyphen = deviceName.find('-'); |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 101 | if (findHyphen == std::string::npos) |
| 102 | { |
| 103 | std::cerr << "found bad device " << deviceName << "\n"; |
| 104 | continue; |
| 105 | } |
| 106 | std::string busStr = deviceName.substr(0, findHyphen); |
| 107 | std::string addrStr = deviceName.substr(findHyphen + 1); |
| 108 | |
| 109 | size_t bus = 0; |
| 110 | size_t addr = 0; |
| 111 | try |
| 112 | { |
| 113 | bus = std::stoi(busStr); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 114 | addr = std::stoi(addrStr, nullptr, 16); |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 115 | } |
| 116 | catch (std::invalid_argument&) |
| 117 | { |
| 118 | continue; |
| 119 | } |
| 120 | const SensorData* sensorData = nullptr; |
| 121 | const std::string* interfacePath = nullptr; |
| 122 | const char* sensorType = nullptr; |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 123 | const SensorBaseConfiguration* baseConfiguration = nullptr; |
| 124 | const SensorBaseConfigMap* baseConfigMap = nullptr; |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 125 | |
| 126 | for (const std::pair<sdbusplus::message::object_path, |
| 127 | SensorData>& sensor : sensorConfigurations) |
| 128 | { |
| 129 | sensorData = &(sensor.second); |
| 130 | for (const char* type : sensorTypes) |
| 131 | { |
| 132 | auto sensorBase = sensorData->find(type); |
| 133 | if (sensorBase != sensorData->end()) |
| 134 | { |
| 135 | baseConfiguration = &(*sensorBase); |
| 136 | sensorType = type; |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | if (baseConfiguration == nullptr) |
| 141 | { |
| 142 | std::cerr << "error finding base configuration for " |
| 143 | << deviceName << "\n"; |
| 144 | continue; |
| 145 | } |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 146 | baseConfigMap = &baseConfiguration->second; |
| 147 | auto configurationBus = baseConfigMap->find("Bus"); |
| 148 | auto configurationAddress = baseConfigMap->find("Address"); |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 149 | |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 150 | if (configurationBus == baseConfigMap->end() || |
| 151 | configurationAddress == baseConfigMap->end()) |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 152 | { |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 153 | std::cerr << "error finding bus or address in " |
| 154 | "configuration\n"; |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 155 | continue; |
| 156 | } |
| 157 | |
| 158 | if (std::get<uint64_t>(configurationBus->second) != bus || |
| 159 | std::get<uint64_t>(configurationAddress->second) != |
| 160 | addr) |
| 161 | { |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | interfacePath = &(sensor.first.str); |
James Feist | 37266ca | 2018-10-15 15:56:28 -0700 | [diff] [blame] | 166 | break; |
| 167 | } |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 168 | if (interfacePath == nullptr) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 169 | { |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 170 | std::cerr << "failed to find match for " << deviceName |
| 171 | << "\n"; |
| 172 | continue; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 173 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 174 | |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 175 | auto findSensorName = baseConfigMap->find("Name"); |
| 176 | if (findSensorName == baseConfigMap->end()) |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 177 | { |
| 178 | std::cerr << "could not determine configuration name for " |
| 179 | << deviceName << "\n"; |
| 180 | continue; |
| 181 | } |
| 182 | std::string sensorName = |
| 183 | std::get<std::string>(findSensorName->second); |
| 184 | // on rescans, only update sensors we were signaled by |
| 185 | auto findSensor = sensors.find(sensorName); |
| 186 | if (!firstScan && findSensor != sensors.end()) |
| 187 | { |
| 188 | bool found = false; |
Bruce Mitchell | d653b75 | 2021-08-23 13:09:00 -0500 | [diff] [blame] | 189 | auto it = sensorsChanged->begin(); |
| 190 | while (it != sensorsChanged->end()) |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 191 | { |
| 192 | if (boost::ends_with(*it, findSensor->second->name)) |
| 193 | { |
Bruce Mitchell | d653b75 | 2021-08-23 13:09:00 -0500 | [diff] [blame] | 194 | it = sensorsChanged->erase(it); |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 195 | findSensor->second = nullptr; |
| 196 | found = true; |
| 197 | break; |
| 198 | } |
Bruce Mitchell | d653b75 | 2021-08-23 13:09:00 -0500 | [diff] [blame] | 199 | ++it; |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 200 | } |
| 201 | if (!found) |
| 202 | { |
| 203 | continue; |
| 204 | } |
| 205 | } |
Matt Spinler | 5636d52 | 2021-03-17 14:52:18 -0500 | [diff] [blame] | 206 | |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 207 | std::vector<thresholds::Threshold> sensorThresholds; |
Matt Spinler | 5636d52 | 2021-03-17 14:52:18 -0500 | [diff] [blame] | 208 | int index = 1; |
| 209 | |
| 210 | if (!parseThresholdsFromConfig(*sensorData, sensorThresholds, |
| 211 | nullptr, &index)) |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 212 | { |
| 213 | std::cerr << "error populating thresholds for " |
Matt Spinler | 5636d52 | 2021-03-17 14:52:18 -0500 | [diff] [blame] | 214 | << sensorName << " index 1\n"; |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 215 | } |
Jeff Lin | 87bc67f | 2020-12-04 20:58:01 +0800 | [diff] [blame] | 216 | |
| 217 | auto findPollRate = baseConfiguration->second.find("PollRate"); |
| 218 | float pollRate = pollRateDefault; |
| 219 | if (findPollRate != baseConfiguration->second.end()) |
| 220 | { |
| 221 | pollRate = std::visit(VariantToFloatVisitor(), |
| 222 | findPollRate->second); |
| 223 | if (pollRate <= 0.0f) |
| 224 | { |
| 225 | pollRate = pollRateDefault; // polling time too short |
| 226 | } |
| 227 | } |
| 228 | |
James Feist | f9b01b6 | 2020-01-29 15:21:58 -0800 | [diff] [blame] | 229 | auto findPowerOn = baseConfiguration->second.find("PowerState"); |
| 230 | PowerState readState = PowerState::always; |
| 231 | if (findPowerOn != baseConfiguration->second.end()) |
| 232 | { |
| 233 | std::string powerState = std::visit( |
| 234 | VariantToStringVisitor(), findPowerOn->second); |
| 235 | setReadState(powerState, readState); |
| 236 | } |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 237 | |
| 238 | auto permitSet = getPermitSet(*baseConfigMap); |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 239 | auto& sensor = sensors[sensorName]; |
| 240 | sensor = nullptr; |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 241 | auto hwmonFile = getFullHwmonFilePath(directory.string(), |
| 242 | "temp1", permitSet); |
| 243 | if (hwmonFile) |
| 244 | { |
| 245 | sensor = std::make_shared<HwmonTempSensor>( |
| 246 | *hwmonFile, sensorType, objectServer, dbusConnection, |
Jeff Lin | 87bc67f | 2020-12-04 20:58:01 +0800 | [diff] [blame] | 247 | io, sensorName, std::move(sensorThresholds), pollRate, |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 248 | *interfacePath, readState); |
| 249 | sensor->setupRead(); |
| 250 | } |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 251 | // Looking for keys like "Name1" for temp2_input, |
| 252 | // "Name2" for temp3_input, etc. |
| 253 | int i = 0; |
| 254 | while (true) |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 255 | { |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 256 | ++i; |
| 257 | auto findKey = |
Jason Ling | 8b8bcc8 | 2020-08-04 19:33:22 -0700 | [diff] [blame] | 258 | baseConfigMap->find("Name" + std::to_string(i)); |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 259 | if (findKey == baseConfigMap->end()) |
| 260 | { |
| 261 | break; |
| 262 | } |
Alex Qiu | 8b3f7d4 | 2020-01-06 13:54:42 -0800 | [diff] [blame] | 263 | std::string sensorName = |
| 264 | std::get<std::string>(findKey->second); |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 265 | hwmonFile = getFullHwmonFilePath( |
| 266 | directory.string(), "temp" + std::to_string(i + 1), |
| 267 | permitSet); |
| 268 | if (hwmonFile) |
| 269 | { |
Matt Spinler | 5636d52 | 2021-03-17 14:52:18 -0500 | [diff] [blame] | 270 | // To look up thresholds for these additional sensors, |
| 271 | // match on the Index property in the threshold data |
| 272 | // where the index comes from the sysfs file we're on, |
| 273 | // i.e. index = 2 for temp2_input. |
| 274 | int index = i + 1; |
| 275 | std::vector<thresholds::Threshold> thresholds; |
| 276 | |
| 277 | if (!parseThresholdsFromConfig(*sensorData, thresholds, |
| 278 | nullptr, &index)) |
| 279 | { |
| 280 | std::cerr << "error populating thresholds for " |
| 281 | << sensorName << " index " << index |
| 282 | << "\n"; |
| 283 | } |
| 284 | |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 285 | auto& sensor = sensors[sensorName]; |
| 286 | sensor = nullptr; |
| 287 | sensor = std::make_shared<HwmonTempSensor>( |
| 288 | *hwmonFile, sensorType, objectServer, |
| 289 | dbusConnection, io, sensorName, |
Matt Spinler | 5636d52 | 2021-03-17 14:52:18 -0500 | [diff] [blame] | 290 | std::move(thresholds), pollRate, *interfacePath, |
| 291 | readState); |
Jason Ling | 100c20b | 2020-08-11 14:50:33 -0700 | [diff] [blame] | 292 | sensor->setupRead(); |
| 293 | } |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 294 | } |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 295 | } |
Ed Tanous | 8a17c30 | 2021-09-02 15:07:11 -0700 | [diff] [blame] | 296 | }); |
James Feist | df51515 | 2019-09-18 16:40:40 -0700 | [diff] [blame] | 297 | getter->getConfiguration( |
| 298 | std::vector<std::string>(sensorTypes.begin(), sensorTypes.end())); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 299 | } |
| 300 | |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 301 | int main() |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 302 | { |
| 303 | boost::asio::io_service io; |
| 304 | auto systemBus = std::make_shared<sdbusplus::asio::connection>(io); |
| 305 | systemBus->request_name("xyz.openbmc_project.HwmonTempSensor"); |
| 306 | sdbusplus::asio::object_server objectServer(systemBus); |
Yong Li | f3fd191 | 2020-03-25 21:35:23 +0800 | [diff] [blame] | 307 | boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 308 | sensors; |
| 309 | std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches; |
James Feist | 5591cf08 | 2020-07-15 16:44:54 -0700 | [diff] [blame] | 310 | auto sensorsChanged = |
| 311 | std::make_shared<boost::container::flat_set<std::string>>(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 312 | |
| 313 | io.post([&]() { |
| 314 | createSensors(io, objectServer, sensors, systemBus, nullptr); |
| 315 | }); |
| 316 | |
| 317 | boost::asio::deadline_timer filterTimer(io); |
| 318 | std::function<void(sdbusplus::message::message&)> eventHandler = |
| 319 | [&](sdbusplus::message::message& message) { |
| 320 | if (message.is_method_error()) |
| 321 | { |
| 322 | std::cerr << "callback method error\n"; |
| 323 | return; |
| 324 | } |
| 325 | sensorsChanged->insert(message.get_path()); |
| 326 | // this implicitly cancels the timer |
| 327 | filterTimer.expires_from_now(boost::posix_time::seconds(1)); |
| 328 | |
| 329 | filterTimer.async_wait([&](const boost::system::error_code& ec) { |
| 330 | if (ec == boost::asio::error::operation_aborted) |
| 331 | { |
| 332 | /* we were canceled*/ |
| 333 | return; |
| 334 | } |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 335 | if (ec) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 336 | { |
| 337 | std::cerr << "timer error\n"; |
| 338 | return; |
| 339 | } |
| 340 | createSensors(io, objectServer, sensors, systemBus, |
| 341 | sensorsChanged); |
| 342 | }); |
| 343 | }; |
| 344 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 345 | for (const char* type : sensorTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 346 | { |
| 347 | auto match = std::make_unique<sdbusplus::bus::match::match>( |
| 348 | static_cast<sdbusplus::bus::bus&>(*systemBus), |
| 349 | "type='signal',member='PropertiesChanged',path_namespace='" + |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 350 | std::string(inventoryPath) + "',arg0namespace='" + type + "'", |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 351 | eventHandler); |
| 352 | matches.emplace_back(std::move(match)); |
| 353 | } |
| 354 | |
Bruce Lee | 1263c3d | 2021-06-04 15:16:33 +0800 | [diff] [blame] | 355 | setupManufacturingModeMatch(*systemBus); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 356 | io.run(); |
| 357 | } |