xref: /openbmc/telemetry/src/trigger_factory.cpp (revision c7935fa1)
176833cb5SWludzik, Jozef #include "trigger_factory.hpp"
276833cb5SWludzik, Jozef 
3f763c9e3SSzymon Dompke #include "discrete_threshold.hpp"
41477fe6aSWludzik, Jozef #include "numeric_threshold.hpp"
5f763c9e3SSzymon Dompke #include "on_change_threshold.hpp"
61477fe6aSWludzik, Jozef #include "sensor.hpp"
776833cb5SWludzik, Jozef #include "trigger.hpp"
8d960e1f3SWludzik, Jozef #include "trigger_actions.hpp"
9b7b7e1b6SSzymon Dompke #include "utils/clock.hpp"
101477fe6aSWludzik, Jozef #include "utils/dbus_mapper.hpp"
114416fce6SCezary Zwolak #include "utils/transform.hpp"
124416fce6SCezary Zwolak 
134416fce6SCezary Zwolak namespace ts = utils::tstring;
1476833cb5SWludzik, Jozef 
TriggerFactory(std::shared_ptr<sdbusplus::asio::connection> bus,std::shared_ptr<sdbusplus::asio::object_server> objServer,SensorCache & sensorCache)1576833cb5SWludzik, Jozef TriggerFactory::TriggerFactory(
1676833cb5SWludzik, Jozef     std::shared_ptr<sdbusplus::asio::connection> bus,
171477fe6aSWludzik, Jozef     std::shared_ptr<sdbusplus::asio::object_server> objServer,
18e6d48874SKrzysztof Grobelny     SensorCache& sensorCache) :
1976833cb5SWludzik, Jozef     bus(std::move(bus)),
20e6d48874SKrzysztof Grobelny     objServer(std::move(objServer)), sensorCache(sensorCache)
2176833cb5SWludzik, Jozef {}
2276833cb5SWludzik, Jozef 
updateDiscreteThresholds(std::vector<std::shared_ptr<interfaces::Threshold>> & currentThresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors,const std::vector<discrete::LabeledThresholdParam> & newParams) const2394f71c51SSzymon Dompke void TriggerFactory::updateDiscreteThresholds(
2494f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
25b7b7e1b6SSzymon Dompke     const std::string& triggerId,
2694f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
2794f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
2894f71c51SSzymon Dompke     const Sensors& sensors,
2994f71c51SSzymon Dompke     const std::vector<discrete::LabeledThresholdParam>& newParams) const
3076833cb5SWludzik, Jozef {
3194f71c51SSzymon Dompke     auto oldThresholds = currentThresholds;
3294f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>> newThresholds;
331477fe6aSWludzik, Jozef 
3494f71c51SSzymon Dompke     bool isCurrentOnChange = false;
3594f71c51SSzymon Dompke     if (oldThresholds.size() == 1 &&
3694f71c51SSzymon Dompke         std::holds_alternative<std::monostate>(
3794f71c51SSzymon Dompke             oldThresholds.back()->getThresholdParam()))
3894f71c51SSzymon Dompke     {
3994f71c51SSzymon Dompke         isCurrentOnChange = true;
4094f71c51SSzymon Dompke     }
4194f71c51SSzymon Dompke 
4294f71c51SSzymon Dompke     newThresholds.reserve(newParams.size());
4394f71c51SSzymon Dompke 
4494f71c51SSzymon Dompke     if (!isCurrentOnChange)
4594f71c51SSzymon Dompke     {
4694f71c51SSzymon Dompke         for (const auto& labeledThresholdParam : newParams)
4794f71c51SSzymon Dompke         {
4894f71c51SSzymon Dompke             auto paramChecker = [labeledThresholdParam](auto threshold) {
4994f71c51SSzymon Dompke                 return labeledThresholdParam ==
5094f71c51SSzymon Dompke                        std::get<discrete::LabeledThresholdParam>(
5194f71c51SSzymon Dompke                            threshold->getThresholdParam());
5294f71c51SSzymon Dompke             };
5394f71c51SSzymon Dompke             if (auto existing = std::find_if(oldThresholds.begin(),
5494f71c51SSzymon Dompke                                              oldThresholds.end(), paramChecker);
5594f71c51SSzymon Dompke                 existing != oldThresholds.end())
5694f71c51SSzymon Dompke             {
5794f71c51SSzymon Dompke                 newThresholds.emplace_back(*existing);
5894f71c51SSzymon Dompke                 oldThresholds.erase(existing);
5994f71c51SSzymon Dompke                 continue;
6094f71c51SSzymon Dompke             }
6194f71c51SSzymon Dompke 
62b7b7e1b6SSzymon Dompke             makeDiscreteThreshold(newThresholds, triggerId, triggerActions,
63b7b7e1b6SSzymon Dompke                                   reportIds, sensors, labeledThresholdParam);
6494f71c51SSzymon Dompke         }
6594f71c51SSzymon Dompke     }
6694f71c51SSzymon Dompke     else
6794f71c51SSzymon Dompke     {
6894f71c51SSzymon Dompke         for (const auto& labeledThresholdParam : newParams)
6994f71c51SSzymon Dompke         {
70b7b7e1b6SSzymon Dompke             makeDiscreteThreshold(newThresholds, triggerId, triggerActions,
71b7b7e1b6SSzymon Dompke                                   reportIds, sensors, labeledThresholdParam);
7294f71c51SSzymon Dompke         }
7394f71c51SSzymon Dompke     }
7494f71c51SSzymon Dompke     if (newParams.empty())
7594f71c51SSzymon Dompke     {
7694f71c51SSzymon Dompke         if (isCurrentOnChange)
7794f71c51SSzymon Dompke         {
7894f71c51SSzymon Dompke             newThresholds.emplace_back(*oldThresholds.begin());
7994f71c51SSzymon Dompke         }
8094f71c51SSzymon Dompke         else
8194f71c51SSzymon Dompke         {
82b7b7e1b6SSzymon Dompke             makeOnChangeThreshold(newThresholds, triggerId, triggerActions,
83b7b7e1b6SSzymon Dompke                                   reportIds, sensors);
8494f71c51SSzymon Dompke         }
8594f71c51SSzymon Dompke     }
8694f71c51SSzymon Dompke     currentThresholds = std::move(newThresholds);
8794f71c51SSzymon Dompke }
8894f71c51SSzymon Dompke 
updateNumericThresholds(std::vector<std::shared_ptr<interfaces::Threshold>> & currentThresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors,const std::vector<numeric::LabeledThresholdParam> & newParams) const8994f71c51SSzymon Dompke void TriggerFactory::updateNumericThresholds(
9094f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
91b7b7e1b6SSzymon Dompke     const std::string& triggerId,
9294f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
9394f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
9494f71c51SSzymon Dompke     const Sensors& sensors,
9594f71c51SSzymon Dompke     const std::vector<numeric::LabeledThresholdParam>& newParams) const
9694f71c51SSzymon Dompke {
9794f71c51SSzymon Dompke     auto oldThresholds = currentThresholds;
9894f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>> newThresholds;
9994f71c51SSzymon Dompke 
10094f71c51SSzymon Dompke     newThresholds.reserve(newParams.size());
10194f71c51SSzymon Dompke 
10294f71c51SSzymon Dompke     for (const auto& labeledThresholdParam : newParams)
10394f71c51SSzymon Dompke     {
10494f71c51SSzymon Dompke         auto paramChecker = [labeledThresholdParam](auto threshold) {
10594f71c51SSzymon Dompke             return labeledThresholdParam ==
10694f71c51SSzymon Dompke                    std::get<numeric::LabeledThresholdParam>(
10794f71c51SSzymon Dompke                        threshold->getThresholdParam());
10894f71c51SSzymon Dompke         };
10994f71c51SSzymon Dompke         if (auto existing = std::find_if(oldThresholds.begin(),
11094f71c51SSzymon Dompke                                          oldThresholds.end(), paramChecker);
11194f71c51SSzymon Dompke             existing != oldThresholds.end())
11294f71c51SSzymon Dompke         {
11394f71c51SSzymon Dompke             newThresholds.emplace_back(*existing);
11494f71c51SSzymon Dompke             oldThresholds.erase(existing);
11594f71c51SSzymon Dompke             continue;
11694f71c51SSzymon Dompke         }
11794f71c51SSzymon Dompke 
118b7b7e1b6SSzymon Dompke         makeNumericThreshold(newThresholds, triggerId, triggerActions,
119b7b7e1b6SSzymon Dompke                              reportIds, sensors, labeledThresholdParam);
12094f71c51SSzymon Dompke     }
12194f71c51SSzymon Dompke     currentThresholds = std::move(newThresholds);
12294f71c51SSzymon Dompke }
12394f71c51SSzymon Dompke 
updateThresholds(std::vector<std::shared_ptr<interfaces::Threshold>> & currentThresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors,const LabeledTriggerThresholdParams & newParams) const12494f71c51SSzymon Dompke void TriggerFactory::updateThresholds(
12594f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
126b7b7e1b6SSzymon Dompke     const std::string& triggerId,
12794f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
12894f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
12994f71c51SSzymon Dompke     const Sensors& sensors,
13094f71c51SSzymon Dompke     const LabeledTriggerThresholdParams& newParams) const
13194f71c51SSzymon Dompke {
13294f71c51SSzymon Dompke     if (isTriggerThresholdDiscrete(newParams))
133f763c9e3SSzymon Dompke     {
1344416fce6SCezary Zwolak         const auto& labeledDiscreteThresholdParams =
13594f71c51SSzymon Dompke             std::get<std::vector<discrete::LabeledThresholdParam>>(newParams);
13694f71c51SSzymon Dompke 
137b7b7e1b6SSzymon Dompke         updateDiscreteThresholds(currentThresholds, triggerId, triggerActions,
138b7b7e1b6SSzymon Dompke                                  reportIds, sensors,
139b7b7e1b6SSzymon Dompke                                  labeledDiscreteThresholdParams);
14094f71c51SSzymon Dompke     }
14194f71c51SSzymon Dompke     else
14294f71c51SSzymon Dompke     {
14394f71c51SSzymon Dompke         const auto& labeledNumericThresholdParams =
14494f71c51SSzymon Dompke             std::get<std::vector<numeric::LabeledThresholdParam>>(newParams);
14594f71c51SSzymon Dompke 
146b7b7e1b6SSzymon Dompke         updateNumericThresholds(currentThresholds, triggerId, triggerActions,
147b7b7e1b6SSzymon Dompke                                 reportIds, sensors,
148b7b7e1b6SSzymon Dompke                                 labeledNumericThresholdParams);
14994f71c51SSzymon Dompke     }
15094f71c51SSzymon Dompke }
15194f71c51SSzymon Dompke 
makeDiscreteThreshold(std::vector<std::shared_ptr<interfaces::Threshold>> & thresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors,const discrete::LabeledThresholdParam & thresholdParam) const15294f71c51SSzymon Dompke void TriggerFactory::makeDiscreteThreshold(
15394f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
154b7b7e1b6SSzymon Dompke     const std::string& triggerId,
15594f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
15694f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
15794f71c51SSzymon Dompke     const Sensors& sensors,
15894f71c51SSzymon Dompke     const discrete::LabeledThresholdParam& thresholdParam) const
159f763c9e3SSzymon Dompke {
160f763c9e3SSzymon Dompke     std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
1614416fce6SCezary Zwolak 
162b7b7e1b6SSzymon Dompke     const std::string& thresholdName = thresholdParam.at_label<ts::UserId>();
16394f71c51SSzymon Dompke     discrete::Severity severity = thresholdParam.at_label<ts::Severity>();
16494f71c51SSzymon Dompke     auto dwellTime = Milliseconds(thresholdParam.at_label<ts::DwellTime>());
165b7b7e1b6SSzymon Dompke     const std::string& thresholdValue =
166b7b7e1b6SSzymon Dompke         thresholdParam.at_label<ts::ThresholdValue>();
1674416fce6SCezary Zwolak 
1682001301aSSzymon Dompke     action::discrete::fillActions(actions, triggerActions, severity,
169e6d48874SKrzysztof Grobelny                                   bus->get_io_context(), reportIds);
170f763c9e3SSzymon Dompke 
171f763c9e3SSzymon Dompke     thresholds.emplace_back(std::make_shared<DiscreteThreshold>(
172b7b7e1b6SSzymon Dompke         bus->get_io_context(), triggerId, sensors, std::move(actions),
173b7b7e1b6SSzymon Dompke         Milliseconds(dwellTime), thresholdValue, thresholdName, severity,
174b7b7e1b6SSzymon Dompke         std::make_unique<Clock>()));
175f763c9e3SSzymon Dompke }
17694f71c51SSzymon Dompke 
makeNumericThreshold(std::vector<std::shared_ptr<interfaces::Threshold>> & thresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors,const numeric::LabeledThresholdParam & thresholdParam) const17794f71c51SSzymon Dompke void TriggerFactory::makeNumericThreshold(
17894f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
179b7b7e1b6SSzymon Dompke     const std::string& triggerId,
18094f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
18194f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
18294f71c51SSzymon Dompke     const Sensors& sensors,
18394f71c51SSzymon Dompke     const numeric::LabeledThresholdParam& thresholdParam) const
184f763c9e3SSzymon Dompke {
185f763c9e3SSzymon Dompke     std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
18694f71c51SSzymon Dompke 
18794f71c51SSzymon Dompke     auto type = thresholdParam.at_label<ts::Type>();
18894f71c51SSzymon Dompke     auto dwellTime = Milliseconds(thresholdParam.at_label<ts::DwellTime>());
18994f71c51SSzymon Dompke     auto direction = thresholdParam.at_label<ts::Direction>();
19094f71c51SSzymon Dompke     auto thresholdValue = double{thresholdParam.at_label<ts::ThresholdValue>()};
19194f71c51SSzymon Dompke 
19294f71c51SSzymon Dompke     action::numeric::fillActions(actions, triggerActions, type, thresholdValue,
193e6d48874SKrzysztof Grobelny                                  bus->get_io_context(), reportIds);
19494f71c51SSzymon Dompke 
19594f71c51SSzymon Dompke     thresholds.emplace_back(std::make_shared<NumericThreshold>(
196b7b7e1b6SSzymon Dompke         bus->get_io_context(), triggerId, sensors, std::move(actions),
197b7b7e1b6SSzymon Dompke         dwellTime, direction, thresholdValue, type, std::make_unique<Clock>()));
19894f71c51SSzymon Dompke }
19994f71c51SSzymon Dompke 
makeOnChangeThreshold(std::vector<std::shared_ptr<interfaces::Threshold>> & thresholds,const std::string & triggerId,const std::vector<TriggerAction> & triggerActions,const std::shared_ptr<std::vector<std::string>> & reportIds,const Sensors & sensors) const20094f71c51SSzymon Dompke void TriggerFactory::makeOnChangeThreshold(
20194f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
202b7b7e1b6SSzymon Dompke     const std::string& triggerId,
20394f71c51SSzymon Dompke     const std::vector<TriggerAction>& triggerActions,
20494f71c51SSzymon Dompke     const std::shared_ptr<std::vector<std::string>>& reportIds,
20594f71c51SSzymon Dompke     const Sensors& sensors) const
20694f71c51SSzymon Dompke {
20794f71c51SSzymon Dompke     std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
20894f71c51SSzymon Dompke 
2092001301aSSzymon Dompke     action::discrete::onChange::fillActions(actions, triggerActions,
210e6d48874SKrzysztof Grobelny                                             bus->get_io_context(), reportIds);
211f763c9e3SSzymon Dompke 
212b7b7e1b6SSzymon Dompke     thresholds.emplace_back(std::make_shared<OnChangeThreshold>(
213b7b7e1b6SSzymon Dompke         triggerId, sensors, std::move(actions), std::make_unique<Clock>()));
214f763c9e3SSzymon Dompke }
21594f71c51SSzymon Dompke 
make(const std::string & idIn,const std::string & name,const std::vector<std::string> & triggerActionsIn,const std::vector<std::string> & reportIdsIn,interfaces::TriggerManager & triggerManager,interfaces::JsonStorage & triggerStorage,const LabeledTriggerThresholdParams & labeledThresholdParams,const std::vector<LabeledSensorInfo> & labeledSensorsInfo) const21694f71c51SSzymon Dompke std::unique_ptr<interfaces::Trigger> TriggerFactory::make(
217b7b7e1b6SSzymon Dompke     const std::string& idIn, const std::string& name,
21894f71c51SSzymon Dompke     const std::vector<std::string>& triggerActionsIn,
21994f71c51SSzymon Dompke     const std::vector<std::string>& reportIdsIn,
22094f71c51SSzymon Dompke     interfaces::TriggerManager& triggerManager,
22194f71c51SSzymon Dompke     interfaces::JsonStorage& triggerStorage,
22294f71c51SSzymon Dompke     const LabeledTriggerThresholdParams& labeledThresholdParams,
22394f71c51SSzymon Dompke     const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const
224f763c9e3SSzymon Dompke {
22594f71c51SSzymon Dompke     const auto& sensors = getSensors(labeledSensorsInfo);
2263a1c297aSPatrick Williams     auto triggerActions = utils::transform(triggerActionsIn,
2273a1c297aSPatrick Williams                                            [](const auto& triggerActionStr) {
22894f71c51SSzymon Dompke         return toTriggerAction(triggerActionStr);
22994f71c51SSzymon Dompke     });
23094f71c51SSzymon Dompke     std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
231b7b7e1b6SSzymon Dompke     auto id = std::make_unique<const std::string>(idIn);
23294f71c51SSzymon Dompke 
23394f71c51SSzymon Dompke     auto reportIds = std::make_shared<std::vector<std::string>>(reportIdsIn);
23494f71c51SSzymon Dompke 
235b7b7e1b6SSzymon Dompke     updateThresholds(thresholds, *id, triggerActions, reportIds, sensors,
2364416fce6SCezary Zwolak                      labeledThresholdParams);
2374416fce6SCezary Zwolak 
2381477fe6aSWludzik, Jozef     return std::make_unique<Trigger>(
239b7b7e1b6SSzymon Dompke         bus->get_io_context(), objServer, std::move(id), name, triggerActions,
240b7b7e1b6SSzymon Dompke         reportIds, std::move(thresholds), triggerManager, triggerStorage, *this,
241b7b7e1b6SSzymon Dompke         sensors);
2421477fe6aSWludzik, Jozef }
2431477fe6aSWludzik, Jozef 
getSensors(const std::vector<LabeledSensorInfo> & labeledSensorsInfo) const24494f71c51SSzymon Dompke Sensors TriggerFactory::getSensors(
2454416fce6SCezary Zwolak     const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const
2461477fe6aSWludzik, Jozef {
247dcc4e193SKrzysztof Grobelny     Sensors sensors;
24894f71c51SSzymon Dompke     updateSensors(sensors, labeledSensorsInfo);
24994f71c51SSzymon Dompke     return sensors;
25094f71c51SSzymon Dompke }
25194f71c51SSzymon Dompke 
updateSensors(Sensors & currentSensors,const std::vector<LabeledSensorInfo> & labeledSensorsInfo) const25294f71c51SSzymon Dompke void TriggerFactory::updateSensors(
25394f71c51SSzymon Dompke     Sensors& currentSensors,
25494f71c51SSzymon Dompke     const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const
25594f71c51SSzymon Dompke {
25694f71c51SSzymon Dompke     Sensors oldSensors = currentSensors;
25794f71c51SSzymon Dompke     Sensors newSensors;
2581477fe6aSWludzik, Jozef 
2594416fce6SCezary Zwolak     for (const auto& labeledSensorInfo : labeledSensorsInfo)
2604416fce6SCezary Zwolak     {
26194f71c51SSzymon Dompke         auto existing = std::find_if(oldSensors.begin(), oldSensors.end(),
26294f71c51SSzymon Dompke                                      [labeledSensorInfo](auto sensor) {
2633a1c297aSPatrick Williams             return labeledSensorInfo == sensor->getLabeledSensorInfo();
26494f71c51SSzymon Dompke         });
26594f71c51SSzymon Dompke 
26694f71c51SSzymon Dompke         if (existing != oldSensors.end())
26794f71c51SSzymon Dompke         {
26894f71c51SSzymon Dompke             newSensors.emplace_back(*existing);
26994f71c51SSzymon Dompke             oldSensors.erase(existing);
27094f71c51SSzymon Dompke             continue;
27194f71c51SSzymon Dompke         }
27294f71c51SSzymon Dompke 
2734416fce6SCezary Zwolak         const auto& service = labeledSensorInfo.at_label<ts::Service>();
27494f71c51SSzymon Dompke         const auto& sensorPath = labeledSensorInfo.at_label<ts::Path>();
275b8cc78ddSKrzysztof Grobelny         const auto& metadata = labeledSensorInfo.at_label<ts::Metadata>();
2764416fce6SCezary Zwolak 
27794f71c51SSzymon Dompke         newSensors.emplace_back(sensorCache.makeSensor<Sensor>(
278b8cc78ddSKrzysztof Grobelny             service, sensorPath, metadata, bus->get_io_context(), bus));
2791477fe6aSWludzik, Jozef     }
2804416fce6SCezary Zwolak 
28194f71c51SSzymon Dompke     currentSensors = std::move(newSensors);
28276833cb5SWludzik, Jozef }
2834416fce6SCezary Zwolak 
2844416fce6SCezary Zwolak std::vector<LabeledSensorInfo>
getLabeledSensorsInfo(boost::asio::yield_context & yield,const SensorsInfo & sensorsInfo) const2854416fce6SCezary Zwolak     TriggerFactory::getLabeledSensorsInfo(boost::asio::yield_context& yield,
2864416fce6SCezary Zwolak                                           const SensorsInfo& sensorsInfo) const
2874416fce6SCezary Zwolak {
28894f71c51SSzymon Dompke     if (sensorsInfo.empty())
28994f71c51SSzymon Dompke     {
29094f71c51SSzymon Dompke         return {};
29194f71c51SSzymon Dompke     }
2924416fce6SCezary Zwolak     auto tree = utils::getSubTreeSensors(yield, bus);
29394f71c51SSzymon Dompke     return parseSensorTree(tree, sensorsInfo);
29494f71c51SSzymon Dompke }
2954416fce6SCezary Zwolak 
29694f71c51SSzymon Dompke std::vector<LabeledSensorInfo>
getLabeledSensorsInfo(const SensorsInfo & sensorsInfo) const29794f71c51SSzymon Dompke     TriggerFactory::getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const
29894f71c51SSzymon Dompke {
29994f71c51SSzymon Dompke     if (sensorsInfo.empty())
30094f71c51SSzymon Dompke     {
30194f71c51SSzymon Dompke         return {};
30294f71c51SSzymon Dompke     }
30394f71c51SSzymon Dompke     auto tree = utils::getSubTreeSensors(bus);
30494f71c51SSzymon Dompke     return parseSensorTree(tree, sensorsInfo);
30594f71c51SSzymon Dompke }
30694f71c51SSzymon Dompke 
30794f71c51SSzymon Dompke std::vector<LabeledSensorInfo>
parseSensorTree(const std::vector<utils::SensorTree> & tree,const SensorsInfo & sensorsInfo)30894f71c51SSzymon Dompke     TriggerFactory::parseSensorTree(const std::vector<utils::SensorTree>& tree,
30994f71c51SSzymon Dompke                                     const SensorsInfo& sensorsInfo)
31094f71c51SSzymon Dompke {
3114416fce6SCezary Zwolak     return utils::transform(sensorsInfo, [&tree](const auto& item) {
3124416fce6SCezary Zwolak         const auto& [sensorPath, metadata] = item;
313*c7935fa1SPatrick Williams         auto found = std::find_if(
314*c7935fa1SPatrick Williams             tree.begin(), tree.end(),
315*c7935fa1SPatrick Williams             [path = sensorPath](const auto& x) { return x.first == path; });
3164416fce6SCezary Zwolak 
3174416fce6SCezary Zwolak         if (tree.end() != found)
3184416fce6SCezary Zwolak         {
3194416fce6SCezary Zwolak             const auto& [service, ifaces] = found->second.front();
3204416fce6SCezary Zwolak             return LabeledSensorInfo(service, sensorPath, metadata);
3214416fce6SCezary Zwolak         }
3224416fce6SCezary Zwolak         throw std::runtime_error("Not found");
3234416fce6SCezary Zwolak     });
3244416fce6SCezary Zwolak }
325