blob: 83bb9b6c5d4d6827cf325cd286ec2780ce06806f [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 <PwmSensor.hpp>
18#include <TachSensor.hpp>
19#include <Utils.hpp>
20#include <VariantVisitors.hpp>
James Feist6714a252018-09-10 15:26:18 -070021#include <boost/algorithm/string/predicate.hpp>
22#include <boost/algorithm/string/replace.hpp>
Patrick Venture96e97db2019-10-31 13:44:38 -070023#include <boost/container/flat_map.hpp>
James Feist6714a252018-09-10 15:26:18 -070024#include <boost/container/flat_set.hpp>
25#include <boost/lexical_cast.hpp>
James Feist38fb5982020-05-28 10:09:54 -070026#include <sdbusplus/asio/connection.hpp>
27#include <sdbusplus/asio/object_server.hpp>
28#include <sdbusplus/bus/match.hpp>
29
30#include <array>
James Feist24f02f22019-04-15 11:05:39 -070031#include <filesystem>
James Feist6714a252018-09-10 15:26:18 -070032#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070033#include <functional>
34#include <memory>
35#include <optional>
James Feist6714a252018-09-10 15:26:18 -070036#include <regex>
Patrick Venture96e97db2019-10-31 13:44:38 -070037#include <string>
38#include <utility>
39#include <variant>
40#include <vector>
James Feist6714a252018-09-10 15:26:18 -070041
James Feistcf3bce62019-01-08 10:07:19 -080042namespace fs = std::filesystem;
James Feist3eb82622019-02-08 13:10:22 -080043
Yong Zhaoa3e8f2a2021-01-09 02:22:43 +000044// The following two structures need to be consistent
Brandon Kim66558232021-11-09 16:53:08 -080045static auto sensorTypes{std::to_array<const char*>(
46 {"xyz.openbmc_project.Configuration.AspeedFan",
47 "xyz.openbmc_project.Configuration.I2CFan",
48 "xyz.openbmc_project.Configuration.NuvotonFan"})};
Yong Zhaoa3e8f2a2021-01-09 02:22:43 +000049
50enum FanTypes
51{
52 aspeed = 0,
53 i2c,
54 nuvoton,
55 max,
56};
57
58static_assert(std::tuple_size<decltype(sensorTypes)>::value == FanTypes::max,
59 "sensorTypes element number is not equal to FanTypes number");
60
James Feistdc6c55f2018-10-31 12:53:20 -070061constexpr const char* redundancyConfiguration =
62 "xyz.openbmc_project.Configuration.FanRedundancy";
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070063static std::regex inputRegex(R"(fan(\d+)_input)");
James Feist6714a252018-09-10 15:26:18 -070064
James Feistdc6c55f2018-10-31 12:53:20 -070065// todo: power supply fan redundancy
James Feist7b18b1e2019-05-14 13:42:09 -070066std::optional<RedundancySensor> systemRedundancy;
James Feist95b079b2018-11-21 09:28:00 -080067
68FanTypes getFanType(const fs::path& parentPath)
69{
70 fs::path linkPath = parentPath / "device";
71 std::string canonical = fs::read_symlink(linkPath);
Potin Lai0b1ae9f2022-01-27 08:21:08 +080072 if (boost::ends_with(canonical, "pwm-tacho-controller") ||
73 boost::ends_with(canonical, "pwm_tach:tach"))
James Feist95b079b2018-11-21 09:28:00 -080074 {
75 return FanTypes::aspeed;
76 }
Potin Lai0b1ae9f2022-01-27 08:21:08 +080077 if (boost::ends_with(canonical, "pwm-fan-controller"))
Peter Lundgren8843b622019-09-12 10:33:41 -070078 {
79 return FanTypes::nuvoton;
80 }
James Feist95b079b2018-11-21 09:28:00 -080081 // todo: will we need to support other types?
82 return FanTypes::i2c;
83}
Jeff Linabf91de2020-12-23 10:55:42 +080084void enablePwm(const fs::path& filePath)
85{
86 std::fstream enableFile(filePath, std::ios::in | std::ios::out);
87 if (!enableFile.good())
88 {
89 std::cerr << "Error read/write " << filePath << "\n";
90 return;
91 }
James Feistdc6c55f2018-10-31 12:53:20 -070092
Jeff Linabf91de2020-12-23 10:55:42 +080093 std::string regulateMode;
94 std::getline(enableFile, regulateMode);
95 if (regulateMode == "0")
96 {
97 enableFile << 1;
98 }
99}
Howard Chiuddf25d12021-12-02 15:14:44 +0800100bool findPwmfanPath(unsigned int configPwmfanIndex, fs::path& pwmPath)
101{
102 /* Search PWM since pwm-fan had separated
103 * PWM from tach directory and 1 channel only*/
104 std::vector<fs::path> pwmfanPaths;
105 std::string pwnfanDevName("pwm-fan");
106
107 pwnfanDevName += std::to_string(configPwmfanIndex);
108
109 if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwmfanPaths))
110 {
111 std::cerr << "No PWMs are found!\n";
112 return false;
113 }
114 for (const auto& path : pwmfanPaths)
115 {
116 std::error_code ec;
117 fs::path link = fs::read_symlink(path.parent_path() / "device", ec);
118
119 if (ec)
120 {
121 std::cerr << "read_symlink() failed: " << ec.message() << " ("
122 << ec.value() << ")\n";
123 continue;
124 }
125
126 if (link.filename().string() == pwnfanDevName)
127 {
128 pwmPath = path;
129 return true;
130 }
131 }
132 return false;
133}
134bool findPwmPath(const fs::path& directory, unsigned int pwm, fs::path& pwmPath)
135{
136 std::error_code ec;
137
138 /* Assuming PWM file is appeared in the same directory as fanX_input */
139 auto path = directory / ("pwm" + std::to_string(pwm + 1));
140 bool exists = fs::exists(path, ec);
141
142 if (ec || !exists)
143 {
144 /* PWM file not exist or error happened */
145 if (ec)
146 {
147 std::cerr << "exists() failed: " << ec.message() << " ("
148 << ec.value() << ")\n";
149 }
150 /* try search form pwm-fanX directory */
151 return findPwmfanPath(pwm, pwmPath);
152 }
153
154 pwmPath = path;
155 return true;
156}
Kuiying Wangd5407412020-09-09 16:06:56 +0800157void createRedundancySensor(
158 const boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
159 sensors,
Ed Tanous8a57ec02020-10-09 12:46:52 -0700160 const std::shared_ptr<sdbusplus::asio::connection>& conn,
Kuiying Wangd5407412020-09-09 16:06:56 +0800161 sdbusplus::asio::object_server& objectServer)
162{
163
164 conn->async_method_call(
165 [&objectServer, &sensors](boost::system::error_code& ec,
Ed Tanous8a57ec02020-10-09 12:46:52 -0700166 const ManagedObjectType& managedObj) {
Ed Tanousbb679322022-05-16 16:10:00 -0700167 if (ec)
168 {
169 std::cerr << "Error calling entity manager \n";
170 return;
171 }
172 for (const auto& pathPair : managedObj)
173 {
174 for (const auto& interfacePair : pathPair.second)
Kuiying Wangd5407412020-09-09 16:06:56 +0800175 {
Ed Tanousbb679322022-05-16 16:10:00 -0700176 if (interfacePair.first == redundancyConfiguration)
Kuiying Wangd5407412020-09-09 16:06:56 +0800177 {
Ed Tanousbb679322022-05-16 16:10:00 -0700178 // currently only support one
179 auto findCount =
180 interfacePair.second.find("AllowedFailures");
181 if (findCount == interfacePair.second.end())
Kuiying Wangd5407412020-09-09 16:06:56 +0800182 {
Ed Tanousbb679322022-05-16 16:10:00 -0700183 std::cerr << "Malformed redundancy record \n";
Kuiying Wangd5407412020-09-09 16:06:56 +0800184 return;
185 }
Ed Tanousbb679322022-05-16 16:10:00 -0700186 std::vector<std::string> sensorList;
187
188 for (const auto& sensor : sensors)
189 {
190 sensorList.push_back(
191 "/xyz/openbmc_project/sensors/fan_tach/" +
192 sensor.second->name);
193 }
194 systemRedundancy.reset();
195 systemRedundancy.emplace(RedundancySensor(
196 std::get<uint64_t>(findCount->second), sensorList,
197 objectServer, pathPair.first));
198
199 return;
Kuiying Wangd5407412020-09-09 16:06:56 +0800200 }
201 }
Ed Tanousbb679322022-05-16 16:10:00 -0700202 }
Kuiying Wangd5407412020-09-09 16:06:56 +0800203 },
204 "xyz.openbmc_project.EntityManager", "/",
205 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
206}
207
James Feist6714a252018-09-10 15:26:18 -0700208void createSensors(
209 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
210 boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
211 tachSensors,
212 boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>&
213 pwmSensors,
214 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
James Feist5591cf082020-07-15 16:44:54 -0700215 const std::shared_ptr<boost::container::flat_set<std::string>>&
James Feistf27a55c2020-08-04 14:27:30 -0700216 sensorsChanged,
217 size_t retries = 0)
James Feist6714a252018-09-10 15:26:18 -0700218{
James Feistde5e9702019-09-18 16:13:02 -0700219 auto getter = std::make_shared<GetSensorConfiguration>(
220 dbusConnection,
Ed Tanous8a17c302021-09-02 15:07:11 -0700221 [&io, &objectServer, &tachSensors, &pwmSensors, &dbusConnection,
222 sensorsChanged](const ManagedObjectType& sensorConfigurations) {
Ed Tanousbb679322022-05-16 16:10:00 -0700223 bool firstScan = sensorsChanged == nullptr;
224 std::vector<fs::path> paths;
225 if (!findFiles(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
226 {
227 std::cerr << "No fan sensors in system\n";
228 return;
229 }
230
231 // iterate through all found fan sensors, and try to match them with
232 // configuration
233 for (const auto& path : paths)
234 {
235 std::smatch match;
236 std::string pathStr = path.string();
237
238 std::regex_search(pathStr, match, inputRegex);
239 std::string indexStr = *(match.begin() + 1);
240
241 fs::path directory = path.parent_path();
242 FanTypes fanType = getFanType(directory);
243
244 // convert to 0 based
245 size_t index = std::stoul(indexStr) - 1;
246
247 const char* baseType = nullptr;
248 const SensorData* sensorData = nullptr;
249 const std::string* interfacePath = nullptr;
250 const SensorBaseConfiguration* baseConfiguration = nullptr;
251 for (const std::pair<sdbusplus::message::object_path, SensorData>&
252 sensor : sensorConfigurations)
James Feist95b079b2018-11-21 09:28:00 -0800253 {
Ed Tanousbb679322022-05-16 16:10:00 -0700254 // find the base of the configuration to see if indexes
255 // match
256 auto sensorBaseFind = sensor.second.find(sensorTypes[fanType]);
257 if (sensorBaseFind == sensor.second.end())
James Feist95b079b2018-11-21 09:28:00 -0800258 {
Ed Tanousbb679322022-05-16 16:10:00 -0700259 continue;
260 }
261
262 baseConfiguration = &(*sensorBaseFind);
263 interfacePath = &(sensor.first.str);
264 baseType = sensorTypes[fanType];
265
266 auto findIndex = baseConfiguration->second.find("Index");
267 if (findIndex == baseConfiguration->second.end())
268 {
269 std::cerr << baseConfiguration->first << " missing index\n";
270 continue;
271 }
272 unsigned int configIndex = std::visit(
273 VariantToUnsignedIntVisitor(), findIndex->second);
274 if (configIndex != index)
275 {
276 continue;
277 }
278 if (fanType == FanTypes::aspeed || fanType == FanTypes::nuvoton)
279 {
280 // there will be only 1 aspeed or nuvoton sensor object
281 // in sysfs, we found the fan
282 sensorData = &(sensor.second);
283 break;
284 }
285 if (fanType == FanTypes::i2c)
286 {
287 size_t bus = 0;
288 size_t address = 0;
289
290 std::string link =
291 fs::read_symlink(directory / "device").filename();
292
293 size_t findDash = link.find('-');
294 if (findDash == std::string::npos ||
295 link.size() <= findDash + 1)
James Feistde5e9702019-09-18 16:13:02 -0700296 {
Ed Tanousbb679322022-05-16 16:10:00 -0700297 std::cerr << "Error finding device from symlink";
James Feistde5e9702019-09-18 16:13:02 -0700298 }
Ed Tanousbb679322022-05-16 16:10:00 -0700299 bus = std::stoi(link.substr(0, findDash));
300 address = std::stoi(link.substr(findDash + 1), nullptr, 16);
Zhikui Ren347dd4e2019-12-12 13:39:50 -0800301
Ed Tanousbb679322022-05-16 16:10:00 -0700302 auto findBus = baseConfiguration->second.find("Bus");
303 auto findAddress =
304 baseConfiguration->second.find("Address");
305 if (findBus == baseConfiguration->second.end() ||
306 findAddress == baseConfiguration->second.end())
James Feistde5e9702019-09-18 16:13:02 -0700307 {
308 std::cerr << baseConfiguration->first
Ed Tanousbb679322022-05-16 16:10:00 -0700309 << " missing bus or address\n";
James Feistde5e9702019-09-18 16:13:02 -0700310 continue;
311 }
Ed Tanousbb679322022-05-16 16:10:00 -0700312 unsigned int configBus = std::visit(
313 VariantToUnsignedIntVisitor(), findBus->second);
314 unsigned int configAddress = std::visit(
315 VariantToUnsignedIntVisitor(), findAddress->second);
316
317 if (configBus == bus && configAddress == address)
James Feistde5e9702019-09-18 16:13:02 -0700318 {
James Feistde5e9702019-09-18 16:13:02 -0700319 sensorData = &(sensor.second);
320 break;
321 }
Ed Tanousbb679322022-05-16 16:10:00 -0700322 }
323 }
324 if (sensorData == nullptr)
325 {
326 std::cerr << "failed to find match for " << path.string()
327 << "\n";
328 continue;
329 }
330
331 auto findSensorName = baseConfiguration->second.find("Name");
332
333 if (findSensorName == baseConfiguration->second.end())
334 {
335 std::cerr << "could not determine configuration name for "
336 << path.string() << "\n";
337 continue;
338 }
339 std::string sensorName =
340 std::get<std::string>(findSensorName->second);
341
342 // on rescans, only update sensors we were signaled by
343 auto findSensor = tachSensors.find(sensorName);
344 if (!firstScan && findSensor != tachSensors.end())
345 {
346 bool found = false;
347 for (auto it = sensorsChanged->begin();
348 it != sensorsChanged->end(); it++)
349 {
350 if (boost::ends_with(*it, findSensor->second->name))
James Feistde5e9702019-09-18 16:13:02 -0700351 {
Ed Tanousbb679322022-05-16 16:10:00 -0700352 sensorsChanged->erase(it);
353 findSensor->second = nullptr;
354 found = true;
355 break;
James Feistde5e9702019-09-18 16:13:02 -0700356 }
357 }
Ed Tanousbb679322022-05-16 16:10:00 -0700358 if (!found)
James Feistde5e9702019-09-18 16:13:02 -0700359 {
James Feist95b079b2018-11-21 09:28:00 -0800360 continue;
361 }
Ed Tanousbb679322022-05-16 16:10:00 -0700362 }
363 std::vector<thresholds::Threshold> sensorThresholds;
364 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
365 {
366 std::cerr << "error populating thresholds for " << sensorName
367 << "\n";
368 }
James Feist95b079b2018-11-21 09:28:00 -0800369
Ed Tanousbb679322022-05-16 16:10:00 -0700370 auto presenceConfig =
371 sensorData->find(baseType + std::string(".Presence"));
Zhikui Ren347dd4e2019-12-12 13:39:50 -0800372
Ed Tanousbb679322022-05-16 16:10:00 -0700373 std::unique_ptr<PresenceSensor> presenceSensor(nullptr);
374
375 // presence sensors are optional
376 if (presenceConfig != sensorData->end())
377 {
378 auto findPolarity = presenceConfig->second.find("Polarity");
379 auto findPinName = presenceConfig->second.find("PinName");
380
381 if (findPinName == presenceConfig->second.end() ||
382 findPolarity == presenceConfig->second.end())
James Feist95b079b2018-11-21 09:28:00 -0800383 {
Ed Tanousbb679322022-05-16 16:10:00 -0700384 std::cerr << "Malformed Presence Configuration\n";
James Feistde5e9702019-09-18 16:13:02 -0700385 }
Ed Tanousbb679322022-05-16 16:10:00 -0700386 else
James Feistde5e9702019-09-18 16:13:02 -0700387 {
Ed Tanousbb679322022-05-16 16:10:00 -0700388 bool inverted =
389 std::get<std::string>(findPolarity->second) == "Low";
390 if (auto pinName =
391 std::get_if<std::string>(&findPinName->second))
James Feistde5e9702019-09-18 16:13:02 -0700392 {
Ed Tanousbb679322022-05-16 16:10:00 -0700393 presenceSensor = std::make_unique<PresenceSensor>(
394 *pinName, inverted, io, sensorName);
James Feistde5e9702019-09-18 16:13:02 -0700395 }
396 else
397 {
Ed Tanousbb679322022-05-16 16:10:00 -0700398 std::cerr << "Malformed Presence pinName for sensor "
399 << sensorName << " \n";
James Feistde5e9702019-09-18 16:13:02 -0700400 }
401 }
Ed Tanousbb679322022-05-16 16:10:00 -0700402 }
403 std::optional<RedundancySensor>* redundancy = nullptr;
404 if (fanType == FanTypes::aspeed)
405 {
406 redundancy = &systemRedundancy;
407 }
408
409 PowerState powerState = PowerState::on;
410 auto findPower = baseConfiguration->second.find("PowerState");
411 if (findPower != baseConfiguration->second.end())
412 {
413 auto ptrPower = std::get_if<std::string>(&(findPower->second));
414 if (ptrPower)
James Feistde5e9702019-09-18 16:13:02 -0700415 {
Ed Tanousbb679322022-05-16 16:10:00 -0700416 setReadState(*ptrPower, powerState);
Yong Zhao77b3add2021-01-09 04:25:18 +0000417 }
James Feist95b079b2018-11-21 09:28:00 -0800418 }
Yong Zhao77b3add2021-01-09 04:25:18 +0000419
Ed Tanousbb679322022-05-16 16:10:00 -0700420 constexpr double defaultMaxReading = 25000;
421 constexpr double defaultMinReading = 0;
422 std::pair<double, double> limits =
423 std::make_pair(defaultMinReading, defaultMaxReading);
424
425 auto connector =
426 sensorData->find(baseType + std::string(".Connector"));
427
428 std::optional<std::string> led;
429 std::string pwmName;
430 fs::path pwmPath;
431
432 // The Mutable parameter is optional, defaulting to false
433 bool isValueMutable = false;
434 if (connector != sensorData->end())
435 {
436 auto findPwm = connector->second.find("Pwm");
437 if (findPwm != connector->second.end())
438 {
439 size_t pwm = std::visit(VariantToUnsignedIntVisitor(),
440 findPwm->second);
441 if (!findPwmPath(directory, pwm, pwmPath))
442 {
443 std::cerr << "Connector for " << sensorName
444 << " no pwm channel found!\n";
445 continue;
446 }
447
448 fs::path pwmEnableFile =
449 "pwm" + std::to_string(pwm + 1) + "_enable";
450 fs::path enablePath = pwmPath.parent_path() / pwmEnableFile;
451 enablePwm(enablePath);
452
453 /* use pwm name override if found in configuration else
454 * use default */
455 auto findOverride = connector->second.find("PwmName");
456 if (findOverride != connector->second.end())
457 {
458 pwmName = std::visit(VariantToStringVisitor(),
459 findOverride->second);
460 }
461 else
462 {
463 pwmName = "Pwm_" + std::to_string(pwm + 1);
464 }
465
466 // Check PWM sensor mutability
467 auto findMutable = connector->second.find("Mutable");
468 if (findMutable != connector->second.end())
469 {
470 auto ptrMutable =
471 std::get_if<bool>(&(findMutable->second));
472 if (ptrMutable)
473 {
474 isValueMutable = *ptrMutable;
475 }
476 }
477 }
478 else
479 {
480 std::cerr << "Connector for " << sensorName
481 << " missing pwm!\n";
482 }
483
484 auto findLED = connector->second.find("LED");
485 if (findLED != connector->second.end())
486 {
487 auto ledName = std::get_if<std::string>(&(findLED->second));
488 if (ledName == nullptr)
489 {
490 std::cerr << "Wrong format for LED of " << sensorName
491 << "\n";
492 }
493 else
494 {
495 led = *ledName;
496 }
497 }
498 }
499
500 findLimits(limits, baseConfiguration);
501 tachSensors[sensorName] = std::make_unique<TachSensor>(
502 path.string(), baseType, objectServer, dbusConnection,
503 std::move(presenceSensor), redundancy, io, sensorName,
504 std::move(sensorThresholds), *interfacePath, limits, powerState,
505 led);
506
507 if (!pwmPath.empty() && fs::exists(pwmPath) &&
508 !pwmSensors.count(pwmPath))
509 {
510 pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
511 pwmName, pwmPath, dbusConnection, objectServer,
512 *interfacePath, "Fan", isValueMutable);
513 }
514 }
515
516 createRedundancySensor(tachSensors, dbusConnection, objectServer);
Ed Tanous8a17c302021-09-02 15:07:11 -0700517 });
James Feistde5e9702019-09-18 16:13:02 -0700518 getter->getConfiguration(
James Feistf27a55c2020-08-04 14:27:30 -0700519 std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()},
520 retries);
James Feist6714a252018-09-10 15:26:18 -0700521}
522
James Feistb6c0b912019-07-09 12:21:44 -0700523int main()
James Feist6714a252018-09-10 15:26:18 -0700524{
525 boost::asio::io_service io;
526 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
527 systemBus->request_name("xyz.openbmc_project.FanSensor");
528 sdbusplus::asio::object_server objectServer(systemBus);
529 boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>
530 tachSensors;
531 boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
532 pwmSensors;
533 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
James Feist5591cf082020-07-15 16:44:54 -0700534 auto sensorsChanged =
535 std::make_shared<boost::container::flat_set<std::string>>();
James Feist6714a252018-09-10 15:26:18 -0700536
537 io.post([&]() {
538 createSensors(io, objectServer, tachSensors, pwmSensors, systemBus,
539 nullptr);
540 });
541
542 boost::asio::deadline_timer filterTimer(io);
543 std::function<void(sdbusplus::message::message&)> eventHandler =
544 [&](sdbusplus::message::message& message) {
Ed Tanousbb679322022-05-16 16:10:00 -0700545 if (message.is_method_error())
546 {
547 std::cerr << "callback method error\n";
548 return;
549 }
550 sensorsChanged->insert(message.get_path());
551 // this implicitly cancels the timer
552 filterTimer.expires_from_now(boost::posix_time::seconds(1));
553
554 filterTimer.async_wait([&](const boost::system::error_code& ec) {
555 if (ec == boost::asio::error::operation_aborted)
James Feist6714a252018-09-10 15:26:18 -0700556 {
Ed Tanousbb679322022-05-16 16:10:00 -0700557 /* we were canceled*/
James Feist6714a252018-09-10 15:26:18 -0700558 return;
559 }
Ed Tanousbb679322022-05-16 16:10:00 -0700560 if (ec)
561 {
562 std::cerr << "timer error\n";
563 return;
564 }
565 createSensors(io, objectServer, tachSensors, pwmSensors, systemBus,
566 sensorsChanged, 5);
567 });
568 };
James Feist6714a252018-09-10 15:26:18 -0700569
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700570 for (const char* type : sensorTypes)
James Feist6714a252018-09-10 15:26:18 -0700571 {
572 auto match = std::make_unique<sdbusplus::bus::match::match>(
573 static_cast<sdbusplus::bus::bus&>(*systemBus),
574 "type='signal',member='PropertiesChanged',path_namespace='" +
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -0700575 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
James Feist6714a252018-09-10 15:26:18 -0700576 eventHandler);
577 matches.emplace_back(std::move(match));
578 }
579
James Feistdc6c55f2018-10-31 12:53:20 -0700580 // redundancy sensor
581 std::function<void(sdbusplus::message::message&)> redundancyHandler =
582 [&tachSensors, &systemBus,
James Feistb6c0b912019-07-09 12:21:44 -0700583 &objectServer](sdbusplus::message::message&) {
Ed Tanousbb679322022-05-16 16:10:00 -0700584 createRedundancySensor(tachSensors, systemBus, objectServer);
585 };
James Feistdc6c55f2018-10-31 12:53:20 -0700586 auto match = std::make_unique<sdbusplus::bus::match::match>(
587 static_cast<sdbusplus::bus::bus&>(*systemBus),
588 "type='signal',member='PropertiesChanged',path_namespace='" +
589 std::string(inventoryPath) + "',arg0namespace='" +
590 redundancyConfiguration + "'",
James Feistb6c0b912019-07-09 12:21:44 -0700591 std::move(redundancyHandler));
James Feistdc6c55f2018-10-31 12:53:20 -0700592 matches.emplace_back(std::move(match));
593
Bruce Lee1263c3d2021-06-04 15:16:33 +0800594 setupManufacturingModeMatch(*systemBus);
James Feist6714a252018-09-10 15:26:18 -0700595 io.run();
Zhikui Ren8685b172021-06-29 15:16:52 -0700596 return 0;
James Feist6714a252018-09-10 15:26:18 -0700597}