blob: 5a773b2d4976ee1bc6041d9970c0cce400f6bfd6 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001/*
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 Tanous8a57ec02020-10-09 12:46:52 -070017#include <HwmonTempSensor.hpp>
18#include <Utils.hpp>
James Feist6714a252018-09-10 15:26:18 -070019#include <boost/algorithm/string/replace.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070020#include <boost/container/flat_map.hpp>
James Feist6714a252018-09-10 15:26:18 -070021#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070022#include <sdbusplus/asio/connection.hpp>
23#include <sdbusplus/asio/object_server.hpp>
24#include <sdbusplus/bus/match.hpp>
25
26#include <array>
Jae Hyun Yoo7dd64432022-03-30 14:28:33 -070027#include <charconv>
James Feist24f02f22019-04-15 11:05:39 -070028#include <filesystem>
James Feist6714a252018-09-10 15:26:18 -070029#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070030#include <functional>
31#include <memory>
James Feist6714a252018-09-10 15:26:18 -070032#include <regex>
Patrick Venture96e97db2019-10-31 13:44:38 -070033#include <stdexcept>
34#include <string>
35#include <utility>
36#include <variant>
37#include <vector>
James Feist6714a252018-09-10 15:26:18 -070038
Jeff Lin87bc67f2020-12-04 20:58:01 +080039static constexpr float pollRateDefault = 0.5;
James Feist6714a252018-09-10 15:26:18 -070040
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050041static constexpr double maxValuePressure = 120000; // Pascals
42static constexpr double minValuePressure = 30000; // Pascals
43
Bruce Mitchell3ec41c52021-12-10 16:05:17 -060044static constexpr double maxValueRelativeHumidity = 100; // PercentRH
45static constexpr double minValueRelativeHumidity = 0; // PercentRH
46
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050047static constexpr double maxValueTemperature = 127; // DegreesC
48static constexpr double minValueTemperature = -128; // DegreesC
49
James Feistcf3bce62019-01-08 10:07:19 -080050namespace fs = std::filesystem;
Zev Weiss054aad82022-08-18 01:37:34 -070051static auto sensorTypes{std::to_array<const char*>(
52 {"DPS310", "EMC1412", "EMC1413", "EMC1414", "HDC1080", "JC42",
53 "LM75A", "LM95234", "MAX31725", "MAX31730", "MAX6581", "MAX6654",
54 "NCT7802", "NCT6779", "SBTSI", "SI7020", "TMP112", "TMP175",
55 "TMP421", "TMP441", "TMP75", "W83773G"})};
James Feist6714a252018-09-10 15:26:18 -070056
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050057static struct SensorParams
58 getSensorParameters(const std::filesystem::path& path)
59{
60 // offset is to default to 0 and scale to 1, see lore
61 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
62 struct SensorParams tmpSensorParameters = {.minValue = minValueTemperature,
63 .maxValue = maxValueTemperature,
64 .offsetValue = 0.0,
65 .scaleValue = 1.0,
Bruce Mitchell5a86e562021-12-10 12:26:22 -060066 .units =
67 sensor_paths::unitDegreesC,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050068 .typeName = "temperature"};
69
70 // For IIO RAW sensors we get a raw_value, an offset, and scale
71 // to compute the value = (raw_value + offset) * scale
72 // with a _raw IIO device we need to get the
73 // offsetValue and scaleValue from the driver
74 // these are used to compute the reading in
75 // units that have yet to be scaled for D-Bus.
76 const std::string pathStr = path.string();
77 if (pathStr.ends_with("_raw"))
78 {
79 std::string pathOffsetStr =
80 pathStr.substr(0, pathStr.size() - 4) + "_offset";
81 std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
82 // In case there is nothing to read skip this device
83 // This is not an error condition see lore
84 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
85 if (tmpOffsetValue)
86 {
87 tmpSensorParameters.offsetValue = *tmpOffsetValue;
88 }
89
90 std::string pathScaleStr =
91 pathStr.substr(0, pathStr.size() - 4) + "_scale";
92 std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
93 // In case there is nothing to read skip this device
94 // This is not an error condition see lore
95 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
96 if (tmpScaleValue)
97 {
98 tmpSensorParameters.scaleValue = *tmpScaleValue;
99 }
100 }
101
102 // Temperatures are read in milli degrees Celsius, we need
103 // degrees Celsius. Pressures are read in kilopascal, we need
104 // Pascals. On D-Bus for Open BMC we use the International
105 // System of Units without prefixes. Links to the kernel
106 // documentation:
107 // https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
108 // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
109 if (path.filename() == "in_pressure_input" ||
110 path.filename() == "in_pressure_raw")
111 {
112 tmpSensorParameters.minValue = minValuePressure;
113 tmpSensorParameters.maxValue = maxValuePressure;
114 // Pressures are read in kilopascal, we need Pascals.
115 tmpSensorParameters.scaleValue *= 1000.0;
116 tmpSensorParameters.typeName = "pressure";
Bruce Mitchell5a86e562021-12-10 12:26:22 -0600117 tmpSensorParameters.units = sensor_paths::unitPascals;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500118 }
Bruce Mitchell3ec41c52021-12-10 16:05:17 -0600119 else if (path.filename() == "in_humidityrelative_input" ||
120 path.filename() == "in_humidityrelative_raw")
121 {
122 tmpSensorParameters.minValue = minValueRelativeHumidity;
123 tmpSensorParameters.maxValue = maxValueRelativeHumidity;
124 // Relative Humidity are read in milli-percent, we need percent.
125 tmpSensorParameters.scaleValue *= 0.001;
126 tmpSensorParameters.typeName = "humidity";
127 tmpSensorParameters.units = "PercentRH";
128 }
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500129 else
130 {
131 // Temperatures are read in milli degrees Celsius,
132 // we need degrees Celsius.
133 tmpSensorParameters.scaleValue *= 0.001;
134 }
135
136 return tmpSensorParameters;
137}
138
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530139struct SensorConfigKey
140{
141 uint64_t bus;
142 uint64_t addr;
143 bool operator<(const SensorConfigKey& other) const
144 {
145 if (bus != other.bus)
146 {
147 return bus < other.bus;
148 }
149 return addr < other.addr;
150 }
151};
152
153struct SensorConfig
154{
155 std::string sensorPath;
156 SensorData sensorData;
157 std::string interface;
158 SensorBaseConfigMap config;
159 std::vector<std::string> name;
160};
161
162using SensorConfigMap =
163 boost::container::flat_map<SensorConfigKey, SensorConfig>;
164
165static SensorConfigMap
166 buildSensorConfigMap(const ManagedObjectType& sensorConfigs)
167{
168 SensorConfigMap configMap;
Zev Weissa1808332022-08-12 18:21:01 -0700169 for (const auto& [path, cfgData] : sensorConfigs)
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530170 {
Zev Weissa1808332022-08-12 18:21:01 -0700171 for (const auto& [intf, cfg] : cfgData)
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530172 {
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530173 auto busCfg = cfg.find("Bus");
174 auto addrCfg = cfg.find("Address");
175 if ((busCfg == cfg.end()) || (addrCfg == cfg.end()))
176 {
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530177 continue;
178 }
179
Ed Tanous2049bd22022-07-09 07:20:26 -0700180 if ((std::get_if<uint64_t>(&busCfg->second) == nullptr) ||
181 (std::get_if<uint64_t>(&addrCfg->second) == nullptr))
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530182 {
Zev Weissa1808332022-08-12 18:21:01 -0700183 std::cerr << path.str << " Bus or Address invalid\n";
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530184 continue;
185 }
186
187 std::vector<std::string> hwmonNames;
188 auto nameCfg = cfg.find("Name");
189 if (nameCfg != cfg.end())
190 {
191 hwmonNames.push_back(std::get<std::string>(nameCfg->second));
192 size_t i = 1;
193 while (true)
194 {
195 auto sensorNameCfg = cfg.find("Name" + std::to_string(i));
196 if (sensorNameCfg == cfg.end())
197 {
198 break;
199 }
200 hwmonNames.push_back(
201 std::get<std::string>(sensorNameCfg->second));
202 i++;
203 }
204 }
205
206 SensorConfigKey key = {std::get<uint64_t>(busCfg->second),
207 std::get<uint64_t>(addrCfg->second)};
Zev Weissa1808332022-08-12 18:21:01 -0700208 SensorConfig val = {path.str, cfgData, intf, cfg, hwmonNames};
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530209
210 auto [it, inserted] = configMap.emplace(key, std::move(val));
211 if (!inserted)
212 {
Zev Weissa1808332022-08-12 18:21:01 -0700213 std::cerr << path.str << ": ignoring duplicate entry for {"
214 << key.bus << ", 0x" << std::hex << key.addr
215 << std::dec << "}\n";
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530216 }
217 }
218 }
219 return configMap;
220}
221
James Feist6714a252018-09-10 15:26:18 -0700222void createSensors(
223 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
Yong Lif3fd1912020-03-25 21:35:23 +0800224 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
James Feist6714a252018-09-10 15:26:18 -0700225 sensors,
226 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
James Feist5591cf082020-07-15 16:44:54 -0700227 const std::shared_ptr<boost::container::flat_set<std::string>>&
James Feist6714a252018-09-10 15:26:18 -0700228 sensorsChanged)
229{
James Feistdf515152019-09-18 16:40:40 -0700230 auto getter = std::make_shared<GetSensorConfiguration>(
231 dbusConnection,
Ed Tanous8a17c302021-09-02 15:07:11 -0700232 [&io, &objectServer, &sensors, &dbusConnection,
233 sensorsChanged](const ManagedObjectType& sensorConfigurations) {
Ed Tanousbb679322022-05-16 16:10:00 -0700234 bool firstScan = sensorsChanged == nullptr;
James Feist6714a252018-09-10 15:26:18 -0700235
Ed Tanousbb679322022-05-16 16:10:00 -0700236 SensorConfigMap configMap = buildSensorConfigMap(sensorConfigurations);
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530237
Ed Tanousbb679322022-05-16 16:10:00 -0700238 // IIO _raw devices look like this on sysfs:
239 // /sys/bus/iio/devices/iio:device0/in_temp_raw
240 // /sys/bus/iio/devices/iio:device0/in_temp_offset
241 // /sys/bus/iio/devices/iio:device0/in_temp_scale
242 //
243 // Other IIO devices look like this on sysfs:
244 // /sys/bus/iio/devices/iio:device1/in_temp_input
245 // /sys/bus/iio/devices/iio:device1/in_pressure_input
246 std::vector<fs::path> paths;
247 fs::path root("/sys/bus/iio/devices");
248 findFiles(root, R"(in_temp\d*_(input|raw))", paths);
249 findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
250 findFiles(root, R"(in_humidityrelative\d*_(input|raw))", paths);
251 findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500252
Ed Tanousbb679322022-05-16 16:10:00 -0700253 if (paths.empty())
254 {
255 return;
256 }
257
258 // iterate through all found temp and pressure sensors,
259 // and try to match them with configuration
260 for (auto& path : paths)
261 {
262 std::smatch match;
263 const std::string pathStr = path.string();
264 auto directory = path.parent_path();
265 fs::path device;
266
267 std::string deviceName;
268 if (pathStr.starts_with("/sys/bus/iio/devices"))
James Feist37266ca2018-10-15 15:56:28 -0700269 {
Ed Tanousbb679322022-05-16 16:10:00 -0700270 device = fs::canonical(directory);
271 deviceName = device.parent_path().stem();
272 }
273 else
274 {
275 device = directory / "device";
276 deviceName = fs::canonical(device).stem();
277 }
278 auto findHyphen = deviceName.find('-');
279 if (findHyphen == std::string::npos)
280 {
281 std::cerr << "found bad device " << deviceName << "\n";
282 continue;
283 }
284 std::string busStr = deviceName.substr(0, findHyphen);
285 std::string addrStr = deviceName.substr(findHyphen + 1);
286
287 uint64_t bus = 0;
288 uint64_t addr = 0;
Ed Tanous2049bd22022-07-09 07:20:26 -0700289 std::from_chars_result res{};
Ed Tanousbb679322022-05-16 16:10:00 -0700290 res = std::from_chars(busStr.data(), busStr.data() + busStr.size(),
291 bus);
292 if (res.ec != std::errc{})
293 {
294 continue;
295 }
296 res = std::from_chars(addrStr.data(),
297 addrStr.data() + addrStr.size(), addr, 16);
298 if (res.ec != std::errc{})
299 {
300 continue;
James Feistdf515152019-09-18 16:40:40 -0700301 }
302
Ed Tanousbb679322022-05-16 16:10:00 -0700303 auto thisSensorParameters = getSensorParameters(path);
304 auto findSensorCfg = configMap.find({bus, addr});
305 if (findSensorCfg == configMap.end())
James Feistdf515152019-09-18 16:40:40 -0700306 {
Ed Tanousbb679322022-05-16 16:10:00 -0700307 continue;
308 }
James Feistdf515152019-09-18 16:40:40 -0700309
Ed Tanousbb679322022-05-16 16:10:00 -0700310 const std::string& interfacePath = findSensorCfg->second.sensorPath;
311 const SensorData& sensorData = findSensorCfg->second.sensorData;
312 const std::string& sensorType = findSensorCfg->second.interface;
313 const SensorBaseConfigMap& baseConfigMap =
314 findSensorCfg->second.config;
315 std::vector<std::string>& hwmonName = findSensorCfg->second.name;
316
317 // Temperature has "Name", pressure has "Name1"
318 auto findSensorName = baseConfigMap.find("Name");
319 int index = 1;
320 if (thisSensorParameters.typeName == "pressure" ||
321 thisSensorParameters.typeName == "humidity")
322 {
323 findSensorName = baseConfigMap.find("Name1");
324 index = 2;
325 }
326
327 if (findSensorName == baseConfigMap.end())
328 {
329 std::cerr << "could not determine configuration name for "
330 << deviceName << "\n";
331 continue;
332 }
333 std::string sensorName =
334 std::get<std::string>(findSensorName->second);
335 // on rescans, only update sensors we were signaled by
336 auto findSensor = sensors.find(sensorName);
337 if (!firstScan && findSensor != sensors.end())
338 {
339 bool found = false;
340 auto it = sensorsChanged->begin();
341 while (it != sensorsChanged->end())
342 {
Zev Weiss6c106d62022-08-17 20:50:00 -0700343 if (it->ends_with(findSensor->second->name))
Ed Tanousbb679322022-05-16 16:10:00 -0700344 {
345 it = sensorsChanged->erase(it);
346 findSensor->second = nullptr;
347 found = true;
348 break;
349 }
350 ++it;
351 }
352 if (!found)
353 {
354 continue;
355 }
356 }
357
358 std::vector<thresholds::Threshold> sensorThresholds;
359
360 if (!parseThresholdsFromConfig(sensorData, sensorThresholds,
361 nullptr, &index))
362 {
363 std::cerr << "error populating thresholds for " << sensorName
364 << " index " << index << "\n";
365 }
366
367 auto findPollRate = baseConfigMap.find("PollRate");
368 float pollRate = pollRateDefault;
369 if (findPollRate != baseConfigMap.end())
370 {
371 pollRate =
372 std::visit(VariantToFloatVisitor(), findPollRate->second);
Ed Tanous2049bd22022-07-09 07:20:26 -0700373 if (pollRate <= 0.0F)
Ed Tanousbb679322022-05-16 16:10:00 -0700374 {
375 pollRate = pollRateDefault; // polling time too short
376 }
377 }
378
Zev Weissa4d27682022-07-19 15:30:36 -0700379 PowerState readState = getPowerState(baseConfigMap);
Ed Tanousbb679322022-05-16 16:10:00 -0700380
381 auto permitSet = getPermitSet(baseConfigMap);
382 auto& sensor = sensors[sensorName];
383 sensor = nullptr;
384 auto hwmonFile =
385 getFullHwmonFilePath(directory.string(), "temp1", permitSet);
386 if (pathStr.starts_with("/sys/bus/iio/devices"))
387 {
388 hwmonFile = pathStr;
389 }
390 if (hwmonFile)
391 {
392 sensor = std::make_shared<HwmonTempSensor>(
393 *hwmonFile, sensorType, objectServer, dbusConnection, io,
394 sensorName, std::move(sensorThresholds),
395 thisSensorParameters, pollRate, interfacePath, readState);
396 sensor->setupRead();
397 }
398 hwmonName.erase(
399 remove(hwmonName.begin(), hwmonName.end(), sensorName),
400 hwmonName.end());
401
402 // Looking for keys like "Name1" for temp2_input,
403 // "Name2" for temp3_input, etc.
404 int i = 0;
405 while (true)
406 {
407 ++i;
408 auto findKey = baseConfigMap.find("Name" + std::to_string(i));
409 if (findKey == baseConfigMap.end())
410 {
411 break;
412 }
413 std::string sensorName = std::get<std::string>(findKey->second);
414 hwmonFile = getFullHwmonFilePath(directory.string(),
415 "temp" + std::to_string(i + 1),
416 permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500417 if (pathStr.starts_with("/sys/bus/iio/devices"))
James Feist37266ca2018-10-15 15:56:28 -0700418 {
James Feistdf515152019-09-18 16:40:40 -0700419 continue;
420 }
Jason Ling100c20b2020-08-11 14:50:33 -0700421 if (hwmonFile)
422 {
Ed Tanousbb679322022-05-16 16:10:00 -0700423 // To look up thresholds for these additional sensors,
424 // match on the Index property in the threshold data
425 // where the index comes from the sysfs file we're on,
426 // i.e. index = 2 for temp2_input.
427 int index = i + 1;
428 std::vector<thresholds::Threshold> thresholds;
429
430 if (!parseThresholdsFromConfig(sensorData, thresholds,
431 nullptr, &index))
432 {
433 std::cerr << "error populating thresholds for "
434 << sensorName << " index " << index << "\n";
435 }
436
437 auto& sensor = sensors[sensorName];
438 sensor = nullptr;
Jason Ling100c20b2020-08-11 14:50:33 -0700439 sensor = std::make_shared<HwmonTempSensor>(
440 *hwmonFile, sensorType, objectServer, dbusConnection,
Ed Tanousbb679322022-05-16 16:10:00 -0700441 io, sensorName, std::move(thresholds),
Jayashree Dhanapal9f3a74e2022-01-06 12:05:06 +0530442 thisSensorParameters, pollRate, interfacePath,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500443 readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700444 sensor->setupRead();
445 }
Ed Tanousbb679322022-05-16 16:10:00 -0700446
Willy Tu9eb0cc32022-04-06 11:03:32 -0700447 hwmonName.erase(
448 remove(hwmonName.begin(), hwmonName.end(), sensorName),
449 hwmonName.end());
James Feistdf515152019-09-18 16:40:40 -0700450 }
Ed Tanousbb679322022-05-16 16:10:00 -0700451 if (hwmonName.empty())
452 {
453 configMap.erase(findSensorCfg);
454 }
455 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700456 });
James Feistdf515152019-09-18 16:40:40 -0700457 getter->getConfiguration(
458 std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
James Feist6714a252018-09-10 15:26:18 -0700459}
460
Matt Spinler20bf2c12021-09-14 11:07:07 -0500461void interfaceRemoved(
Patrick Williams92f8f512022-07-22 19:26:55 -0500462 sdbusplus::message_t& message,
Matt Spinler20bf2c12021-09-14 11:07:07 -0500463 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
464 sensors)
465{
466 if (message.is_method_error())
467 {
468 std::cerr << "interfacesRemoved callback method error\n";
469 return;
470 }
471
472 sdbusplus::message::object_path path;
473 std::vector<std::string> interfaces;
474
475 message.read(path, interfaces);
476
477 // If the xyz.openbmc_project.Confguration.X interface was removed
478 // for one or more sensors, delete those sensor objects.
479 auto sensorIt = sensors.begin();
480 while (sensorIt != sensors.end())
481 {
482 if ((sensorIt->second->configurationPath == path) &&
483 (std::find(interfaces.begin(), interfaces.end(),
484 sensorIt->second->objectType) != interfaces.end()))
485 {
486 sensorIt = sensors.erase(sensorIt);
487 }
488 else
489 {
490 sensorIt++;
491 }
492 }
493}
494
James Feistb6c0b912019-07-09 12:21:44 -0700495int main()
James Feist6714a252018-09-10 15:26:18 -0700496{
497 boost::asio::io_service io;
498 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
499 systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
500 sdbusplus::asio::object_server objectServer(systemBus);
Yong Lif3fd1912020-03-25 21:35:23 +0800501 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
James Feist6714a252018-09-10 15:26:18 -0700502 sensors;
James Feist5591cf082020-07-15 16:44:54 -0700503 auto sensorsChanged =
504 std::make_shared<boost::container::flat_set<std::string>>();
James Feist6714a252018-09-10 15:26:18 -0700505
506 io.post([&]() {
507 createSensors(io, objectServer, sensors, systemBus, nullptr);
508 });
509
510 boost::asio::deadline_timer filterTimer(io);
Patrick Williams92f8f512022-07-22 19:26:55 -0500511 std::function<void(sdbusplus::message_t&)> eventHandler =
512 [&](sdbusplus::message_t& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700513 if (message.is_method_error())
514 {
515 std::cerr << "callback method error\n";
516 return;
517 }
518 sensorsChanged->insert(message.get_path());
519 // this implicitly cancels the timer
520 filterTimer.expires_from_now(boost::posix_time::seconds(1));
521
522 filterTimer.async_wait([&](const boost::system::error_code& ec) {
523 if (ec == boost::asio::error::operation_aborted)
James Feist6714a252018-09-10 15:26:18 -0700524 {
Ed Tanousbb679322022-05-16 16:10:00 -0700525 /* we were canceled*/
James Feist6714a252018-09-10 15:26:18 -0700526 return;
527 }
Ed Tanousbb679322022-05-16 16:10:00 -0700528 if (ec)
529 {
530 std::cerr << "timer error\n";
531 return;
532 }
533 createSensors(io, objectServer, sensors, systemBus, sensorsChanged);
534 });
535 };
James Feist6714a252018-09-10 15:26:18 -0700536
Zev Weiss214d9712022-08-12 12:54:31 -0700537 std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
538 setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
Bruce Lee1263c3d2021-06-04 15:16:33 +0800539 setupManufacturingModeMatch(*systemBus);
Matt Spinler20bf2c12021-09-14 11:07:07 -0500540
541 // Watch for entity-manager to remove configuration interfaces
542 // so the corresponding sensors can be removed.
Patrick Williams92f8f512022-07-22 19:26:55 -0500543 auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match_t>(
544 static_cast<sdbusplus::bus_t&>(*systemBus),
Matt Spinler20bf2c12021-09-14 11:07:07 -0500545 "type='signal',member='InterfacesRemoved',arg0path='" +
546 std::string(inventoryPath) + "/'",
Patrick Williams92f8f512022-07-22 19:26:55 -0500547 [&sensors](sdbusplus::message_t& msg) {
Ed Tanousbb679322022-05-16 16:10:00 -0700548 interfaceRemoved(msg, sensors);
Matt Spinler20bf2c12021-09-14 11:07:07 -0500549 });
550
551 matches.emplace_back(std::move(ifaceRemovedMatch));
552
James Feist6714a252018-09-10 15:26:18 -0700553 io.run();
554}