blob: 670947ba020b6ebf9c3acca1cac7d5e867931f8e [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 std::cerr << "failed to find match for " << deviceName
268 << "\n";
269 continue;
James Feist6714a252018-09-10 15:26:18 -0700270 }
James Feist6714a252018-09-10 15:26:18 -0700271
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500272 // Temperature has "Name", pressure has "Name1"
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800273 auto findSensorName = baseConfigMap->find("Name");
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500274 if (thisSensorParameters.typeName == "pressure")
275 {
276 findSensorName = baseConfigMap->find("Name1");
277 }
278
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800279 if (findSensorName == baseConfigMap->end())
James Feistdf515152019-09-18 16:40:40 -0700280 {
281 std::cerr << "could not determine configuration name for "
282 << deviceName << "\n";
283 continue;
284 }
285 std::string sensorName =
286 std::get<std::string>(findSensorName->second);
287 // on rescans, only update sensors we were signaled by
288 auto findSensor = sensors.find(sensorName);
289 if (!firstScan && findSensor != sensors.end())
290 {
291 bool found = false;
Bruce Mitchelld653b752021-08-23 13:09:00 -0500292 auto it = sensorsChanged->begin();
293 while (it != sensorsChanged->end())
James Feistdf515152019-09-18 16:40:40 -0700294 {
295 if (boost::ends_with(*it, findSensor->second->name))
296 {
Bruce Mitchelld653b752021-08-23 13:09:00 -0500297 it = sensorsChanged->erase(it);
James Feistdf515152019-09-18 16:40:40 -0700298 findSensor->second = nullptr;
299 found = true;
300 break;
301 }
Bruce Mitchelld653b752021-08-23 13:09:00 -0500302 ++it;
James Feistdf515152019-09-18 16:40:40 -0700303 }
304 if (!found)
305 {
306 continue;
307 }
308 }
Matt Spinler5636d522021-03-17 14:52:18 -0500309
James Feistdf515152019-09-18 16:40:40 -0700310 std::vector<thresholds::Threshold> sensorThresholds;
Matt Spinler5636d522021-03-17 14:52:18 -0500311 int index = 1;
312
313 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
314 nullptr, &index))
James Feistdf515152019-09-18 16:40:40 -0700315 {
316 std::cerr << "error populating thresholds for "
Matt Spinler5636d522021-03-17 14:52:18 -0500317 << sensorName << " index 1\n";
James Feistdf515152019-09-18 16:40:40 -0700318 }
Jeff Lin87bc67f2020-12-04 20:58:01 +0800319
320 auto findPollRate = baseConfiguration->second.find("PollRate");
321 float pollRate = pollRateDefault;
322 if (findPollRate != baseConfiguration->second.end())
323 {
324 pollRate = std::visit(VariantToFloatVisitor(),
325 findPollRate->second);
326 if (pollRate <= 0.0f)
327 {
328 pollRate = pollRateDefault; // polling time too short
329 }
330 }
331
James Feistf9b01b62020-01-29 15:21:58 -0800332 auto findPowerOn = baseConfiguration->second.find("PowerState");
333 PowerState readState = PowerState::always;
334 if (findPowerOn != baseConfiguration->second.end())
335 {
336 std::string powerState = std::visit(
337 VariantToStringVisitor(), findPowerOn->second);
338 setReadState(powerState, readState);
339 }
Jason Ling100c20b2020-08-11 14:50:33 -0700340
341 auto permitSet = getPermitSet(*baseConfigMap);
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800342 auto& sensor = sensors[sensorName];
343 sensor = nullptr;
Jason Ling100c20b2020-08-11 14:50:33 -0700344 auto hwmonFile = getFullHwmonFilePath(directory.string(),
345 "temp1", permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500346 if (pathStr.starts_with("/sys/bus/iio/devices"))
347 {
348 hwmonFile = pathStr;
349 }
Jason Ling100c20b2020-08-11 14:50:33 -0700350 if (hwmonFile)
351 {
352 sensor = std::make_shared<HwmonTempSensor>(
353 *hwmonFile, sensorType, objectServer, dbusConnection,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500354 io, sensorName, std::move(sensorThresholds),
355 thisSensorParameters, pollRate, *interfacePath,
356 readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700357 sensor->setupRead();
358 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800359 // Looking for keys like "Name1" for temp2_input,
360 // "Name2" for temp3_input, etc.
361 int i = 0;
362 while (true)
James Feistdf515152019-09-18 16:40:40 -0700363 {
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800364 ++i;
365 auto findKey =
Jason Ling8b8bcc82020-08-04 19:33:22 -0700366 baseConfigMap->find("Name" + std::to_string(i));
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800367 if (findKey == baseConfigMap->end())
368 {
369 break;
370 }
Alex Qiu8b3f7d42020-01-06 13:54:42 -0800371 std::string sensorName =
372 std::get<std::string>(findKey->second);
Jason Ling100c20b2020-08-11 14:50:33 -0700373 hwmonFile = getFullHwmonFilePath(
374 directory.string(), "temp" + std::to_string(i + 1),
375 permitSet);
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500376 if (pathStr.starts_with("/sys/bus/iio/devices"))
377 {
378 continue;
379 }
Jason Ling100c20b2020-08-11 14:50:33 -0700380 if (hwmonFile)
381 {
Matt Spinler5636d522021-03-17 14:52:18 -0500382 // To look up thresholds for these additional sensors,
383 // match on the Index property in the threshold data
384 // where the index comes from the sysfs file we're on,
385 // i.e. index = 2 for temp2_input.
386 int index = i + 1;
387 std::vector<thresholds::Threshold> thresholds;
388
389 if (!parseThresholdsFromConfig(*sensorData, thresholds,
390 nullptr, &index))
391 {
392 std::cerr << "error populating thresholds for "
393 << sensorName << " index " << index
394 << "\n";
395 }
396
Jason Ling100c20b2020-08-11 14:50:33 -0700397 auto& sensor = sensors[sensorName];
398 sensor = nullptr;
399 sensor = std::make_shared<HwmonTempSensor>(
400 *hwmonFile, sensorType, objectServer,
401 dbusConnection, io, sensorName,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -0500402 std::move(thresholds), thisSensorParameters,
403 pollRate, *interfacePath, readState);
Jason Ling100c20b2020-08-11 14:50:33 -0700404 sensor->setupRead();
405 }
James Feistdf515152019-09-18 16:40:40 -0700406 }
James Feistdf515152019-09-18 16:40:40 -0700407 }
Ed Tanous8a17c302021-09-02 15:07:11 -0700408 });
James Feistdf515152019-09-18 16:40:40 -0700409 getter->getConfiguration(
410 std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
James Feist6714a252018-09-10 15:26:18 -0700411}
412
Matt Spinler20bf2c12021-09-14 11:07:07 -0500413void interfaceRemoved(
414 sdbusplus::message::message& message,
415 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>&
416 sensors)
417{
418 if (message.is_method_error())
419 {
420 std::cerr << "interfacesRemoved callback method error\n";
421 return;
422 }
423
424 sdbusplus::message::object_path path;
425 std::vector<std::string> interfaces;
426
427 message.read(path, interfaces);
428
429 // If the xyz.openbmc_project.Confguration.X interface was removed
430 // for one or more sensors, delete those sensor objects.
431 auto sensorIt = sensors.begin();
432 while (sensorIt != sensors.end())
433 {
434 if ((sensorIt->second->configurationPath == path) &&
435 (std::find(interfaces.begin(), interfaces.end(),
436 sensorIt->second->objectType) != interfaces.end()))
437 {
438 sensorIt = sensors.erase(sensorIt);
439 }
440 else
441 {
442 sensorIt++;
443 }
444 }
445}
446
James Feistb6c0b912019-07-09 12:21:44 -0700447int main()
James Feist6714a252018-09-10 15:26:18 -0700448{
449 boost::asio::io_service io;
450 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
451 systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
452 sdbusplus::asio::object_server objectServer(systemBus);
Yong Lif3fd1912020-03-25 21:35:23 +0800453 boost::container::flat_map<std::string, std::shared_ptr<HwmonTempSensor>>
James Feist6714a252018-09-10 15:26:18 -0700454 sensors;
455 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
James Feist5591cf082020-07-15 16:44:54 -0700456 auto sensorsChanged =
457 std::make_shared<boost::container::flat_set<std::string>>();
James Feist6714a252018-09-10 15:26:18 -0700458
459 io.post([&]() {
460 createSensors(io, objectServer, sensors, systemBus, nullptr);
461 });
462
463 boost::asio::deadline_timer filterTimer(io);
464 std::function<void(sdbusplus::message::message&)> eventHandler =
465 [&](sdbusplus::message::message& message) {
466 if (message.is_method_error())
467 {
468 std::cerr << "callback method error\n";
469 return;
470 }
471 sensorsChanged->insert(message.get_path());
472 // this implicitly cancels the timer
473 filterTimer.expires_from_now(boost::posix_time::seconds(1));
474
475 filterTimer.async_wait([&](const boost::system::error_code& ec) {
476 if (ec == boost::asio::error::operation_aborted)
477 {
478 /* we were canceled*/
479 return;
480 }
Ed Tanous8a57ec02020-10-09 12:46:52 -0700481 if (ec)
James Feist6714a252018-09-10 15:26:18 -0700482 {
483 std::cerr << "timer error\n";
484 return;
485 }
486 createSensors(io, objectServer, sensors, systemBus,
487 sensorsChanged);
488 });
489 };
490
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700491 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700492 {
493 auto match = std::make_unique<sdbusplus::bus::match::match>(
494 static_cast<sdbusplus::bus::bus&>(*systemBus),
495 "type='signal',member='PropertiesChanged',path_namespace='" +
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700496 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
James Feist6714a252018-09-10 15:26:18 -0700497 eventHandler);
498 matches.emplace_back(std::move(match));
499 }
500
Bruce Lee1263c3d2021-06-04 15:16:33 +0800501 setupManufacturingModeMatch(*systemBus);
Matt Spinler20bf2c12021-09-14 11:07:07 -0500502
503 // Watch for entity-manager to remove configuration interfaces
504 // so the corresponding sensors can be removed.
505 auto ifaceRemovedMatch = std::make_unique<sdbusplus::bus::match::match>(
506 static_cast<sdbusplus::bus::bus&>(*systemBus),
507 "type='signal',member='InterfacesRemoved',arg0path='" +
508 std::string(inventoryPath) + "/'",
509 [&sensors](sdbusplus::message::message& msg) {
510 interfaceRemoved(msg, sensors);
511 });
512
513 matches.emplace_back(std::move(ifaceRemovedMatch));
514
James Feist6714a252018-09-10 15:26:18 -0700515 io.run();
516}