blob: 274e0a1f0b6a24b6e56e7c6d9b28fb219c6c482e [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{
49 std::to_array<const char*>({"xyz.openbmc_project.Configuration.EMC1412",
50 "xyz.openbmc_project.Configuration.EMC1413",
51 "xyz.openbmc_project.Configuration.EMC1414",
52 "xyz.openbmc_project.Configuration.MAX31725",
53 "xyz.openbmc_project.Configuration.MAX31730",
54 "xyz.openbmc_project.Configuration.MAX6581",
55 "xyz.openbmc_project.Configuration.MAX6654",
56 "xyz.openbmc_project.Configuration.NCT7802",
57 "xyz.openbmc_project.Configuration.SBTSI",
58 "xyz.openbmc_project.Configuration.LM95234",
59 "xyz.openbmc_project.Configuration.TMP112",
60 "xyz.openbmc_project.Configuration.TMP175",
61 "xyz.openbmc_project.Configuration.TMP421",
62 "xyz.openbmc_project.Configuration.TMP441",
63 "xyz.openbmc_project.Configuration.LM75A",
64 "xyz.openbmc_project.Configuration.TMP75",
hsanganidaf6f562021-11-30 12:17:37 +053065 "xyz.openbmc_project.Configuration.W83773G",
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050066 "xyz.openbmc_project.Configuration.DPS310",
67 "xyz.openbmc_project.Configuration.SI7020",
hsanganidaf6f562021-11-30 12:17:37 +053068 "xyz.openbmc_project.Configuration.JC42"})};
James Feist6714a252018-09-10 15:26:18 -070069
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050070static struct SensorParams
71 getSensorParameters(const std::filesystem::path& path)
72{
73 // offset is to default to 0 and scale to 1, see lore
74 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
75 struct SensorParams tmpSensorParameters = {.minValue = minValueTemperature,
76 .maxValue = maxValueTemperature,
77 .offsetValue = 0.0,
78 .scaleValue = 1.0,
Bruce Mitchell5a86e562021-12-10 12:26:22 -060079 .units =
80 sensor_paths::unitDegreesC,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050081 .typeName = "temperature"};
82
83 // For IIO RAW sensors we get a raw_value, an offset, and scale
84 // to compute the value = (raw_value + offset) * scale
85 // with a _raw IIO device we need to get the
86 // offsetValue and scaleValue from the driver
87 // these are used to compute the reading in
88 // units that have yet to be scaled for D-Bus.
89 const std::string pathStr = path.string();
90 if (pathStr.ends_with("_raw"))
91 {
92 std::string pathOffsetStr =
93 pathStr.substr(0, pathStr.size() - 4) + "_offset";
94 std::optional<double> tmpOffsetValue = readFile(pathOffsetStr, 1.0);
95 // In case there is nothing to read skip this device
96 // This is not an error condition see lore
97 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
98 if (tmpOffsetValue)
99 {
100 tmpSensorParameters.offsetValue = *tmpOffsetValue;
101 }
102
103 std::string pathScaleStr =
104 pathStr.substr(0, pathStr.size() - 4) + "_scale";
105 std::optional<double> tmpScaleValue = readFile(pathScaleStr, 1.0);
106 // In case there is nothing to read skip this device
107 // This is not an error condition see lore
108 // https://lore.kernel.org/linux-iio/5c79425f-6e88-36b6-cdfe-4080738d039f@metafoo.de/
109 if (tmpScaleValue)
110 {
111 tmpSensorParameters.scaleValue = *tmpScaleValue;
112 }
113 }
114
115 // Temperatures are read in milli degrees Celsius, we need
116 // degrees Celsius. Pressures are read in kilopascal, we need
117 // Pascals. On D-Bus for Open BMC we use the International
118 // System of Units without prefixes. Links to the kernel
119 // documentation:
120 // https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
121 // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
122 if (path.filename() == "in_pressure_input" ||
123 path.filename() == "in_pressure_raw")
124 {
125 tmpSensorParameters.minValue = minValuePressure;
126 tmpSensorParameters.maxValue = maxValuePressure;
127 // Pressures are read in kilopascal, we need Pascals.
128 tmpSensorParameters.scaleValue *= 1000.0;
129 tmpSensorParameters.typeName = "pressure";
Bruce Mitchell5a86e562021-12-10 12:26:22 -0600130 tmpSensorParameters.units = sensor_paths::unitPascals;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500131 }
132 else
133 {
134 // Temperatures are read in milli degrees Celsius,
135 // we need degrees Celsius.
136 tmpSensorParameters.scaleValue *= 0.001;
137 }
138
139 return tmpSensorParameters;
140}
141
James Feist6714a252018-09-10 15:26:18 -0700142void createSensors(
143 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
Yong Lif3fd1912020-03-25 21:35:23 +0800144 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
James Feist6714a252018-09-10 15:26:18 -0700145 sensors,
146 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
James Feist5591cf082020-07-15 16:44:54 -0700147 const std::shared_ptr<boost::container::flat_set<std::string>>&
James Feist6714a252018-09-10 15:26:18 -0700148 sensorsChanged)
149{
James Feistdf515152019-09-18 16:40:40 -0700150 auto getter = std::make_shared<GetSensorConfiguration>(
151 dbusConnection,
Ed Tanous8a17c302021-09-02 15:07:11 -0700152 [&io, &objectServer, &sensors, &dbusConnection,
153 sensorsChanged](const ManagedObjectType& sensorConfigurations) {
James Feistdf515152019-09-18 16:40:40 -0700154 bool firstScan = sensorsChanged == nullptr;
James Feist6714a252018-09-10 15:26:18 -0700155
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500156 // IIO _raw devices look like this on sysfs:
157 // /sys/bus/iio/devices/iio:device0/in_temp_raw
158 // /sys/bus/iio/devices/iio:device0/in_temp_offset
159 // /sys/bus/iio/devices/iio:device0/in_temp_scale
160 //
161 // Other IIO devices look like this on sysfs:
162 // /sys/bus/iio/devices/iio:device1/in_temp_input
163 // /sys/bus/iio/devices/iio:device1/in_pressure_input
James Feistdf515152019-09-18 16:40:40 -0700164 std::vector<fs::path> paths;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500165 fs::path root("/sys/bus/iio/devices");
166 findFiles(root, R"(in_temp\d*_(input|raw))", paths);
167 findFiles(root, R"(in_pressure\d*_(input|raw))", paths);
168 findFiles(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths);
169
170 if (paths.empty())
James Feist37266ca2018-10-15 15:56:28 -0700171 {
James Feistdf515152019-09-18 16:40:40 -0700172 return;
173 }
174
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500175 // iterate through all found temp and pressure sensors,
176 // and try to match them with configuration
James Feistdf515152019-09-18 16:40:40 -0700177 for (auto& path : paths)
178 {
179 std::smatch match;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500180 const std::string pathStr = path.string();
James Feistdf515152019-09-18 16:40:40 -0700181 auto directory = path.parent_path();
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500182 fs::path device;
James Feistdf515152019-09-18 16:40:40 -0700183
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500184 std::string deviceName;
185 if (pathStr.starts_with("/sys/bus/iio/devices"))
James Feist37266ca2018-10-15 15:56:28 -0700186 {
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500187 device = fs::canonical(directory);
188 deviceName = device.parent_path().stem();
James Feistdf515152019-09-18 16:40:40 -0700189 }
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500190 else
191 {
192 device = directory / "device";
193 deviceName = fs::canonical(device).stem();
194 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700195 auto findHyphen = deviceName.find('-');
James Feistdf515152019-09-18 16:40:40 -0700196 if (findHyphen == std::string::npos)
197 {
198 std::cerr << "found bad device " << deviceName << "\n";
199 continue;
200 }
201 std::string busStr = deviceName.substr(0, findHyphen);
202 std::string addrStr = deviceName.substr(findHyphen + 1);
203
204 size_t bus = 0;
205 size_t addr = 0;
206 try
207 {
208 bus = std::stoi(busStr);
Ed Tanous8a57ec02020-10-09 12:46:52 -0700209 addr = std::stoi(addrStr, nullptr, 16);
James Feistdf515152019-09-18 16:40:40 -0700210 }
Patrick Williams26601e82021-10-06 12:43:25 -0500211 catch (const std::invalid_argument&)
James Feistdf515152019-09-18 16:40:40 -0700212 {
213 continue;
214 }
215 const SensorData* sensorData = nullptr;
216 const std::string* interfacePath = nullptr;
217 const char* sensorType = nullptr;
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800218 const SensorBaseConfiguration* baseConfiguration = nullptr;
219 const SensorBaseConfigMap* baseConfigMap = nullptr;
James Feistdf515152019-09-18 16:40:40 -0700220
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500221 auto thisSensorParameters = getSensorParameters(path);
222
James Feistdf515152019-09-18 16:40:40 -0700223 for (const std::pair<sdbusplus::message::object_path,
224 SensorData>& sensor : sensorConfigurations)
225 {
226 sensorData = &(sensor.second);
227 for (const char* type : sensorTypes)
228 {
229 auto sensorBase = sensorData->find(type);
230 if (sensorBase != sensorData->end())
231 {
232 baseConfiguration = &(*sensorBase);
233 sensorType = type;
234 break;
235 }
236 }
237 if (baseConfiguration == nullptr)
238 {
239 std::cerr << "error finding base configuration for "
240 << deviceName << "\n";
241 continue;
242 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800243 baseConfigMap = &baseConfiguration->second;
244 auto configurationBus = baseConfigMap->find("Bus");
245 auto configurationAddress = baseConfigMap->find("Address");
James Feistdf515152019-09-18 16:40:40 -0700246
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800247 if (configurationBus == baseConfigMap->end() ||
248 configurationAddress == baseConfigMap->end())
James Feistdf515152019-09-18 16:40:40 -0700249 {
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800250 std::cerr << "error finding bus or address in "
251 "configuration\n";
James Feistdf515152019-09-18 16:40:40 -0700252 continue;
253 }
254
255 if (std::get<uint64_t>(configurationBus->second) != bus ||
256 std::get<uint64_t>(configurationAddress->second) !=
257 addr)
258 {
259 continue;
260 }
261
262 interfacePath = &(sensor.first.str);
James Feist37266ca2018-10-15 15:56:28 -0700263 break;
264 }
James Feistdf515152019-09-18 16:40:40 -0700265 if (interfacePath == nullptr)
James Feist6714a252018-09-10 15:26:18 -0700266 {
James Feistdf515152019-09-18 16:40:40 -0700267 continue;
James Feist6714a252018-09-10 15:26:18 -0700268 }
James Feist6714a252018-09-10 15:26:18 -0700269
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500270 // Temperature has "Name", pressure has "Name1"
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800271 auto findSensorName = baseConfigMap->find("Name");
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500272 if (thisSensorParameters.typeName == "pressure")
273 {
274 findSensorName = baseConfigMap->find("Name1");
275 }
276
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800277 if (findSensorName == baseConfigMap->end())
James Feistdf515152019-09-18 16:40:40 -0700278 {
279 std::cerr << "could not determine configuration name for "
280 << deviceName << "\n";
281 continue;
282 }
283 std::string sensorName =
284 std::get<std::string>(findSensorName->second);
285 // on rescans, only update sensors we were signaled by
286 auto findSensor = sensors.find(sensorName);
287 if (!firstScan && findSensor != sensors.end())
288 {
289 bool found = false;
Bruce Mitchelld653b752021-08-23 13:09:00 -0500290 auto it = sensorsChanged->begin();
291 while (it != sensorsChanged->end())
James Feistdf515152019-09-18 16:40:40 -0700292 {
293 if (boost::ends_with(*it, findSensor->second->name))
294 {
Bruce Mitchelld653b752021-08-23 13:09:00 -0500295 it = sensorsChanged->erase(it);
James Feistdf515152019-09-18 16:40:40 -0700296 findSensor->second = nullptr;
297 found = true;
298 break;
299 }
Bruce Mitchelld653b752021-08-23 13:09:00 -0500300 ++it;
James Feistdf515152019-09-18 16:40:40 -0700301 }
302 if (!found)
303 {
304 continue;
305 }
306 }
Matt Spinler5636d522021-03-17 14:52:18 -0500307
James Feistdf515152019-09-18 16:40:40 -0700308 std::vector<thresholds::Threshold> sensorThresholds;
Matt Spinler5636d522021-03-17 14:52:18 -0500309 int index = 1;
310
311 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
312 nullptr, &index))
James Feistdf515152019-09-18 16:40:40 -0700313 {
314 std::cerr << "error populating thresholds for "
Matt Spinler5636d522021-03-17 14:52:18 -0500315 << sensorName << " index 1\n";
James Feistdf515152019-09-18 16:40:40 -0700316 }
Jeff Lin87bc67f2020-12-04 20:58:01 +0800317
318 auto findPollRate = baseConfiguration->second.find("PollRate");
319 float pollRate = pollRateDefault;
320 if (findPollRate != baseConfiguration->second.end())
321 {
322 pollRate = std::visit(VariantToFloatVisitor(),
323 findPollRate->second);
324 if (pollRate <= 0.0f)
325 {
326 pollRate = pollRateDefault; // polling time too short
327 }
328 }
329
James Feistf9b01b62020-01-29 15:21:58 -0800330 auto findPowerOn = baseConfiguration->second.find("PowerState");
331 PowerState readState = PowerState::always;
332 if (findPowerOn != baseConfiguration->second.end())
333 {
334 std::string powerState = std::visit(
335 VariantToStringVisitor(), findPowerOn->second);
336 setReadState(powerState, readState);
337 }
Jason Ling100c20b2020-08-11 14:50:33 -0700338
339 auto permitSet = getPermitSet(*baseConfigMap);
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800340 auto& sensor = sensors[sensorName];
341 sensor = nullptr;
Jason Ling100c20b2020-08-11 14:50:33 -0700342 auto hwmonFile = getFullHwmonFilePath(directory.string(),
343 "temp1", permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500344 if (pathStr.starts_with("/sys/bus/iio/devices"))
345 {
346 hwmonFile = pathStr;
347 }
Jason Ling100c20b2020-08-11 14:50:33 -0700348 if (hwmonFile)
349 {
350 sensor = std::make_shared<HwmonTempSensor>(
351 *hwmonFile, sensorType, objectServer, dbusConnection,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500352 io, sensorName, std::move(sensorThresholds),
353 thisSensorParameters, pollRate, *interfacePath,
354 readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700355 sensor->setupRead();
356 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800357 // Looking for keys like "Name1" for temp2_input,
358 // "Name2" for temp3_input, etc.
359 int i = 0;
360 while (true)
James Feistdf515152019-09-18 16:40:40 -0700361 {
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800362 ++i;
363 auto findKey =
Jason Ling8b8bcc82020-08-04 19:33:22 -0700364 baseConfigMap->find("Name" + std::to_string(i));
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800365 if (findKey == baseConfigMap->end())
366 {
367 break;
368 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800369 std::string sensorName =
370 std::get<std::string>(findKey->second);
Jason Ling100c20b2020-08-11 14:50:33 -0700371 hwmonFile = getFullHwmonFilePath(
372 directory.string(), "temp" + std::to_string(i + 1),
373 permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500374 if (pathStr.starts_with("/sys/bus/iio/devices"))
375 {
376 continue;
377 }
Jason Ling100c20b2020-08-11 14:50:33 -0700378 if (hwmonFile)
379 {
Matt Spinler5636d522021-03-17 14:52:18 -0500380 // To look up thresholds for these additional sensors,
381 // match on the Index property in the threshold data
382 // where the index comes from the sysfs file we're on,
383 // i.e. index = 2 for temp2_input.
384 int index = i + 1;
385 std::vector<thresholds::Threshold> thresholds;
386
387 if (!parseThresholdsFromConfig(*sensorData, thresholds,
388 nullptr, &index))
389 {
390 std::cerr << "error populating thresholds for "
391 << sensorName << " index " << index
392 << "\n";
393 }
394
Jason Ling100c20b2020-08-11 14:50:33 -0700395 auto& sensor = sensors[sensorName];
396 sensor = nullptr;
397 sensor = std::make_shared<HwmonTempSensor>(
398 *hwmonFile, sensorType, objectServer,
399 dbusConnection, io, sensorName,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500400 std::move(thresholds), thisSensorParameters,
401 pollRate, *interfacePath, readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700402 sensor->setupRead();
403 }
James Feistdf515152019-09-18 16:40:40 -0700404 }
James Feistdf515152019-09-18 16:40:40 -0700405 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700406 });
James Feistdf515152019-09-18 16:40:40 -0700407 getter->getConfiguration(
408 std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
James Feist6714a252018-09-10 15:26:18 -0700409}
410
Matt Spinler20bf2c12021-09-14 11:07:07 -0500411void interfaceRemoved(
412 sdbusplus::message::message& message,
413 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
414 sensors)
415{
416 if (message.is_method_error())
417 {
418 std::cerr << "interfacesRemoved callback method error\n";
419 return;
420 }
421
422 sdbusplus::message::object_path path;
423 std::vector<std::string> interfaces;
424
425 message.read(path, interfaces);
426
427 // If the xyz.openbmc_project.Confguration.X interface was removed
428 // for one or more sensors, delete those sensor objects.
429 auto sensorIt = sensors.begin();
430 while (sensorIt != sensors.end())
431 {
432 if ((sensorIt->second->configurationPath == path) &&
433 (std::find(interfaces.begin(), interfaces.end(),
434 sensorIt->second->objectType) != interfaces.end()))
435 {
436 sensorIt = sensors.erase(sensorIt);
437 }
438 else
439 {
440 sensorIt++;
441 }
442 }
443}
444
James Feistb6c0b912019-07-09 12:21:44 -0700445int main()
James Feist6714a252018-09-10 15:26:18 -0700446{
447 boost::asio::io_service io;
448 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
449 systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
450 sdbusplus::asio::object_server objectServer(systemBus);
Yong Lif3fd1912020-03-25 21:35:23 +0800451 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
James Feist6714a252018-09-10 15:26:18 -0700452 sensors;
453 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
James Feist5591cf082020-07-15 16:44:54 -0700454 auto sensorsChanged =
455 std::make_shared<boost::container::flat_set<std::string>>();
James Feist6714a252018-09-10 15:26:18 -0700456
457 io.post([&]() {
458 createSensors(io, objectServer, sensors, systemBus, nullptr);
459 });
460
461 boost::asio::deadline_timer filterTimer(io);
462 std::function<void(sdbusplus::message::message&)> eventHandler =
463 [&](sdbusplus::message::message& message) {
464 if (message.is_method_error())
465 {
466 std::cerr << "callback method error\n";
467 return;
468 }
469 sensorsChanged->insert(message.get_path());
470 // this implicitly cancels the timer
471 filterTimer.expires_from_now(boost::posix_time::seconds(1));
472
473 filterTimer.async_wait([&](const boost::system::error_code& ec) {
474 if (ec == boost::asio::error::operation_aborted)
475 {
476 /* we were canceled*/
477 return;
478 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700479 if (ec)
James Feist6714a252018-09-10 15:26:18 -0700480 {
481 std::cerr << "timer error\n";
482 return;
483 }
484 createSensors(io, objectServer, sensors, systemBus,
485 sensorsChanged);
486 });
487 };
488
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700489 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700490 {
491 auto match = std::make_unique<sdbusplus::bus::match::match>(
492 static_cast<sdbusplus::bus::bus&>(*systemBus),
493 "type='signal',member='PropertiesChanged',path_namespace='" +
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700494 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
James Feist6714a252018-09-10 15:26:18 -0700495 eventHandler);
496 matches.emplace_back(std::move(match));
497 }
498
Bruce Lee1263c3d2021-06-04 15:16:33 +0800499 setupManufacturingModeMatch(*systemBus);
Matt Spinler20bf2c12021-09-14 11:07:07 -0500500
501 // Watch for entity-manager to remove configuration interfaces
502 // so the corresponding sensors can be removed.
503 auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
504 static_cast<sdbusplus::bus::bus&>(*systemBus),
505 "type='signal',member='InterfacesRemoved',arg0path='" +
506 std::string(inventoryPath) + "/'",
507 [&sensors](sdbusplus::message::message& msg) {
508 interfaceRemoved(msg, sensors);
509 });
510
511 matches.emplace_back(std::move(ifaceRemovedMatch));
512
James Feist6714a252018-09-10 15:26:18 -0700513 io.run();
514}