blob: dbccd275813cd4e755cbb6748e3048c14354abf0 [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/predicate.hpp>
20#include <boost/algorithm/string/replace.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070021#include <boost/container/flat_map.hpp>
James Feist6714a252018-09-10 15:26:18 -070022#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070023#include <sdbusplus/asio/connection.hpp>
24#include <sdbusplus/asio/object_server.hpp>
25#include <sdbusplus/bus/match.hpp>
26
27#include <array>
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
44static constexpr double maxValueTemperature = 127; // DegreesC
45static constexpr double minValueTemperature = -128; // DegreesC
46
James Feistcf3bce62019-01-08 10:07:19 -080047namespace fs = std::filesystem;
Brandon Kim66558232021-11-09 16:53:08 -080048static auto sensorTypes{
Potin Lai47863342021-12-14 18:58:12 +080049 std::to_array<const char*>({"xyz.openbmc_project.Configuration.DPS310",
50 "xyz.openbmc_project.Configuration.EMC1412",
Brandon Kim66558232021-11-09 16:53:08 -080051 "xyz.openbmc_project.Configuration.EMC1413",
52 "xyz.openbmc_project.Configuration.EMC1414",
Potin Lai47863342021-12-14 18:58:12 +080053 "xyz.openbmc_project.Configuration.HDC1080",
54 "xyz.openbmc_project.Configuration.JC42",
55 "xyz.openbmc_project.Configuration.LM75A",
56 "xyz.openbmc_project.Configuration.LM95234",
Brandon Kim66558232021-11-09 16:53:08 -080057 "xyz.openbmc_project.Configuration.MAX31725",
58 "xyz.openbmc_project.Configuration.MAX31730",
59 "xyz.openbmc_project.Configuration.MAX6581",
60 "xyz.openbmc_project.Configuration.MAX6654",
61 "xyz.openbmc_project.Configuration.NCT7802",
62 "xyz.openbmc_project.Configuration.SBTSI",
Potin Lai47863342021-12-14 18:58:12 +080063 "xyz.openbmc_project.Configuration.SI7020",
Brandon Kim66558232021-11-09 16:53:08 -080064 "xyz.openbmc_project.Configuration.TMP112",
65 "xyz.openbmc_project.Configuration.TMP175",
66 "xyz.openbmc_project.Configuration.TMP421",
67 "xyz.openbmc_project.Configuration.TMP441",
Brandon Kim66558232021-11-09 16:53:08 -080068 "xyz.openbmc_project.Configuration.TMP75",
Potin Lai47863342021-12-14 18:58:12 +080069 "xyz.openbmc_project.Configuration.W83773G"})};
James Feist6714a252018-09-10 15:26:18 -070070
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050071static struct SensorParams
72 getSensorParameters(const std::filesystem::path& path)
73{
74 // offset is to default to 0 and scale to 1, see lore
75 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
76 struct SensorParams tmpSensorParameters = {.minValue = minValueTemperature,
77 .maxValue = maxValueTemperature,
78 .offsetValue = 0.0,
79 .scaleValue = 1.0,
Bruce Mitchell5a86e562021-12-10 12:26:22 -060080 .units =
81 sensor_paths::unitDegreesC,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050082 .typeName = "temperature"};
83
84 // For IIO RAW sensors we get a raw_value, an offset, and scale
85 // to compute the value = (raw_value + offset) * scale
86 // with a _raw IIO device we need to get the
87 // offsetValue and scaleValue from the driver
88 // these are used to compute the reading in
89 // units that have yet to be scaled for D-Bus.
90 const std::string pathStr = path.string();
91 if (pathStr.ends_with("_raw"))
92 {
93 std::string pathOffsetStr =
94 pathStr.substr(0, pathStr.size() - 4) + "_offset";
95 std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
96 // In case there is nothing to read skip this device
97 // This is not an error condition see lore
98 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
99 if (tmpOffsetValue)
100 {
101 tmpSensorParameters.offsetValue = *tmpOffsetValue;
102 }
103
104 std::string pathScaleStr =
105 pathStr.substr(0, pathStr.size() - 4) + "_scale";
106 std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
107 // In case there is nothing to read skip this device
108 // This is not an error condition see lore
109 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
110 if (tmpScaleValue)
111 {
112 tmpSensorParameters.scaleValue = *tmpScaleValue;
113 }
114 }
115
116 // Temperatures are read in milli degrees Celsius, we need
117 // degrees Celsius. Pressures are read in kilopascal, we need
118 // Pascals. On D-Bus for Open BMC we use the International
119 // System of Units without prefixes. Links to the kernel
120 // documentation:
121 // https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
122 // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
123 if (path.filename() == "in_pressure_input" ||
124 path.filename() == "in_pressure_raw")
125 {
126 tmpSensorParameters.minValue = minValuePressure;
127 tmpSensorParameters.maxValue = maxValuePressure;
128 // Pressures are read in kilopascal, we need Pascals.
129 tmpSensorParameters.scaleValue *= 1000.0;
130 tmpSensorParameters.typeName = "pressure";
Bruce Mitchell5a86e562021-12-10 12:26:22 -0600131 tmpSensorParameters.units = sensor_paths::unitPascals;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500132 }
133 else
134 {
135 // Temperatures are read in milli degrees Celsius,
136 // we need degrees Celsius.
137 tmpSensorParameters.scaleValue *= 0.001;
138 }
139
140 return tmpSensorParameters;
141}
142
James Feist6714a252018-09-10 15:26:18 -0700143void createSensors(
144 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
Yong Lif3fd1912020-03-25 21:35:23 +0800145 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
James Feist6714a252018-09-10 15:26:18 -0700146 sensors,
147 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
James Feist5591cf082020-07-15 16:44:54 -0700148 const std::shared_ptr<boost::container::flat_set<std::string>>&
James Feist6714a252018-09-10 15:26:18 -0700149 sensorsChanged)
150{
James Feistdf515152019-09-18 16:40:40 -0700151 auto getter = std::make_shared<GetSensorConfiguration>(
152 dbusConnection,
Ed Tanous8a17c302021-09-02 15:07:11 -0700153 [&io, &objectServer, &sensors, &dbusConnection,
154 sensorsChanged](const ManagedObjectType& sensorConfigurations) {
James Feistdf515152019-09-18 16:40:40 -0700155 bool firstScan = sensorsChanged == nullptr;
James Feist6714a252018-09-10 15:26:18 -0700156
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500157 // IIO _raw devices look like this on sysfs:
158 // /sys/bus/iio/devices/iio:device0/in_temp_raw
159 // /sys/bus/iio/devices/iio:device0/in_temp_offset
160 // /sys/bus/iio/devices/iio:device0/in_temp_scale
161 //
162 // Other IIO devices look like this on sysfs:
163 // /sys/bus/iio/devices/iio:device1/in_temp_input
164 // /sys/bus/iio/devices/iio:device1/in_pressure_input
James Feistdf515152019-09-18 16:40:40 -0700165 std::vector<fs::path> paths;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500166 fs::path root("/sys/bus/iio/devices");
167 findFiles(root, R"(in_temp\d*_(input|raw))", paths);
168 findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
169 findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
170
171 if (paths.empty())
James Feist37266ca2018-10-15 15:56:28 -0700172 {
James Feistdf515152019-09-18 16:40:40 -0700173 return;
174 }
175
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500176 // iterate through all found temp and pressure sensors,
177 // and try to match them with configuration
James Feistdf515152019-09-18 16:40:40 -0700178 for (auto& path : paths)
179 {
180 std::smatch match;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500181 const std::string pathStr = path.string();
James Feistdf515152019-09-18 16:40:40 -0700182 auto directory = path.parent_path();
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500183 fs::path device;
James Feistdf515152019-09-18 16:40:40 -0700184
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500185 std::string deviceName;
186 if (pathStr.starts_with("/sys/bus/iio/devices"))
James Feist37266ca2018-10-15 15:56:28 -0700187 {
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500188 device = fs::canonical(directory);
189 deviceName = device.parent_path().stem();
James Feistdf515152019-09-18 16:40:40 -0700190 }
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500191 else
192 {
193 device = directory / "device";
194 deviceName = fs::canonical(device).stem();
195 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700196 auto findHyphen = deviceName.find('-');
James Feistdf515152019-09-18 16:40:40 -0700197 if (findHyphen == std::string::npos)
198 {
199 std::cerr << "found bad device " << deviceName << "\n";
200 continue;
201 }
202 std::string busStr = deviceName.substr(0, findHyphen);
203 std::string addrStr = deviceName.substr(findHyphen + 1);
204
205 size_t bus = 0;
206 size_t addr = 0;
207 try
208 {
209 bus = std::stoi(busStr);
Ed Tanous8a57ec02020-10-09 12:46:52 -0700210 addr = std::stoi(addrStr, nullptr, 16);
James Feistdf515152019-09-18 16:40:40 -0700211 }
Patrick Williams26601e82021-10-06 12:43:25 -0500212 catch (const std::invalid_argument&)
James Feistdf515152019-09-18 16:40:40 -0700213 {
214 continue;
215 }
216 const SensorData* sensorData = nullptr;
217 const std::string* interfacePath = nullptr;
218 const char* sensorType = nullptr;
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800219 const SensorBaseConfiguration* baseConfiguration = nullptr;
220 const SensorBaseConfigMap* baseConfigMap = nullptr;
James Feistdf515152019-09-18 16:40:40 -0700221
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500222 auto thisSensorParameters = getSensorParameters(path);
223
James Feistdf515152019-09-18 16:40:40 -0700224 for (const std::pair<sdbusplus::message::object_path,
225 SensorData>& sensor : sensorConfigurations)
226 {
227 sensorData = &(sensor.second);
228 for (const char* type : sensorTypes)
229 {
230 auto sensorBase = sensorData->find(type);
231 if (sensorBase != sensorData->end())
232 {
233 baseConfiguration = &(*sensorBase);
234 sensorType = type;
235 break;
236 }
237 }
238 if (baseConfiguration == nullptr)
239 {
240 std::cerr << "error finding base configuration for "
241 << deviceName << "\n";
242 continue;
243 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800244 baseConfigMap = &baseConfiguration->second;
245 auto configurationBus = baseConfigMap->find("Bus");
246 auto configurationAddress = baseConfigMap->find("Address");
James Feistdf515152019-09-18 16:40:40 -0700247
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800248 if (configurationBus == baseConfigMap->end() ||
249 configurationAddress == baseConfigMap->end())
James Feistdf515152019-09-18 16:40:40 -0700250 {
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800251 std::cerr << "error finding bus or address in "
252 "configuration\n";
James Feistdf515152019-09-18 16:40:40 -0700253 continue;
254 }
255
256 if (std::get<uint64_t>(configurationBus->second) != bus ||
257 std::get<uint64_t>(configurationAddress->second) !=
258 addr)
259 {
260 continue;
261 }
262
263 interfacePath = &(sensor.first.str);
James Feist37266ca2018-10-15 15:56:28 -0700264 break;
265 }
James Feistdf515152019-09-18 16:40:40 -0700266 if (interfacePath == nullptr)
James Feist6714a252018-09-10 15:26:18 -0700267 {
James Feistdf515152019-09-18 16:40:40 -0700268 continue;
James Feist6714a252018-09-10 15:26:18 -0700269 }
James Feist6714a252018-09-10 15:26:18 -0700270
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500271 // Temperature has "Name", pressure has "Name1"
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800272 auto findSensorName = baseConfigMap->find("Name");
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500273 if (thisSensorParameters.typeName == "pressure")
274 {
275 findSensorName = baseConfigMap->find("Name1");
276 }
277
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800278 if (findSensorName == baseConfigMap->end())
James Feistdf515152019-09-18 16:40:40 -0700279 {
280 std::cerr << "could not determine configuration name for "
281 << deviceName << "\n";
282 continue;
283 }
284 std::string sensorName =
285 std::get<std::string>(findSensorName->second);
286 // on rescans, only update sensors we were signaled by
287 auto findSensor = sensors.find(sensorName);
288 if (!firstScan && findSensor != sensors.end())
289 {
290 bool found = false;
Bruce Mitchelld653b752021-08-23 13:09:00 -0500291 auto it = sensorsChanged->begin();
292 while (it != sensorsChanged->end())
James Feistdf515152019-09-18 16:40:40 -0700293 {
294 if (boost::ends_with(*it, findSensor->second->name))
295 {
Bruce Mitchelld653b752021-08-23 13:09:00 -0500296 it = sensorsChanged->erase(it);
James Feistdf515152019-09-18 16:40:40 -0700297 findSensor->second = nullptr;
298 found = true;
299 break;
300 }
Bruce Mitchelld653b752021-08-23 13:09:00 -0500301 ++it;
James Feistdf515152019-09-18 16:40:40 -0700302 }
303 if (!found)
304 {
305 continue;
306 }
307 }
Matt Spinler5636d522021-03-17 14:52:18 -0500308
James Feistdf515152019-09-18 16:40:40 -0700309 std::vector<thresholds::Threshold> sensorThresholds;
Matt Spinler5636d522021-03-17 14:52:18 -0500310 int index = 1;
311
312 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
313 nullptr, &index))
James Feistdf515152019-09-18 16:40:40 -0700314 {
315 std::cerr << "error populating thresholds for "
Matt Spinler5636d522021-03-17 14:52:18 -0500316 << sensorName << " index 1\n";
James Feistdf515152019-09-18 16:40:40 -0700317 }
Jeff Lin87bc67f2020-12-04 20:58:01 +0800318
319 auto findPollRate = baseConfiguration->second.find("PollRate");
320 float pollRate = pollRateDefault;
321 if (findPollRate != baseConfiguration->second.end())
322 {
323 pollRate = std::visit(VariantToFloatVisitor(),
324 findPollRate->second);
325 if (pollRate <= 0.0f)
326 {
327 pollRate = pollRateDefault; // polling time too short
328 }
329 }
330
James Feistf9b01b62020-01-29 15:21:58 -0800331 auto findPowerOn = baseConfiguration->second.find("PowerState");
332 PowerState readState = PowerState::always;
333 if (findPowerOn != baseConfiguration->second.end())
334 {
335 std::string powerState = std::visit(
336 VariantToStringVisitor(), findPowerOn->second);
337 setReadState(powerState, readState);
338 }
Jason Ling100c20b2020-08-11 14:50:33 -0700339
340 auto permitSet = getPermitSet(*baseConfigMap);
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800341 auto& sensor = sensors[sensorName];
342 sensor = nullptr;
Jason Ling100c20b2020-08-11 14:50:33 -0700343 auto hwmonFile = getFullHwmonFilePath(directory.string(),
344 "temp1", permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500345 if (pathStr.starts_with("/sys/bus/iio/devices"))
346 {
347 hwmonFile = pathStr;
348 }
Jason Ling100c20b2020-08-11 14:50:33 -0700349 if (hwmonFile)
350 {
351 sensor = std::make_shared<HwmonTempSensor>(
352 *hwmonFile, sensorType, objectServer, dbusConnection,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500353 io, sensorName, std::move(sensorThresholds),
354 thisSensorParameters, pollRate, *interfacePath,
355 readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700356 sensor->setupRead();
357 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800358 // Looking for keys like "Name1" for temp2_input,
359 // "Name2" for temp3_input, etc.
360 int i = 0;
361 while (true)
James Feistdf515152019-09-18 16:40:40 -0700362 {
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800363 ++i;
364 auto findKey =
Jason Ling8b8bcc82020-08-04 19:33:22 -0700365 baseConfigMap->find("Name" + std::to_string(i));
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800366 if (findKey == baseConfigMap->end())
367 {
368 break;
369 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800370 std::string sensorName =
371 std::get<std::string>(findKey->second);
Jason Ling100c20b2020-08-11 14:50:33 -0700372 hwmonFile = getFullHwmonFilePath(
373 directory.string(), "temp" + std::to_string(i + 1),
374 permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500375 if (pathStr.starts_with("/sys/bus/iio/devices"))
376 {
377 continue;
378 }
Jason Ling100c20b2020-08-11 14:50:33 -0700379 if (hwmonFile)
380 {
Matt Spinler5636d522021-03-17 14:52:18 -0500381 // To look up thresholds for these additional sensors,
382 // match on the Index property in the threshold data
383 // where the index comes from the sysfs file we're on,
384 // i.e. index = 2 for temp2_input.
385 int index = i + 1;
386 std::vector<thresholds::Threshold> thresholds;
387
388 if (!parseThresholdsFromConfig(*sensorData, thresholds,
389 nullptr, &index))
390 {
391 std::cerr << "error populating thresholds for "
392 << sensorName << " index " << index
393 << "\n";
394 }
395
Jason Ling100c20b2020-08-11 14:50:33 -0700396 auto& sensor = sensors[sensorName];
397 sensor = nullptr;
398 sensor = std::make_shared<HwmonTempSensor>(
399 *hwmonFile, sensorType, objectServer,
400 dbusConnection, io, sensorName,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500401 std::move(thresholds), thisSensorParameters,
402 pollRate, *interfacePath, readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700403 sensor->setupRead();
404 }
James Feistdf515152019-09-18 16:40:40 -0700405 }
James Feistdf515152019-09-18 16:40:40 -0700406 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700407 });
James Feistdf515152019-09-18 16:40:40 -0700408 getter->getConfiguration(
409 std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
James Feist6714a252018-09-10 15:26:18 -0700410}
411
Matt Spinler20bf2c12021-09-14 11:07:07 -0500412void interfaceRemoved(
413 sdbusplus::message::message& message,
414 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
415 sensors)
416{
417 if (message.is_method_error())
418 {
419 std::cerr << "interfacesRemoved callback method error\n";
420 return;
421 }
422
423 sdbusplus::message::object_path path;
424 std::vector<std::string> interfaces;
425
426 message.read(path, interfaces);
427
428 // If the xyz.openbmc_project.Confguration.X interface was removed
429 // for one or more sensors, delete those sensor objects.
430 auto sensorIt = sensors.begin();
431 while (sensorIt != sensors.end())
432 {
433 if ((sensorIt->second->configurationPath == path) &&
434 (std::find(interfaces.begin(), interfaces.end(),
435 sensorIt->second->objectType) != interfaces.end()))
436 {
437 sensorIt = sensors.erase(sensorIt);
438 }
439 else
440 {
441 sensorIt++;
442 }
443 }
444}
445
James Feistb6c0b912019-07-09 12:21:44 -0700446int main()
James Feist6714a252018-09-10 15:26:18 -0700447{
448 boost::asio::io_service io;
449 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
450 systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
451 sdbusplus::asio::object_server objectServer(systemBus);
Yong Lif3fd1912020-03-25 21:35:23 +0800452 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
James Feist6714a252018-09-10 15:26:18 -0700453 sensors;
454 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
James Feist5591cf082020-07-15 16:44:54 -0700455 auto sensorsChanged =
456 std::make_shared<boost::container::flat_set<std::string>>();
James Feist6714a252018-09-10 15:26:18 -0700457
458 io.post([&]() {
459 createSensors(io, objectServer, sensors, systemBus, nullptr);
460 });
461
462 boost::asio::deadline_timer filterTimer(io);
463 std::function<void(sdbusplus::message::message&)> eventHandler =
464 [&](sdbusplus::message::message& message) {
465 if (message.is_method_error())
466 {
467 std::cerr << "callback method error\n";
468 return;
469 }
470 sensorsChanged->insert(message.get_path());
471 // this implicitly cancels the timer
472 filterTimer.expires_from_now(boost::posix_time::seconds(1));
473
474 filterTimer.async_wait([&](const boost::system::error_code& ec) {
475 if (ec == boost::asio::error::operation_aborted)
476 {
477 /* we were canceled*/
478 return;
479 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700480 if (ec)
James Feist6714a252018-09-10 15:26:18 -0700481 {
482 std::cerr << "timer error\n";
483 return;
484 }
485 createSensors(io, objectServer, sensors, systemBus,
486 sensorsChanged);
487 });
488 };
489
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700490 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700491 {
492 auto match = std::make_unique<sdbusplus::bus::match::match>(
493 static_cast<sdbusplus::bus::bus&>(*systemBus),
494 "type='signal',member='PropertiesChanged',path_namespace='" +
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700495 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
James Feist6714a252018-09-10 15:26:18 -0700496 eventHandler);
497 matches.emplace_back(std::move(match));
498 }
499
Bruce Lee1263c3d2021-06-04 15:16:33 +0800500 setupManufacturingModeMatch(*systemBus);
Matt Spinler20bf2c12021-09-14 11:07:07 -0500501
502 // Watch for entity-manager to remove configuration interfaces
503 // so the corresponding sensors can be removed.
504 auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
505 static_cast<sdbusplus::bus::bus&>(*systemBus),
506 "type='signal',member='InterfacesRemoved',arg0path='" +
507 std::string(inventoryPath) + "/'",
508 [&sensors](sdbusplus::message::message& msg) {
509 interfaceRemoved(msg, sensors);
510 });
511
512 matches.emplace_back(std::move(ifaceRemovedMatch));
513
James Feist6714a252018-09-10 15:26:18 -0700514 io.run();
515}