blob: b8966a69f379ae2289944685cd65a7908df4e08f [file] [log] [blame]
Cheng C Yang209ec562019-03-12 16:37:44 +08001/*
2// Copyright (c) 2019 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*/
Josh Lehan0830c7b2019-10-08 16:35:09 -070016
Patrick Ventureca44b2f2019-10-31 11:02:26 -070017#include "PSUEvent.hpp"
18#include "PSUSensor.hpp"
19#include "Utils.hpp"
20
Cheng C Yang209ec562019-03-12 16:37:44 +080021#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>
Cheng C Yang209ec562019-03-12 16:37:44 +080024#include <boost/container/flat_set.hpp>
James Feist38fb5982020-05-28 10:09:54 -070025#include <sdbusplus/asio/connection.hpp>
26#include <sdbusplus/asio/object_server.hpp>
27#include <sdbusplus/bus/match.hpp>
28
29#include <array>
Josh Lehan74d9bd92019-10-31 08:51:58 -070030#include <cmath>
James Feist24f02f22019-04-15 11:05:39 -070031#include <filesystem>
Cheng C Yang209ec562019-03-12 16:37:44 +080032#include <fstream>
Patrick Venture96e97db2019-10-31 13:44:38 -070033#include <functional>
Cheng C Yang58b2b532019-05-31 00:19:45 +080034#include <iostream>
Cheng C Yang209ec562019-03-12 16:37:44 +080035#include <regex>
Patrick Venture96e97db2019-10-31 13:44:38 -070036#include <string>
37#include <utility>
38#include <variant>
39#include <vector>
Cheng C Yang209ec562019-03-12 16:37:44 +080040
Josh Lehan49cfba92019-10-08 16:50:42 -070041static constexpr bool DEBUG = false;
42
Gaurav Gandhi49585582020-12-22 01:01:24 +000043static constexpr std::array<const char*, 17> sensorTypes = {
Josh Lehan62084c82020-06-22 15:27:12 -070044 "xyz.openbmc_project.Configuration.ADM1272",
45 "xyz.openbmc_project.Configuration.ADM1278",
46 "xyz.openbmc_project.Configuration.INA219",
Devjit Gopalpurde65ef72019-10-30 04:47:35 -070047 "xyz.openbmc_project.Configuration.INA230",
Alex Qiu6690d8f2020-01-22 17:56:33 -080048 "xyz.openbmc_project.Configuration.ISL68137",
Jason Lingdfad1ff2020-07-29 15:43:11 -070049 "xyz.openbmc_project.Configuration.ISL68220",
Gaurav Gandhi49585582020-12-22 01:01:24 +000050 "xyz.openbmc_project.Configuration.ISL68223",
51 "xyz.openbmc_project.Configuration.ISL69243",
Alex Qiuf5709b42020-01-29 13:29:50 -080052 "xyz.openbmc_project.Configuration.MAX16601",
Gaurav Gandhi49585582020-12-22 01:01:24 +000053 "xyz.openbmc_project.Configuration.MAX20710",
Alex Qiu6690d8f2020-01-22 17:56:33 -080054 "xyz.openbmc_project.Configuration.MAX20730",
55 "xyz.openbmc_project.Configuration.MAX20734",
56 "xyz.openbmc_project.Configuration.MAX20796",
57 "xyz.openbmc_project.Configuration.MAX34451",
Josh Lehan62084c82020-06-22 15:27:12 -070058 "xyz.openbmc_project.Configuration.pmbus",
59 "xyz.openbmc_project.Configuration.PXE1610",
60 "xyz.openbmc_project.Configuration.RAA228228"};
Cheng C Yang209ec562019-03-12 16:37:44 +080061
Alex Qiu6690d8f2020-01-22 17:56:33 -080062static std::vector<std::string> pmbusNames = {
Gaurav Gandhi49585582020-12-22 01:01:24 +000063 "adm1272", "adm1278", "ina219", "ina230", "isl68137", "isl68220",
64 "isl68223", "isl69243", "max16601", "max20710", "max20730", "max20734",
65 "max20796", "max34451", "pmbus", "pxe1610", "raa228228"};
Josh Lehan0830c7b2019-10-08 16:35:09 -070066
Cheng C Yang209ec562019-03-12 16:37:44 +080067namespace fs = std::filesystem;
68
Yong Libf8b1da2020-04-15 16:32:50 +080069static boost::container::flat_map<std::string, std::shared_ptr<PSUSensor>>
Cheng C Yang916360b2019-05-07 18:47:16 +080070 sensors;
Cheng C Yang58b2b532019-05-31 00:19:45 +080071static boost::container::flat_map<std::string, std::unique_ptr<PSUCombineEvent>>
72 combineEvents;
Cheng C Yang916360b2019-05-07 18:47:16 +080073static boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
74 pwmSensors;
75static boost::container::flat_map<std::string, std::string> sensorTable;
76static boost::container::flat_map<std::string, PSUProperty> labelMatch;
77static boost::container::flat_map<std::string, std::string> pwmTable;
Cheng C Yang58b2b532019-05-31 00:19:45 +080078static boost::container::flat_map<std::string, std::vector<std::string>>
79 eventMatch;
Cheng C Yang202a1ff2020-01-09 09:34:22 +080080static boost::container::flat_map<
81 std::string,
82 boost::container::flat_map<std::string, std::vector<std::string>>>
83 groupEventMatch;
Cheng C Yang58b2b532019-05-31 00:19:45 +080084static boost::container::flat_map<std::string, std::vector<std::string>>
85 limitEventMatch;
86
Josh Lehan74d9bd92019-10-31 08:51:58 -070087static std::vector<PSUProperty> psuProperties;
88
Cheng C Yang58b2b532019-05-31 00:19:45 +080089// Function CheckEvent will check each attribute from eventMatch table in the
90// sysfs. If the attributes exists in sysfs, then store the complete path
91// of the attribute into eventPathList.
92void checkEvent(
93 const std::string& directory,
94 const boost::container::flat_map<std::string, std::vector<std::string>>&
95 eventMatch,
96 boost::container::flat_map<std::string, std::vector<std::string>>&
97 eventPathList)
98{
99 for (const auto& match : eventMatch)
100 {
101 const std::vector<std::string>& eventAttrs = match.second;
102 const std::string& eventName = match.first;
103 for (const auto& eventAttr : eventAttrs)
104 {
105 auto eventPath = directory + "/" + eventAttr;
106
107 std::ifstream eventFile(eventPath);
108 if (!eventFile.good())
109 {
110 continue;
111 }
112
113 eventPathList[eventName].push_back(eventPath);
114 }
115 }
116}
117
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800118// Check Group Events which contains more than one targets in each combine
119// events.
120void checkGroupEvent(
121 const std::string& directory,
122 const boost::container::flat_map<
123 std::string,
124 boost::container::flat_map<std::string, std::vector<std::string>>>&
125 groupEventMatch,
126 boost::container::flat_map<
127 std::string,
128 boost::container::flat_map<std::string, std::vector<std::string>>>&
129 groupEventPathList)
130{
131 for (const auto& match : groupEventMatch)
132 {
133 const std::string& groupEventName = match.first;
134 const boost::container::flat_map<std::string, std::vector<std::string>>
135 events = match.second;
136 boost::container::flat_map<std::string, std::vector<std::string>>
137 pathList;
138 for (const auto& match : events)
139 {
140 const std::string& eventName = match.first;
141 const std::vector<std::string>& eventAttrs = match.second;
142 for (const auto& eventAttr : eventAttrs)
143 {
144 auto eventPath = directory + "/" + eventAttr;
145 std::ifstream eventFile(eventPath);
146 if (!eventFile.good())
147 {
148 continue;
149 }
150
151 pathList[eventName].push_back(eventPath);
152 }
153 }
154 groupEventPathList[groupEventName] = pathList;
155 }
156}
157
Cheng C Yang58b2b532019-05-31 00:19:45 +0800158// Function checkEventLimits will check all the psu related xxx_input attributes
159// in sysfs to see if xxx_crit_alarm xxx_lcrit_alarm xxx_max_alarm
160// xxx_min_alarm exist, then store the existing paths of the alarm attributes
161// to eventPathList.
162void checkEventLimits(
163 const std::string& sensorPathStr,
164 const boost::container::flat_map<std::string, std::vector<std::string>>&
165 limitEventMatch,
166 boost::container::flat_map<std::string, std::vector<std::string>>&
167 eventPathList)
168{
169 for (const auto& limitMatch : limitEventMatch)
170 {
171 const std::vector<std::string>& limitEventAttrs = limitMatch.second;
172 const std::string& eventName = limitMatch.first;
173 for (const auto& limitEventAttr : limitEventAttrs)
174 {
175 auto limitEventPath =
176 boost::replace_all_copy(sensorPathStr, "input", limitEventAttr);
177 std::ifstream eventFile(limitEventPath);
178 if (!eventFile.good())
179 {
180 continue;
181 }
182 eventPathList[eventName].push_back(limitEventPath);
183 }
184 }
185}
Cheng C Yang916360b2019-05-07 18:47:16 +0800186
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530187static void
188 checkPWMSensor(const fs::path& sensorPath, std::string& labelHead,
189 const std::string& interfacePath,
190 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
191 sdbusplus::asio::object_server& objectServer,
192 const std::string& psuName)
Cheng C Yang916360b2019-05-07 18:47:16 +0800193{
194 for (const auto& pwmName : pwmTable)
195 {
196 if (pwmName.first != labelHead)
197 {
198 continue;
199 }
200
201 const std::string& sensorPathStr = sensorPath.string();
202 const std::string& pwmPathStr =
203 boost::replace_all_copy(sensorPathStr, "input", "target");
204 std::ifstream pwmFile(pwmPathStr);
205 if (!pwmFile.good())
206 {
207 continue;
208 }
209
210 auto findPWMSensor = pwmSensors.find(psuName + labelHead);
211 if (findPWMSensor != pwmSensors.end())
212 {
213 continue;
214 }
215
216 pwmSensors[psuName + labelHead] = std::make_unique<PwmSensor>(
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530217 "Pwm_" + psuName + "_" + pwmName.second, pwmPathStr, dbusConnection,
218 objectServer, interfacePath + "_" + pwmName.second, "PSU");
Cheng C Yang916360b2019-05-07 18:47:16 +0800219 }
220}
221
Zhikui Ren23c96e72020-11-05 22:32:28 -0800222static void createSensorsCallback(
223 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
224 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
225 const ManagedObjectType& sensorConfigs,
226 const std::shared_ptr<boost::container::flat_set<std::string>>&
227 sensorsChanged)
Cheng C Yang209ec562019-03-12 16:37:44 +0800228{
Josh Lehan49cfba92019-10-08 16:50:42 -0700229 int numCreated = 0;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800230 bool firstScan = sensorsChanged == nullptr;
Cheng C Yang209ec562019-03-12 16:37:44 +0800231
232 std::vector<fs::path> pmbusPaths;
233 if (!findFiles(fs::path("/sys/class/hwmon"), "name", pmbusPaths))
234 {
235 std::cerr << "No PSU sensors in system\n";
236 return;
237 }
238
239 boost::container::flat_set<std::string> directories;
240 for (const auto& pmbusPath : pmbusPaths)
241 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800242 boost::container::flat_map<std::string, std::vector<std::string>>
243 eventPathList;
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800244 boost::container::flat_map<
245 std::string,
246 boost::container::flat_map<std::string, std::vector<std::string>>>
247 groupEventPathList;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800248
249 std::ifstream nameFile(pmbusPath);
250 if (!nameFile.good())
251 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700252 std::cerr << "Failure finding pmbus path " << pmbusPath << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800253 continue;
254 }
255
256 std::string pmbusName;
257 std::getline(nameFile, pmbusName);
258 nameFile.close();
Vijay Khemka996bad12019-05-28 15:15:16 -0700259
260 if (std::find(pmbusNames.begin(), pmbusNames.end(), pmbusName) ==
261 pmbusNames.end())
Cheng C Yang58b2b532019-05-31 00:19:45 +0800262 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700263 // To avoid this error message, add your driver name to
264 // the pmbusNames vector at the top of this file.
265 std::cerr << "Driver name " << pmbusName
266 << " not found in sensor whitelist\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800267 continue;
268 }
269
270 const std::string* psuName;
Cheng C Yang209ec562019-03-12 16:37:44 +0800271 auto directory = pmbusPath.parent_path();
272
273 auto ret = directories.insert(directory.string());
274 if (!ret.second)
275 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700276 std::cerr << "Duplicate path " << directory.string() << "\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800277 continue; // check if path has already been searched
Cheng C Yang209ec562019-03-12 16:37:44 +0800278 }
279
James Feistb6c0b912019-07-09 12:21:44 -0700280 fs::path device = directory / "device";
Cheng C Yang209ec562019-03-12 16:37:44 +0800281 std::string deviceName = fs::canonical(device).stem();
282 auto findHyphen = deviceName.find("-");
283 if (findHyphen == std::string::npos)
284 {
285 std::cerr << "found bad device" << deviceName << "\n";
286 continue;
287 }
288 std::string busStr = deviceName.substr(0, findHyphen);
289 std::string addrStr = deviceName.substr(findHyphen + 1);
290
291 size_t bus = 0;
292 size_t addr = 0;
293
294 try
295 {
296 bus = std::stoi(busStr);
297 addr = std::stoi(addrStr, 0, 16);
298 }
James Feistb6c0b912019-07-09 12:21:44 -0700299 catch (std::invalid_argument&)
Cheng C Yang209ec562019-03-12 16:37:44 +0800300 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700301 std::cerr << "Error parsing bus " << busStr << " addr " << addrStr
302 << "\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800303 continue;
304 }
305
Cheng C Yang209ec562019-03-12 16:37:44 +0800306 const std::pair<std::string, boost::container::flat_map<
307 std::string, BasicVariantType>>*
308 baseConfig = nullptr;
309 const SensorData* sensorData = nullptr;
310 const std::string* interfacePath = nullptr;
311 const char* sensorType = nullptr;
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800312 size_t thresholdConfSize = 0;
Cheng C Yang209ec562019-03-12 16:37:44 +0800313
314 for (const std::pair<sdbusplus::message::object_path, SensorData>&
315 sensor : sensorConfigs)
316 {
317 sensorData = &(sensor.second);
318 for (const char* type : sensorTypes)
319 {
320 auto sensorBase = sensorData->find(type);
321 if (sensorBase != sensorData->end())
322 {
323 baseConfig = &(*sensorBase);
324 sensorType = type;
325 break;
326 }
327 }
328 if (baseConfig == nullptr)
329 {
330 std::cerr << "error finding base configuration for "
331 << deviceName << "\n";
332 continue;
333 }
334
335 auto configBus = baseConfig->second.find("Bus");
336 auto configAddress = baseConfig->second.find("Address");
337
338 if (configBus == baseConfig->second.end() ||
339 configAddress == baseConfig->second.end())
340 {
Cheng C Yang58b2b532019-05-31 00:19:45 +0800341 std::cerr << "error finding necessary entry in configuration\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800342 continue;
343 }
344
Cheng C Yang58b2b532019-05-31 00:19:45 +0800345 const uint64_t* confBus;
346 const uint64_t* confAddr;
347 if (!(confBus = std::get_if<uint64_t>(&(configBus->second))) ||
348 !(confAddr = std::get_if<uint64_t>(&(configAddress->second))))
349 {
350 std::cerr
Josh Lehan49cfba92019-10-08 16:50:42 -0700351 << "Cannot get bus or address, invalid configuration\n";
Cheng C Yang58b2b532019-05-31 00:19:45 +0800352 continue;
353 }
354
355 if ((*confBus != bus) || (*confAddr != addr))
Cheng C Yang209ec562019-03-12 16:37:44 +0800356 {
Josh Lehan432d1ed2019-10-16 12:23:31 -0700357 std::cerr << "Configuration skipping " << *confBus << "-"
358 << *confAddr << " because not " << bus << "-" << addr
359 << "\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800360 continue;
361 }
362
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800363 std::vector<thresholds::Threshold> confThresholds;
364 if (!parseThresholdsFromConfig(*sensorData, confThresholds))
365 {
366 std::cerr << "error populating totoal thresholds\n";
367 }
368 thresholdConfSize = confThresholds.size();
369
Cheng C Yang209ec562019-03-12 16:37:44 +0800370 interfacePath = &(sensor.first.str);
371 break;
372 }
373 if (interfacePath == nullptr)
374 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700375 // To avoid this error message, add your export map entry,
376 // from Entity Manager, to sensorTypes at the top of this file.
Cheng C Yang209ec562019-03-12 16:37:44 +0800377 std::cerr << "failed to find match for " << deviceName << "\n";
378 continue;
379 }
380
Cheng C Yange50345b2019-04-02 17:26:15 +0800381 auto findPSUName = baseConfig->second.find("Name");
382 if (findPSUName == baseConfig->second.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800383 {
384 std::cerr << "could not determine configuration name for "
385 << deviceName << "\n";
386 continue;
387 }
388
Cheng C Yang58b2b532019-05-31 00:19:45 +0800389 if (!(psuName = std::get_if<std::string>(&(findPSUName->second))))
390 {
391 std::cerr << "Cannot find psu name, invalid configuration\n";
392 continue;
393 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800394
395 // on rescans, only update sensors we were signaled by
396 if (!firstScan)
397 {
398 std::string psuNameStr = "/" + *psuName;
399 auto it =
400 std::find_if(sensorsChanged->begin(), sensorsChanged->end(),
401 [psuNameStr](std::string& s) {
402 return boost::ends_with(s, psuNameStr);
403 });
404
405 if (it == sensorsChanged->end())
406 {
407 continue;
408 }
409 sensorsChanged->erase(it);
410 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800411 checkEvent(directory.string(), eventMatch, eventPathList);
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800412 checkGroupEvent(directory.string(), groupEventMatch,
413 groupEventPathList);
Cheng C Yang58b2b532019-05-31 00:19:45 +0800414
Vijay Khemka996bad12019-05-28 15:15:16 -0700415 /* Check if there are more sensors in the same interface */
416 int i = 1;
417 std::vector<std::string> psuNames;
418 do
419 {
Josh Lehan49cfba92019-10-08 16:50:42 -0700420 // Individual string fields: Name, Name1, Name2, Name3, ...
Vijay Khemka996bad12019-05-28 15:15:16 -0700421 psuNames.push_back(std::get<std::string>(findPSUName->second));
422 findPSUName = baseConfig->second.find("Name" + std::to_string(i++));
423 } while (findPSUName != baseConfig->second.end());
424
Cheng C Yange50345b2019-04-02 17:26:15 +0800425 std::vector<fs::path> sensorPaths;
James Feistb6c0b912019-07-09 12:21:44 -0700426 if (!findFiles(directory, R"(\w\d+_input$)", sensorPaths, 0))
Cheng C Yang209ec562019-03-12 16:37:44 +0800427 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800428 std::cerr << "No PSU non-label sensor in PSU\n";
Cheng C Yang209ec562019-03-12 16:37:44 +0800429 continue;
430 }
431
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530432 /* read max value in sysfs for in, curr, power, temp, ... */
433 if (!findFiles(directory, R"(\w\d+_max$)", sensorPaths, 0))
434 {
435 if constexpr (DEBUG)
436 {
437 std::cerr << "No max name in PSU \n";
438 }
439 }
440
Vijay Khemka996bad12019-05-28 15:15:16 -0700441 /* Find array of labels to be exposed if it is defined in config */
442 std::vector<std::string> findLabels;
443 auto findLabelObj = baseConfig->second.find("Labels");
444 if (findLabelObj != baseConfig->second.end())
445 {
446 findLabels =
447 std::get<std::vector<std::string>>(findLabelObj->second);
448 }
449
Jason Ling5747fab2019-10-02 16:46:23 -0700450 std::regex sensorNameRegEx("([A-Za-z]+)[0-9]*_");
451 std::smatch matches;
452
Cheng C Yange50345b2019-04-02 17:26:15 +0800453 for (const auto& sensorPath : sensorPaths)
Cheng C Yang209ec562019-03-12 16:37:44 +0800454 {
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530455 bool maxLabel = false;
Cheng C Yange50345b2019-04-02 17:26:15 +0800456 std::string labelHead;
457 std::string sensorPathStr = sensorPath.string();
458 std::string sensorNameStr = sensorPath.filename();
Jason Ling5747fab2019-10-02 16:46:23 -0700459 std::string sensorNameSubStr{""};
460 if (std::regex_search(sensorNameStr, matches, sensorNameRegEx))
461 {
Josh Lehan06494452019-10-31 09:49:16 -0700462 // hwmon *_input filename without number:
463 // in, curr, power, temp, ...
Jason Ling5747fab2019-10-02 16:46:23 -0700464 sensorNameSubStr = matches[1];
465 }
466 else
467 {
Josh Lehan06494452019-10-31 09:49:16 -0700468 std::cerr << "Could not extract the alpha prefix from "
Jason Ling5747fab2019-10-02 16:46:23 -0700469 << sensorNameStr;
470 continue;
471 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800472
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530473 std::string labelPath;
474
475 /* find and differentiate _max and _input to replace "label" */
Brad Bishopfeb19ef2019-11-07 18:02:16 -0500476 size_t pos = sensorPathStr.find("_");
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530477 if (pos != std::string::npos)
478 {
479
480 std::string sensorPathStrMax = sensorPathStr.substr(pos);
481 if (sensorPathStrMax.compare("_max") == 0)
482 {
483 labelPath =
484 boost::replace_all_copy(sensorPathStr, "max", "label");
485 maxLabel = true;
486 }
487 else
488 {
489 labelPath = boost::replace_all_copy(sensorPathStr, "input",
490 "label");
491 maxLabel = false;
492 }
493 }
494 else
495 {
496 continue;
497 }
498
Cheng C Yangecba9de2019-09-12 23:41:50 +0800499 std::ifstream labelFile(labelPath);
500 if (!labelFile.good())
Cheng C Yang209ec562019-03-12 16:37:44 +0800501 {
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800502 if constexpr (DEBUG)
503 {
504 std::cerr << "Input file " << sensorPath
505 << " has no corresponding label file\n";
506 }
Josh Lehan06494452019-10-31 09:49:16 -0700507 // hwmon *_input filename with number:
508 // temp1, temp2, temp3, ...
Cheng C Yange50345b2019-04-02 17:26:15 +0800509 labelHead = sensorNameStr.substr(0, sensorNameStr.find("_"));
Cheng C Yang209ec562019-03-12 16:37:44 +0800510 }
511 else
512 {
Cheng C Yange50345b2019-04-02 17:26:15 +0800513 std::string label;
514 std::getline(labelFile, label);
515 labelFile.close();
Cheng C Yange50345b2019-04-02 17:26:15 +0800516 auto findSensor = sensors.find(label);
517 if (findSensor != sensors.end())
518 {
519 continue;
520 }
521
Josh Lehan06494452019-10-31 09:49:16 -0700522 // hwmon corresponding *_label file contents:
523 // vin1, vout1, ...
Cheng C Yange50345b2019-04-02 17:26:15 +0800524 labelHead = label.substr(0, label.find(" "));
525 }
526
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530527 /* append "max" for labelMatch */
528 if (maxLabel)
529 {
530 labelHead = "max" + labelHead;
531 }
532
Josh Lehan74d9bd92019-10-31 08:51:58 -0700533 if constexpr (DEBUG)
534 {
535 std::cerr << "Sensor type=\"" << sensorNameSubStr
536 << "\" label=\"" << labelHead << "\"\n";
537 }
538
AppaRao Pulid9d8caf2020-02-27 20:56:59 +0530539 checkPWMSensor(sensorPath, labelHead, *interfacePath,
540 dbusConnection, objectServer, psuNames[0]);
Cheng C Yang916360b2019-05-07 18:47:16 +0800541
Vijay Khemka996bad12019-05-28 15:15:16 -0700542 if (!findLabels.empty())
543 {
544 /* Check if this labelHead is enabled in config file */
545 if (std::find(findLabels.begin(), findLabels.end(),
546 labelHead) == findLabels.end())
547 {
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800548 if constexpr (DEBUG)
549 {
550 std::cerr << "could not find " << labelHead
551 << " in the Labels list\n";
552 }
Vijay Khemka996bad12019-05-28 15:15:16 -0700553 continue;
554 }
555 }
Cheng C Yange50345b2019-04-02 17:26:15 +0800556
Cheng C Yange50345b2019-04-02 17:26:15 +0800557 auto findProperty = labelMatch.find(labelHead);
558 if (findProperty == labelMatch.end())
Cheng C Yang209ec562019-03-12 16:37:44 +0800559 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700560 if constexpr (DEBUG)
561 {
562 std::cerr << "Could not find matching default property for "
563 << labelHead << "\n";
564 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800565 continue;
566 }
567
Josh Lehan74d9bd92019-10-31 08:51:58 -0700568 // Protect the hardcoded labelMatch list from changes,
569 // by making a copy and modifying that instead.
570 // Avoid bleedthrough of one device's customizations to
571 // the next device, as each should be independently customizable.
572 psuProperties.push_back(findProperty->second);
573 auto psuProperty = psuProperties.rbegin();
574
575 // Use label head as prefix for reading from config file,
576 // example if temp1: temp1_Name, temp1_Scale, temp1_Min, ...
577 std::string keyName = labelHead + "_Name";
578 std::string keyScale = labelHead + "_Scale";
579 std::string keyMin = labelHead + "_Min";
580 std::string keyMax = labelHead + "_Max";
581
582 bool customizedName = false;
583 auto findCustomName = baseConfig->second.find(keyName);
584 if (findCustomName != baseConfig->second.end())
Josh Lehan432d1ed2019-10-16 12:23:31 -0700585 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700586 try
587 {
588 psuProperty->labelTypeName = std::visit(
589 VariantToStringVisitor(), findCustomName->second);
590 }
591 catch (std::invalid_argument&)
592 {
593 std::cerr << "Unable to parse " << keyName << "\n";
594 continue;
595 }
596
597 // All strings are valid, including empty string
598 customizedName = true;
599 }
600
601 bool customizedScale = false;
602 auto findCustomScale = baseConfig->second.find(keyScale);
603 if (findCustomScale != baseConfig->second.end())
604 {
605 try
606 {
607 psuProperty->sensorScaleFactor = std::visit(
608 VariantToUnsignedIntVisitor(), findCustomScale->second);
609 }
610 catch (std::invalid_argument&)
611 {
612 std::cerr << "Unable to parse " << keyScale << "\n";
613 continue;
614 }
615
616 // Avoid later division by zero
617 if (psuProperty->sensorScaleFactor > 0)
618 {
619 customizedScale = true;
620 }
621 else
622 {
623 std::cerr << "Unable to accept " << keyScale << "\n";
624 continue;
625 }
626 }
627
628 auto findCustomMin = baseConfig->second.find(keyMin);
629 if (findCustomMin != baseConfig->second.end())
630 {
631 try
632 {
633 psuProperty->minReading = std::visit(
634 VariantToDoubleVisitor(), findCustomMin->second);
635 }
636 catch (std::invalid_argument&)
637 {
638 std::cerr << "Unable to parse " << keyMin << "\n";
639 continue;
640 }
641 }
642
643 auto findCustomMax = baseConfig->second.find(keyMax);
644 if (findCustomMax != baseConfig->second.end())
645 {
646 try
647 {
648 psuProperty->maxReading = std::visit(
649 VariantToDoubleVisitor(), findCustomMax->second);
650 }
651 catch (std::invalid_argument&)
652 {
653 std::cerr << "Unable to parse " << keyMax << "\n";
654 continue;
655 }
656 }
657
658 if (!(psuProperty->minReading < psuProperty->maxReading))
659 {
660 std::cerr << "Min must be less than Max\n";
661 continue;
662 }
663
664 // If the sensor name is being customized by config file,
665 // then prefix/suffix composition becomes not necessary,
666 // and in fact not wanted, because it gets in the way.
667 std::string psuNameFromIndex;
668 if (!customizedName)
669 {
670 /* Find out sensor name index for this label */
671 std::regex rgx("[A-Za-z]+([0-9]+)");
Brad Bishopfbb44ad2019-11-08 09:42:37 -0500672 size_t nameIndex{0};
Josh Lehan74d9bd92019-10-31 08:51:58 -0700673 if (std::regex_search(labelHead, matches, rgx))
674 {
675 nameIndex = std::stoi(matches[1]);
676
677 // Decrement to preserve alignment, because hwmon
678 // human-readable filenames and labels use 1-based
679 // numbering, but the "Name", "Name1", "Name2", etc. naming
680 // convention (the psuNames vector) uses 0-based numbering.
681 if (nameIndex > 0)
682 {
683 --nameIndex;
684 }
685 }
686 else
687 {
688 nameIndex = 0;
689 }
690
691 if (psuNames.size() <= nameIndex)
692 {
693 std::cerr << "Could not pair " << labelHead
694 << " with a Name field\n";
695 continue;
696 }
697
698 psuNameFromIndex = psuNames[nameIndex];
699
700 if constexpr (DEBUG)
701 {
702 std::cerr << "Sensor label head " << labelHead
703 << " paired with " << psuNameFromIndex
704 << " at index " << nameIndex << "\n";
705 }
Josh Lehan432d1ed2019-10-16 12:23:31 -0700706 }
707
Cheng C Yang58b2b532019-05-31 00:19:45 +0800708 checkEventLimits(sensorPathStr, limitEventMatch, eventPathList);
709
Josh Lehan74d9bd92019-10-31 08:51:58 -0700710 // Similarly, if sensor scaling factor is being customized,
711 // then the below power-of-10 constraint becomes unnecessary,
712 // as config should be able to specify an arbitrary divisor.
713 unsigned int factor = psuProperty->sensorScaleFactor;
714 if (!customizedScale)
Vijay Khemka53ca4442019-07-23 11:03:55 -0700715 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700716 // Preserve existing usage of hardcoded labelMatch table below
717 factor = std::pow(10.0, factor);
Vijay Khemka53ca4442019-07-23 11:03:55 -0700718
Josh Lehan74d9bd92019-10-31 08:51:58 -0700719 /* Change first char of substring to uppercase */
720 char firstChar = sensorNameSubStr[0] - 0x20;
721 std::string strScaleFactor =
722 firstChar + sensorNameSubStr.substr(1) + "ScaleFactor";
723
724 // Preserve existing configs by accepting earlier syntax,
725 // example CurrScaleFactor, PowerScaleFactor, ...
726 auto findScaleFactor = baseConfig->second.find(strScaleFactor);
727 if (findScaleFactor != baseConfig->second.end())
728 {
729 factor = std::visit(VariantToIntVisitor(),
730 findScaleFactor->second);
731 }
732
733 if constexpr (DEBUG)
734 {
735 std::cerr << "Sensor scaling factor " << factor
736 << " string " << strScaleFactor << "\n";
737 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700738 }
739
Vijay Khemka996bad12019-05-28 15:15:16 -0700740 std::vector<thresholds::Threshold> sensorThresholds;
Joshi, Mansi14f0ad82019-11-21 10:52:30 +0530741 if (!parseThresholdsFromConfig(*sensorData, sensorThresholds,
742 &labelHead))
Cheng C Yange50345b2019-04-02 17:26:15 +0800743 {
James Feist17ab6e02019-06-25 12:28:13 -0700744 std::cerr << "error populating thresholds for "
745 << sensorNameSubStr << "\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800746 }
747
748 auto findSensorType = sensorTable.find(sensorNameSubStr);
749 if (findSensorType == sensorTable.end())
750 {
Jason Ling5747fab2019-10-02 16:46:23 -0700751 std::cerr << sensorNameSubStr
Josh Lehan06494452019-10-31 09:49:16 -0700752 << " is not a recognized sensor type\n";
Cheng C Yange50345b2019-04-02 17:26:15 +0800753 continue;
754 }
755
Josh Lehan49cfba92019-10-08 16:50:42 -0700756 if constexpr (DEBUG)
757 {
Josh Lehan74d9bd92019-10-31 08:51:58 -0700758 std::cerr << "Sensor properties: Name \""
759 << psuProperty->labelTypeName << "\" Scale "
760 << psuProperty->sensorScaleFactor << " Min "
761 << psuProperty->minReading << " Max "
762 << psuProperty->maxReading << "\n";
763 }
764
765 std::string sensorName = psuProperty->labelTypeName;
766 if (customizedName)
767 {
768 if (sensorName.empty())
769 {
770 // Allow selective disabling of an individual sensor,
771 // by customizing its name to an empty string.
772 std::cerr << "Sensor disabled, empty string\n";
773 continue;
774 }
775 }
776 else
777 {
778 // Sensor name not customized, do prefix/suffix composition,
779 // preserving default behavior by using psuNameFromIndex.
780 sensorName =
781 psuNameFromIndex + " " + psuProperty->labelTypeName;
782 }
783
784 if constexpr (DEBUG)
785 {
786 std::cerr << "Sensor name \"" << sensorName << "\" path \""
787 << sensorPathStr << "\" type \"" << sensorType
788 << "\"\n";
Josh Lehan49cfba92019-10-08 16:50:42 -0700789 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800790 // destruct existing one first if already created
791 sensors[sensorName] = nullptr;
Yong Libf8b1da2020-04-15 16:32:50 +0800792 sensors[sensorName] = std::make_shared<PSUSensor>(
Cheng C Yange50345b2019-04-02 17:26:15 +0800793 sensorPathStr, sensorType, objectServer, dbusConnection, io,
Cheng C Yang209ec562019-03-12 16:37:44 +0800794 sensorName, std::move(sensorThresholds), *interfacePath,
Josh Lehan74d9bd92019-10-31 08:51:58 -0700795 findSensorType->second, factor, psuProperty->maxReading,
Cheng C Yang6b1247a2020-03-09 23:48:39 +0800796 psuProperty->minReading, labelHead, thresholdConfSize);
Yong Libf8b1da2020-04-15 16:32:50 +0800797 sensors[sensorName]->setupRead();
Josh Lehan74d9bd92019-10-31 08:51:58 -0700798 ++numCreated;
799 if constexpr (DEBUG)
800 {
801 std::cerr << "Created " << numCreated << " sensors so far\n";
802 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800803 }
Cheng C Yang58b2b532019-05-31 00:19:45 +0800804
805 // OperationalStatus event
Cheng C Yang92498eb2019-09-26 21:59:25 +0800806 combineEvents[*psuName + "OperationalStatus"] = nullptr;
Cheng C Yang58b2b532019-05-31 00:19:45 +0800807 combineEvents[*psuName + "OperationalStatus"] =
Yong Li3046a022020-04-03 13:01:02 +0800808 std::make_unique<PSUCombineEvent>(
809 objectServer, dbusConnection, io, *psuName, eventPathList,
810 groupEventPathList, "OperationalStatus");
Cheng C Yang209ec562019-03-12 16:37:44 +0800811 }
Josh Lehan49cfba92019-10-08 16:50:42 -0700812
813 if constexpr (DEBUG)
814 {
815 std::cerr << "Created total of " << numCreated << " sensors\n";
816 }
Cheng C Yang209ec562019-03-12 16:37:44 +0800817 return;
818}
819
Zhikui Ren23c96e72020-11-05 22:32:28 -0800820void createSensors(
821 boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
822 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
823 const std::shared_ptr<boost::container::flat_set<std::string>>&
824 sensorsChanged)
825{
826 auto getter = std::make_shared<GetSensorConfiguration>(
827 dbusConnection, [&io, &objectServer, &dbusConnection, sensorsChanged](
828 const ManagedObjectType& sensorConfigs) {
829 createSensorsCallback(io, objectServer, dbusConnection,
830 sensorConfigs, sensorsChanged);
831 });
832 getter->getConfiguration(
833 std::vector<std::string>(sensorTypes.begin(), sensorTypes.end()));
834}
835
Cheng C Yang916360b2019-05-07 18:47:16 +0800836void propertyInitialize(void)
Cheng C Yang209ec562019-03-12 16:37:44 +0800837{
Cheng C Yange50345b2019-04-02 17:26:15 +0800838 sensorTable = {{"power", "power/"},
839 {"curr", "current/"},
840 {"temp", "temperature/"},
841 {"in", "voltage/"},
842 {"fan", "fan_tach/"}};
843
844 labelMatch = {{"pin", PSUProperty("Input Power", 3000, 0, 6)},
845 {"pout1", PSUProperty("Output Power", 3000, 0, 6)},
Vijay Khemka996bad12019-05-28 15:15:16 -0700846 {"pout2", PSUProperty("Output Power", 3000, 0, 6)},
847 {"pout3", PSUProperty("Output Power", 3000, 0, 6)},
Vijay Khemkabe664412019-06-28 12:10:04 -0700848 {"power1", PSUProperty("Output Power", 3000, 0, 6)},
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530849 {"maxpin", PSUProperty("Max Input Power", 3000, 0, 6)},
Cheng C Yangbdbde962019-04-26 22:50:34 +0800850 {"vin", PSUProperty("Input Voltage", 300, 0, 3)},
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530851 {"maxvin", PSUProperty("Max Input Voltage", 300, 0, 3)},
Vijay Khemka996bad12019-05-28 15:15:16 -0700852 {"vout1", PSUProperty("Output Voltage", 255, 0, 3)},
853 {"vout2", PSUProperty("Output Voltage", 255, 0, 3)},
854 {"vout3", PSUProperty("Output Voltage", 255, 0, 3)},
Jason Ling5747fab2019-10-02 16:46:23 -0700855 {"vout4", PSUProperty("Output Voltage", 255, 0, 3)},
856 {"vout5", PSUProperty("Output Voltage", 255, 0, 3)},
857 {"vout6", PSUProperty("Output Voltage", 255, 0, 3)},
858 {"vout7", PSUProperty("Output Voltage", 255, 0, 3)},
859 {"vout8", PSUProperty("Output Voltage", 255, 0, 3)},
860 {"vout9", PSUProperty("Output Voltage", 255, 0, 3)},
861 {"vout10", PSUProperty("Output Voltage", 255, 0, 3)},
862 {"vout11", PSUProperty("Output Voltage", 255, 0, 3)},
863 {"vout12", PSUProperty("Output Voltage", 255, 0, 3)},
864 {"vout13", PSUProperty("Output Voltage", 255, 0, 3)},
865 {"vout14", PSUProperty("Output Voltage", 255, 0, 3)},
866 {"vout15", PSUProperty("Output Voltage", 255, 0, 3)},
867 {"vout16", PSUProperty("Output Voltage", 255, 0, 3)},
Jason Ling32047ef2020-09-30 15:43:32 -0700868 {"vout17", PSUProperty("Output Voltage", 255, 0, 3)},
869 {"vout18", PSUProperty("Output Voltage", 255, 0, 3)},
870 {"vout19", PSUProperty("Output Voltage", 255, 0, 3)},
871 {"vout20", PSUProperty("Output Voltage", 255, 0, 3)},
872 {"vout21", PSUProperty("Output Voltage", 255, 0, 3)},
873 {"vout22", PSUProperty("Output Voltage", 255, 0, 3)},
874 {"vout23", PSUProperty("Output Voltage", 255, 0, 3)},
875 {"vout24", PSUProperty("Output Voltage", 255, 0, 3)},
876 {"vout25", PSUProperty("Output Voltage", 255, 0, 3)},
877 {"vout26", PSUProperty("Output Voltage", 255, 0, 3)},
878 {"vout27", PSUProperty("Output Voltage", 255, 0, 3)},
879 {"vout28", PSUProperty("Output Voltage", 255, 0, 3)},
880 {"vout29", PSUProperty("Output Voltage", 255, 0, 3)},
881 {"vout30", PSUProperty("Output Voltage", 255, 0, 3)},
882 {"vout31", PSUProperty("Output Voltage", 255, 0, 3)},
883 {"vout32", PSUProperty("Output Voltage", 255, 0, 3)},
Vijay Khemkabe664412019-06-28 12:10:04 -0700884 {"in1", PSUProperty("Output Voltage", 255, 0, 3)},
Cheng C Yange50345b2019-04-02 17:26:15 +0800885 {"iin", PSUProperty("Input Current", 20, 0, 3)},
886 {"iout1", PSUProperty("Output Current", 255, 0, 3)},
Vijay Khemka996bad12019-05-28 15:15:16 -0700887 {"iout2", PSUProperty("Output Current", 255, 0, 3)},
888 {"iout3", PSUProperty("Output Current", 255, 0, 3)},
Peter Lundgren48b44232020-01-30 16:02:11 -0800889 {"iout4", PSUProperty("Output Current", 255, 0, 3)},
890 {"iout5", PSUProperty("Output Current", 255, 0, 3)},
891 {"iout6", PSUProperty("Output Current", 255, 0, 3)},
892 {"iout7", PSUProperty("Output Current", 255, 0, 3)},
893 {"iout8", PSUProperty("Output Current", 255, 0, 3)},
894 {"iout9", PSUProperty("Output Current", 255, 0, 3)},
895 {"iout10", PSUProperty("Output Current", 255, 0, 3)},
896 {"iout11", PSUProperty("Output Current", 255, 0, 3)},
897 {"iout12", PSUProperty("Output Current", 255, 0, 3)},
898 {"iout13", PSUProperty("Output Current", 255, 0, 3)},
899 {"iout14", PSUProperty("Output Current", 255, 0, 3)},
Vijay Khemkabe664412019-06-28 12:10:04 -0700900 {"curr1", PSUProperty("Output Current", 255, 0, 3)},
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530901 {"maxiout1", PSUProperty("Max Output Current", 255, 0, 3)},
Cheng C Yange50345b2019-04-02 17:26:15 +0800902 {"temp1", PSUProperty("Temperature", 127, -128, 3)},
Vijay Khemka996bad12019-05-28 15:15:16 -0700903 {"temp2", PSUProperty("Temperature", 127, -128, 3)},
904 {"temp3", PSUProperty("Temperature", 127, -128, 3)},
Jason Ling5747fab2019-10-02 16:46:23 -0700905 {"temp4", PSUProperty("Temperature", 127, -128, 3)},
906 {"temp5", PSUProperty("Temperature", 127, -128, 3)},
Alex Qiuf5709b42020-01-29 13:29:50 -0800907 {"temp6", PSUProperty("Temperature", 127, -128, 3)},
Manikandan Elumalaic7e95622020-06-03 20:22:01 +0530908 {"maxtemp1", PSUProperty("Max Temperature", 127, -128, 3)},
Cheng C Yang8dbb3952019-05-23 00:03:12 +0800909 {"fan1", PSUProperty("Fan Speed 1", 30000, 0, 0)},
910 {"fan2", PSUProperty("Fan Speed 2", 30000, 0, 0)}};
Cheng C Yang916360b2019-05-07 18:47:16 +0800911
912 pwmTable = {{"fan1", "Fan_1"}, {"fan2", "Fan_2"}};
Cheng C Yang58b2b532019-05-31 00:19:45 +0800913
914 limitEventMatch = {{"PredictiveFailure", {"max_alarm", "min_alarm"}},
915 {"Failure", {"crit_alarm", "lcrit_alarm"}}};
916
Cheng C Yang202a1ff2020-01-09 09:34:22 +0800917 eventMatch = {{"PredictiveFailure", {"power1_alarm"}},
918 {"Failure", {"in2_alarm"}},
919 {"ACLost", {"in1_beep"}},
920 {"ConfigureError", {"in1_fault"}}};
921
922 groupEventMatch = {{"FanFault",
923 {{"fan1", {"fan1_alarm", "fan1_fault"}},
924 {"fan2", {"fan2_alarm", "fan2_fault"}}}}};
Cheng C Yang209ec562019-03-12 16:37:44 +0800925}
926
James Feistb6c0b912019-07-09 12:21:44 -0700927int main()
Cheng C Yang209ec562019-03-12 16:37:44 +0800928{
929 boost::asio::io_service io;
930 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
931
932 systemBus->request_name("xyz.openbmc_project.PSUSensor");
933 sdbusplus::asio::object_server objectServer(systemBus);
Cheng C Yang209ec562019-03-12 16:37:44 +0800934 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
Zhikui Ren23c96e72020-11-05 22:32:28 -0800935 auto sensorsChanged =
936 std::make_shared<boost::container::flat_set<std::string>>();
Cheng C Yang209ec562019-03-12 16:37:44 +0800937
Cheng C Yang916360b2019-05-07 18:47:16 +0800938 propertyInitialize();
Cheng C Yang209ec562019-03-12 16:37:44 +0800939
Zhikui Ren23c96e72020-11-05 22:32:28 -0800940 io.post([&]() { createSensors(io, objectServer, systemBus, nullptr); });
Cheng C Yang209ec562019-03-12 16:37:44 +0800941 boost::asio::deadline_timer filterTimer(io);
942 std::function<void(sdbusplus::message::message&)> eventHandler =
943 [&](sdbusplus::message::message& message) {
944 if (message.is_method_error())
945 {
946 std::cerr << "callback method error\n";
947 return;
948 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800949 sensorsChanged->insert(message.get_path());
Cheng C Yanga97f1342020-02-11 15:10:41 +0800950 filterTimer.expires_from_now(boost::posix_time::seconds(3));
Cheng C Yang209ec562019-03-12 16:37:44 +0800951 filterTimer.async_wait([&](const boost::system::error_code& ec) {
952 if (ec == boost::asio::error::operation_aborted)
953 {
954 return;
955 }
956 else if (ec)
957 {
958 std::cerr << "timer error\n";
959 }
Zhikui Ren23c96e72020-11-05 22:32:28 -0800960 createSensors(io, objectServer, systemBus, sensorsChanged);
Cheng C Yang209ec562019-03-12 16:37:44 +0800961 });
962 };
963
964 for (const char* type : sensorTypes)
965 {
966 auto match = std::make_unique<sdbusplus::bus::match::match>(
967 static_cast<sdbusplus::bus::bus&>(*systemBus),
968 "type='signal',member='PropertiesChanged',path_namespace='" +
969 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
970 eventHandler);
971 matches.emplace_back(std::move(match));
972 }
973 io.run();
974}