1*d7be555eSGeorge Liu /*
2*d7be555eSGeorge Liu // Copyright (c) 2017 Intel Corporation
3*d7be555eSGeorge Liu //
4*d7be555eSGeorge Liu // Licensed under the Apache License, Version 2.0 (the "License");
5*d7be555eSGeorge Liu // you may not use this file except in compliance with the License.
6*d7be555eSGeorge Liu // You may obtain a copy of the License at
7*d7be555eSGeorge Liu //
8*d7be555eSGeorge Liu // http://www.apache.org/licenses/LICENSE-2.0
9*d7be555eSGeorge Liu //
10*d7be555eSGeorge Liu // Unless required by applicable law or agreed to in writing, software
11*d7be555eSGeorge Liu // distributed under the License is distributed on an "AS IS" BASIS,
12*d7be555eSGeorge Liu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*d7be555eSGeorge Liu // See the License for the specific language governing permissions and
14*d7be555eSGeorge Liu // limitations under the License.
15*d7be555eSGeorge Liu */
16*d7be555eSGeorge Liu
17*d7be555eSGeorge Liu #include "ADCSensor.hpp"
18*d7be555eSGeorge Liu #include "Thresholds.hpp"
19*d7be555eSGeorge Liu #include "Utils.hpp"
20*d7be555eSGeorge Liu #include "VariantVisitors.hpp"
21*d7be555eSGeorge Liu
22*d7be555eSGeorge Liu #include <boost/algorithm/string/case_conv.hpp>
23*d7be555eSGeorge Liu #include <boost/asio/error.hpp>
24*d7be555eSGeorge Liu #include <boost/asio/io_context.hpp>
25*d7be555eSGeorge Liu #include <boost/asio/post.hpp>
26*d7be555eSGeorge Liu #include <boost/asio/steady_timer.hpp>
27*d7be555eSGeorge Liu #include <boost/container/flat_map.hpp>
28*d7be555eSGeorge Liu #include <boost/container/flat_set.hpp>
29*d7be555eSGeorge Liu #include <gpiod.hpp>
30*d7be555eSGeorge Liu #include <sdbusplus/asio/connection.hpp>
31*d7be555eSGeorge Liu #include <sdbusplus/asio/object_server.hpp>
32*d7be555eSGeorge Liu #include <sdbusplus/bus.hpp>
33*d7be555eSGeorge Liu #include <sdbusplus/bus/match.hpp>
34*d7be555eSGeorge Liu #include <sdbusplus/message.hpp>
35*d7be555eSGeorge Liu #include <sdbusplus/message/native_types.hpp>
36*d7be555eSGeorge Liu
37*d7be555eSGeorge Liu #include <array>
38*d7be555eSGeorge Liu #include <chrono>
39*d7be555eSGeorge Liu #include <cstddef>
40*d7be555eSGeorge Liu #include <filesystem>
41*d7be555eSGeorge Liu #include <fstream>
42*d7be555eSGeorge Liu #include <functional>
43*d7be555eSGeorge Liu #include <iostream>
44*d7be555eSGeorge Liu #include <memory>
45*d7be555eSGeorge Liu #include <optional>
46*d7be555eSGeorge Liu #include <regex>
47*d7be555eSGeorge Liu #include <stdexcept>
48*d7be555eSGeorge Liu #include <string>
49*d7be555eSGeorge Liu #include <utility>
50*d7be555eSGeorge Liu #include <variant>
51*d7be555eSGeorge Liu #include <vector>
52*d7be555eSGeorge Liu
53*d7be555eSGeorge Liu static constexpr bool debug = false;
54*d7be555eSGeorge Liu static constexpr float pollRateDefault = 0.5;
55*d7be555eSGeorge Liu static constexpr float gpioBridgeSetupTimeDefault = 0.02;
56*d7be555eSGeorge Liu
57*d7be555eSGeorge Liu namespace fs = std::filesystem;
58*d7be555eSGeorge Liu
59*d7be555eSGeorge Liu static constexpr auto sensorTypes{std::to_array<const char*>({"ADC"})};
60*d7be555eSGeorge Liu static std::regex inputRegex(R"(in(\d+)_input)");
61*d7be555eSGeorge Liu
62*d7be555eSGeorge Liu static boost::container::flat_map<size_t, bool> cpuPresence;
63*d7be555eSGeorge Liu
64*d7be555eSGeorge Liu enum class UpdateType
65*d7be555eSGeorge Liu {
66*d7be555eSGeorge Liu init,
67*d7be555eSGeorge Liu cpuPresenceChange
68*d7be555eSGeorge Liu };
69*d7be555eSGeorge Liu
70*d7be555eSGeorge Liu // filter out adc from any other voltage sensor
isAdc(const fs::path & parentPath)71*d7be555eSGeorge Liu bool isAdc(const fs::path& parentPath)
72*d7be555eSGeorge Liu {
73*d7be555eSGeorge Liu fs::path namePath = parentPath / "name";
74*d7be555eSGeorge Liu
75*d7be555eSGeorge Liu std::ifstream nameFile(namePath);
76*d7be555eSGeorge Liu if (!nameFile.good())
77*d7be555eSGeorge Liu {
78*d7be555eSGeorge Liu std::cerr << "Failure reading " << namePath.string() << "\n";
79*d7be555eSGeorge Liu return false;
80*d7be555eSGeorge Liu }
81*d7be555eSGeorge Liu
82*d7be555eSGeorge Liu std::string name;
83*d7be555eSGeorge Liu std::getline(nameFile, name);
84*d7be555eSGeorge Liu
85*d7be555eSGeorge Liu return name == "iio_hwmon";
86*d7be555eSGeorge Liu }
87*d7be555eSGeorge Liu
createSensors(boost::asio::io_context & io,sdbusplus::asio::object_server & objectServer,boost::container::flat_map<std::string,std::shared_ptr<ADCSensor>> & sensors,std::shared_ptr<sdbusplus::asio::connection> & dbusConnection,const std::shared_ptr<boost::container::flat_set<std::string>> & sensorsChanged,UpdateType updateType)88*d7be555eSGeorge Liu void createSensors(
89*d7be555eSGeorge Liu boost::asio::io_context& io, sdbusplus::asio::object_server& objectServer,
90*d7be555eSGeorge Liu boost::container::flat_map<std::string, std::shared_ptr<ADCSensor>>&
91*d7be555eSGeorge Liu sensors,
92*d7be555eSGeorge Liu std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
93*d7be555eSGeorge Liu const std::shared_ptr<boost::container::flat_set<std::string>>&
94*d7be555eSGeorge Liu sensorsChanged,
95*d7be555eSGeorge Liu UpdateType updateType)
96*d7be555eSGeorge Liu {
97*d7be555eSGeorge Liu auto getter = std::make_shared<GetSensorConfiguration>(
98*d7be555eSGeorge Liu dbusConnection,
99*d7be555eSGeorge Liu [&io, &objectServer, &sensors, &dbusConnection, sensorsChanged,
100*d7be555eSGeorge Liu updateType](const ManagedObjectType& sensorConfigurations) {
101*d7be555eSGeorge Liu bool firstScan = sensorsChanged == nullptr;
102*d7be555eSGeorge Liu std::vector<fs::path> paths;
103*d7be555eSGeorge Liu if (!findFiles(fs::path("/sys/class/hwmon"), R"(in\d+_input)",
104*d7be555eSGeorge Liu paths))
105*d7be555eSGeorge Liu {
106*d7be555eSGeorge Liu std::cerr << "No adc sensors in system\n";
107*d7be555eSGeorge Liu return;
108*d7be555eSGeorge Liu }
109*d7be555eSGeorge Liu
110*d7be555eSGeorge Liu // iterate through all found adc sensors, and try to match them with
111*d7be555eSGeorge Liu // configuration
112*d7be555eSGeorge Liu for (auto& path : paths)
113*d7be555eSGeorge Liu {
114*d7be555eSGeorge Liu if (!isAdc(path.parent_path()))
115*d7be555eSGeorge Liu {
116*d7be555eSGeorge Liu continue;
117*d7be555eSGeorge Liu }
118*d7be555eSGeorge Liu std::smatch match;
119*d7be555eSGeorge Liu std::string pathStr = path.string();
120*d7be555eSGeorge Liu
121*d7be555eSGeorge Liu std::regex_search(pathStr, match, inputRegex);
122*d7be555eSGeorge Liu std::string indexStr = *(match.begin() + 1);
123*d7be555eSGeorge Liu
124*d7be555eSGeorge Liu // convert to 0 based
125*d7be555eSGeorge Liu size_t index = std::stoul(indexStr) - 1;
126*d7be555eSGeorge Liu
127*d7be555eSGeorge Liu const SensorData* sensorData = nullptr;
128*d7be555eSGeorge Liu const std::string* interfacePath = nullptr;
129*d7be555eSGeorge Liu const std::pair<std::string, SensorBaseConfigMap>*
130*d7be555eSGeorge Liu baseConfiguration = nullptr;
131*d7be555eSGeorge Liu for (const auto& [path, cfgData] : sensorConfigurations)
132*d7be555eSGeorge Liu {
133*d7be555eSGeorge Liu // clear it out each loop
134*d7be555eSGeorge Liu baseConfiguration = nullptr;
135*d7be555eSGeorge Liu
136*d7be555eSGeorge Liu // find base configuration
137*d7be555eSGeorge Liu for (const char* type : sensorTypes)
138*d7be555eSGeorge Liu {
139*d7be555eSGeorge Liu auto sensorBase =
140*d7be555eSGeorge Liu cfgData.find(configInterfaceName(type));
141*d7be555eSGeorge Liu if (sensorBase != cfgData.end())
142*d7be555eSGeorge Liu {
143*d7be555eSGeorge Liu baseConfiguration = &(*sensorBase);
144*d7be555eSGeorge Liu break;
145*d7be555eSGeorge Liu }
146*d7be555eSGeorge Liu }
147*d7be555eSGeorge Liu if (baseConfiguration == nullptr)
148*d7be555eSGeorge Liu {
149*d7be555eSGeorge Liu continue;
150*d7be555eSGeorge Liu }
151*d7be555eSGeorge Liu auto findIndex = baseConfiguration->second.find("Index");
152*d7be555eSGeorge Liu if (findIndex == baseConfiguration->second.end())
153*d7be555eSGeorge Liu {
154*d7be555eSGeorge Liu std::cerr << "Base configuration missing Index"
155*d7be555eSGeorge Liu << baseConfiguration->first << "\n";
156*d7be555eSGeorge Liu continue;
157*d7be555eSGeorge Liu }
158*d7be555eSGeorge Liu
159*d7be555eSGeorge Liu unsigned int number = std::visit(
160*d7be555eSGeorge Liu VariantToUnsignedIntVisitor(), findIndex->second);
161*d7be555eSGeorge Liu
162*d7be555eSGeorge Liu if (number != index)
163*d7be555eSGeorge Liu {
164*d7be555eSGeorge Liu continue;
165*d7be555eSGeorge Liu }
166*d7be555eSGeorge Liu
167*d7be555eSGeorge Liu sensorData = &cfgData;
168*d7be555eSGeorge Liu interfacePath = &path.str;
169*d7be555eSGeorge Liu break;
170*d7be555eSGeorge Liu }
171*d7be555eSGeorge Liu if (sensorData == nullptr)
172*d7be555eSGeorge Liu {
173*d7be555eSGeorge Liu if constexpr (debug)
174*d7be555eSGeorge Liu {
175*d7be555eSGeorge Liu std::cerr << "failed to find match for "
176*d7be555eSGeorge Liu << path.string() << "\n";
177*d7be555eSGeorge Liu }
178*d7be555eSGeorge Liu continue;
179*d7be555eSGeorge Liu }
180*d7be555eSGeorge Liu
181*d7be555eSGeorge Liu if (baseConfiguration == nullptr)
182*d7be555eSGeorge Liu {
183*d7be555eSGeorge Liu std::cerr << "error finding base configuration for"
184*d7be555eSGeorge Liu << path.string() << "\n";
185*d7be555eSGeorge Liu continue;
186*d7be555eSGeorge Liu }
187*d7be555eSGeorge Liu
188*d7be555eSGeorge Liu auto findSensorName = baseConfiguration->second.find("Name");
189*d7be555eSGeorge Liu if (findSensorName == baseConfiguration->second.end())
190*d7be555eSGeorge Liu {
191*d7be555eSGeorge Liu std::cerr << "could not determine configuration name for "
192*d7be555eSGeorge Liu << path.string() << "\n";
193*d7be555eSGeorge Liu continue;
194*d7be555eSGeorge Liu }
195*d7be555eSGeorge Liu std::string sensorName =
196*d7be555eSGeorge Liu std::get<std::string>(findSensorName->second);
197*d7be555eSGeorge Liu
198*d7be555eSGeorge Liu // on rescans, only update sensors we were signaled by
199*d7be555eSGeorge Liu auto findSensor = sensors.find(sensorName);
200*d7be555eSGeorge Liu if (!firstScan && findSensor != sensors.end())
201*d7be555eSGeorge Liu {
202*d7be555eSGeorge Liu bool found = false;
203*d7be555eSGeorge Liu for (auto it = sensorsChanged->begin();
204*d7be555eSGeorge Liu it != sensorsChanged->end(); it++)
205*d7be555eSGeorge Liu {
206*d7be555eSGeorge Liu if (findSensor->second &&
207*d7be555eSGeorge Liu it->ends_with(findSensor->second->name))
208*d7be555eSGeorge Liu {
209*d7be555eSGeorge Liu sensorsChanged->erase(it);
210*d7be555eSGeorge Liu findSensor->second = nullptr;
211*d7be555eSGeorge Liu found = true;
212*d7be555eSGeorge Liu break;
213*d7be555eSGeorge Liu }
214*d7be555eSGeorge Liu }
215*d7be555eSGeorge Liu if (!found)
216*d7be555eSGeorge Liu {
217*d7be555eSGeorge Liu continue;
218*d7be555eSGeorge Liu }
219*d7be555eSGeorge Liu }
220*d7be555eSGeorge Liu
221*d7be555eSGeorge Liu auto findCPU = baseConfiguration->second.find("CPURequired");
222*d7be555eSGeorge Liu if (findCPU != baseConfiguration->second.end())
223*d7be555eSGeorge Liu {
224*d7be555eSGeorge Liu size_t index =
225*d7be555eSGeorge Liu std::visit(VariantToIntVisitor(), findCPU->second);
226*d7be555eSGeorge Liu auto presenceFind = cpuPresence.find(index);
227*d7be555eSGeorge Liu if (presenceFind == cpuPresence.end())
228*d7be555eSGeorge Liu {
229*d7be555eSGeorge Liu continue; // no such cpu
230*d7be555eSGeorge Liu }
231*d7be555eSGeorge Liu if (!presenceFind->second)
232*d7be555eSGeorge Liu {
233*d7be555eSGeorge Liu continue; // cpu not installed
234*d7be555eSGeorge Liu }
235*d7be555eSGeorge Liu }
236*d7be555eSGeorge Liu else if (updateType == UpdateType::cpuPresenceChange)
237*d7be555eSGeorge Liu {
238*d7be555eSGeorge Liu continue;
239*d7be555eSGeorge Liu }
240*d7be555eSGeorge Liu
241*d7be555eSGeorge Liu std::vector<thresholds::Threshold> sensorThresholds;
242*d7be555eSGeorge Liu if (!parseThresholdsFromConfig(*sensorData, sensorThresholds))
243*d7be555eSGeorge Liu {
244*d7be555eSGeorge Liu std::cerr << "error populating thresholds for "
245*d7be555eSGeorge Liu << sensorName << "\n";
246*d7be555eSGeorge Liu }
247*d7be555eSGeorge Liu
248*d7be555eSGeorge Liu auto findScaleFactor =
249*d7be555eSGeorge Liu baseConfiguration->second.find("ScaleFactor");
250*d7be555eSGeorge Liu float scaleFactor = 1.0;
251*d7be555eSGeorge Liu if (findScaleFactor != baseConfiguration->second.end())
252*d7be555eSGeorge Liu {
253*d7be555eSGeorge Liu scaleFactor = std::visit(VariantToFloatVisitor(),
254*d7be555eSGeorge Liu findScaleFactor->second);
255*d7be555eSGeorge Liu // scaleFactor is used in division
256*d7be555eSGeorge Liu if (scaleFactor == 0.0F)
257*d7be555eSGeorge Liu {
258*d7be555eSGeorge Liu scaleFactor = 1.0;
259*d7be555eSGeorge Liu }
260*d7be555eSGeorge Liu }
261*d7be555eSGeorge Liu
262*d7be555eSGeorge Liu float pollRate =
263*d7be555eSGeorge Liu getPollRate(baseConfiguration->second, pollRateDefault);
264*d7be555eSGeorge Liu PowerState readState = getPowerState(baseConfiguration->second);
265*d7be555eSGeorge Liu
266*d7be555eSGeorge Liu auto& sensor = sensors[sensorName];
267*d7be555eSGeorge Liu sensor = nullptr;
268*d7be555eSGeorge Liu
269*d7be555eSGeorge Liu std::optional<BridgeGpio> bridgeGpio;
270*d7be555eSGeorge Liu for (const auto& [key, cfgMap] : *sensorData)
271*d7be555eSGeorge Liu {
272*d7be555eSGeorge Liu if (key.find("BridgeGpio") != std::string::npos)
273*d7be555eSGeorge Liu {
274*d7be555eSGeorge Liu auto findName = cfgMap.find("Name");
275*d7be555eSGeorge Liu if (findName != cfgMap.end())
276*d7be555eSGeorge Liu {
277*d7be555eSGeorge Liu std::string gpioName = std::visit(
278*d7be555eSGeorge Liu VariantToStringVisitor(), findName->second);
279*d7be555eSGeorge Liu
280*d7be555eSGeorge Liu int polarity = gpiod::line::ACTIVE_HIGH;
281*d7be555eSGeorge Liu auto findPolarity = cfgMap.find("Polarity");
282*d7be555eSGeorge Liu if (findPolarity != cfgMap.end())
283*d7be555eSGeorge Liu {
284*d7be555eSGeorge Liu if (std::string("Low") ==
285*d7be555eSGeorge Liu std::visit(VariantToStringVisitor(),
286*d7be555eSGeorge Liu findPolarity->second))
287*d7be555eSGeorge Liu {
288*d7be555eSGeorge Liu polarity = gpiod::line::ACTIVE_LOW;
289*d7be555eSGeorge Liu }
290*d7be555eSGeorge Liu }
291*d7be555eSGeorge Liu
292*d7be555eSGeorge Liu float setupTime = gpioBridgeSetupTimeDefault;
293*d7be555eSGeorge Liu auto findSetupTime = cfgMap.find("SetupTime");
294*d7be555eSGeorge Liu if (findSetupTime != cfgMap.end())
295*d7be555eSGeorge Liu {
296*d7be555eSGeorge Liu setupTime = std::visit(VariantToFloatVisitor(),
297*d7be555eSGeorge Liu findSetupTime->second);
298*d7be555eSGeorge Liu }
299*d7be555eSGeorge Liu
300*d7be555eSGeorge Liu bridgeGpio =
301*d7be555eSGeorge Liu BridgeGpio(gpioName, polarity, setupTime);
302*d7be555eSGeorge Liu }
303*d7be555eSGeorge Liu
304*d7be555eSGeorge Liu break;
305*d7be555eSGeorge Liu }
306*d7be555eSGeorge Liu }
307*d7be555eSGeorge Liu
308*d7be555eSGeorge Liu sensor = std::make_shared<ADCSensor>(
309*d7be555eSGeorge Liu path.string(), objectServer, dbusConnection, io, sensorName,
310*d7be555eSGeorge Liu std::move(sensorThresholds), scaleFactor, pollRate,
311*d7be555eSGeorge Liu readState, *interfacePath, std::move(bridgeGpio));
312*d7be555eSGeorge Liu sensor->setupRead();
313*d7be555eSGeorge Liu }
314*d7be555eSGeorge Liu });
315*d7be555eSGeorge Liu
316*d7be555eSGeorge Liu getter->getConfiguration(
317*d7be555eSGeorge Liu std::vector<std::string>{sensorTypes.begin(), sensorTypes.end()});
318*d7be555eSGeorge Liu }
319*d7be555eSGeorge Liu
main()320*d7be555eSGeorge Liu int main()
321*d7be555eSGeorge Liu {
322*d7be555eSGeorge Liu boost::asio::io_context io;
323*d7be555eSGeorge Liu auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
324*d7be555eSGeorge Liu sdbusplus::asio::object_server objectServer(systemBus, true);
325*d7be555eSGeorge Liu objectServer.add_manager("/xyz/openbmc_project/sensors");
326*d7be555eSGeorge Liu
327*d7be555eSGeorge Liu systemBus->request_name("xyz.openbmc_project.ADCSensor");
328*d7be555eSGeorge Liu boost::container::flat_map<std::string, std::shared_ptr<ADCSensor>> sensors;
329*d7be555eSGeorge Liu auto sensorsChanged =
330*d7be555eSGeorge Liu std::make_shared<boost::container::flat_set<std::string>>();
331*d7be555eSGeorge Liu
332*d7be555eSGeorge Liu boost::asio::post(io, [&]() {
333*d7be555eSGeorge Liu createSensors(io, objectServer, sensors, systemBus, nullptr,
334*d7be555eSGeorge Liu UpdateType::init);
335*d7be555eSGeorge Liu });
336*d7be555eSGeorge Liu
337*d7be555eSGeorge Liu boost::asio::steady_timer filterTimer(io);
338*d7be555eSGeorge Liu std::function<void(sdbusplus::message_t&)> eventHandler =
339*d7be555eSGeorge Liu [&](sdbusplus::message_t& message) {
340*d7be555eSGeorge Liu if (message.is_method_error())
341*d7be555eSGeorge Liu {
342*d7be555eSGeorge Liu std::cerr << "callback method error\n";
343*d7be555eSGeorge Liu return;
344*d7be555eSGeorge Liu }
345*d7be555eSGeorge Liu sensorsChanged->insert(message.get_path());
346*d7be555eSGeorge Liu // this implicitly cancels the timer
347*d7be555eSGeorge Liu filterTimer.expires_after(std::chrono::seconds(1));
348*d7be555eSGeorge Liu
349*d7be555eSGeorge Liu filterTimer.async_wait([&](const boost::system::error_code& ec) {
350*d7be555eSGeorge Liu if (ec == boost::asio::error::operation_aborted)
351*d7be555eSGeorge Liu {
352*d7be555eSGeorge Liu /* we were canceled*/
353*d7be555eSGeorge Liu return;
354*d7be555eSGeorge Liu }
355*d7be555eSGeorge Liu if (ec)
356*d7be555eSGeorge Liu {
357*d7be555eSGeorge Liu std::cerr << "timer error\n";
358*d7be555eSGeorge Liu return;
359*d7be555eSGeorge Liu }
360*d7be555eSGeorge Liu createSensors(io, objectServer, sensors, systemBus,
361*d7be555eSGeorge Liu sensorsChanged, UpdateType::init);
362*d7be555eSGeorge Liu });
363*d7be555eSGeorge Liu };
364*d7be555eSGeorge Liu
365*d7be555eSGeorge Liu boost::asio::steady_timer cpuFilterTimer(io);
366*d7be555eSGeorge Liu std::function<void(sdbusplus::message_t&)> cpuPresenceHandler =
367*d7be555eSGeorge Liu [&](sdbusplus::message_t& message) {
368*d7be555eSGeorge Liu std::string path = message.get_path();
369*d7be555eSGeorge Liu boost::to_lower(path);
370*d7be555eSGeorge Liu
371*d7be555eSGeorge Liu sdbusplus::message::object_path cpuPath(path);
372*d7be555eSGeorge Liu std::string cpuName = cpuPath.filename();
373*d7be555eSGeorge Liu if (!cpuName.starts_with("cpu"))
374*d7be555eSGeorge Liu {
375*d7be555eSGeorge Liu return; // not interested
376*d7be555eSGeorge Liu }
377*d7be555eSGeorge Liu size_t index = 0;
378*d7be555eSGeorge Liu try
379*d7be555eSGeorge Liu {
380*d7be555eSGeorge Liu index = std::stoi(path.substr(path.size() - 1));
381*d7be555eSGeorge Liu }
382*d7be555eSGeorge Liu catch (const std::invalid_argument&)
383*d7be555eSGeorge Liu {
384*d7be555eSGeorge Liu std::cerr << "Found invalid path " << path << "\n";
385*d7be555eSGeorge Liu return;
386*d7be555eSGeorge Liu }
387*d7be555eSGeorge Liu
388*d7be555eSGeorge Liu std::string objectName;
389*d7be555eSGeorge Liu boost::container::flat_map<std::string, std::variant<bool>> values;
390*d7be555eSGeorge Liu message.read(objectName, values);
391*d7be555eSGeorge Liu auto findPresence = values.find("Present");
392*d7be555eSGeorge Liu if (findPresence != values.end())
393*d7be555eSGeorge Liu {
394*d7be555eSGeorge Liu cpuPresence[index] = std::get<bool>(findPresence->second);
395*d7be555eSGeorge Liu }
396*d7be555eSGeorge Liu
397*d7be555eSGeorge Liu // this implicitly cancels the timer
398*d7be555eSGeorge Liu cpuFilterTimer.expires_after(std::chrono::seconds(1));
399*d7be555eSGeorge Liu
400*d7be555eSGeorge Liu cpuFilterTimer.async_wait([&](const boost::system::error_code& ec) {
401*d7be555eSGeorge Liu if (ec == boost::asio::error::operation_aborted)
402*d7be555eSGeorge Liu {
403*d7be555eSGeorge Liu /* we were canceled*/
404*d7be555eSGeorge Liu return;
405*d7be555eSGeorge Liu }
406*d7be555eSGeorge Liu if (ec)
407*d7be555eSGeorge Liu {
408*d7be555eSGeorge Liu std::cerr << "timer error\n";
409*d7be555eSGeorge Liu return;
410*d7be555eSGeorge Liu }
411*d7be555eSGeorge Liu createSensors(io, objectServer, sensors, systemBus, nullptr,
412*d7be555eSGeorge Liu UpdateType::cpuPresenceChange);
413*d7be555eSGeorge Liu });
414*d7be555eSGeorge Liu };
415*d7be555eSGeorge Liu
416*d7be555eSGeorge Liu std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches =
417*d7be555eSGeorge Liu setupPropertiesChangedMatches(*systemBus, sensorTypes, eventHandler);
418*d7be555eSGeorge Liu matches.emplace_back(std::make_unique<sdbusplus::bus::match_t>(
419*d7be555eSGeorge Liu static_cast<sdbusplus::bus_t&>(*systemBus),
420*d7be555eSGeorge Liu "type='signal',member='PropertiesChanged',path_namespace='" +
421*d7be555eSGeorge Liu std::string(cpuInventoryPath) +
422*d7be555eSGeorge Liu "',arg0namespace='xyz.openbmc_project.Inventory.Item'",
423*d7be555eSGeorge Liu cpuPresenceHandler));
424*d7be555eSGeorge Liu
425*d7be555eSGeorge Liu setupManufacturingModeMatch(*systemBus);
426*d7be555eSGeorge Liu io.run();
427*d7be555eSGeorge Liu }
428