Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 3 | #include "interfaces/report_manager.hpp" |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 4 | #include "interfaces/sensor.hpp" |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 5 | #include "interfaces/threshold.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 6 | #include "interfaces/trigger_factory.hpp" |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 7 | #include "sensor_cache.hpp" |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 8 | #include "utils/dbus_mapper.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 9 | |
| 10 | #include <sdbusplus/asio/object_server.hpp> |
| 11 | |
| 12 | class TriggerFactory : public interfaces::TriggerFactory |
| 13 | { |
| 14 | public: |
| 15 | TriggerFactory(std::shared_ptr<sdbusplus::asio::connection> bus, |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 16 | std::shared_ptr<sdbusplus::asio::object_server> objServer, |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 17 | SensorCache& sensorCache); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 18 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 19 | std::unique_ptr<interfaces::Trigger> |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 20 | make(const std::string& id, const std::string& name, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 21 | const std::vector<std::string>& triggerActions, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 22 | const std::vector<std::string>& reportIds, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 23 | interfaces::TriggerManager& triggerManager, |
| 24 | interfaces::JsonStorage& triggerStorage, |
| 25 | const LabeledTriggerThresholdParams& labeledThresholdParams, |
| 26 | const std::vector<LabeledSensorInfo>& labeledSensorsinfo) |
| 27 | const override; |
| 28 | |
| 29 | std::vector<LabeledSensorInfo> |
| 30 | getLabeledSensorsInfo(boost::asio::yield_context& yield, |
Krzysztof Grobelny | fbeb5bf | 2022-01-03 09:41:29 +0100 | [diff] [blame] | 31 | const SensorsInfo& sensorsInfo) const override; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 32 | std::vector<LabeledSensorInfo> |
| 33 | getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const override; |
| 34 | |
| 35 | void updateThresholds( |
| 36 | std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds, |
| 37 | const std::vector<TriggerAction>& triggerActions, |
| 38 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 39 | const Sensors& sensors, |
| 40 | const LabeledTriggerThresholdParams& newParams) const override; |
| 41 | |
| 42 | void updateSensors(Sensors& currentSensors, |
| 43 | const std::vector<LabeledSensorInfo>& labeledSensorsInfo) |
| 44 | const override; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | std::shared_ptr<sdbusplus::asio::connection> bus; |
| 48 | std::shared_ptr<sdbusplus::asio::object_server> objServer; |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 49 | SensorCache& sensorCache; |
| 50 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 51 | Sensors getSensors( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 52 | const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 53 | |
| 54 | static std::vector<LabeledSensorInfo> |
| 55 | parseSensorTree(const std::vector<utils::SensorTree>& tree, |
| 56 | const SensorsInfo& sensorsInfo); |
| 57 | |
| 58 | void updateDiscreteThresholds( |
| 59 | std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds, |
| 60 | const std::vector<TriggerAction>& triggerActions, |
| 61 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 62 | const Sensors& sensors, |
| 63 | const std::vector<discrete::LabeledThresholdParam>& newParams) const; |
| 64 | |
| 65 | void updateNumericThresholds( |
| 66 | std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds, |
| 67 | const std::vector<TriggerAction>& triggerActions, |
| 68 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 69 | const Sensors& sensors, |
| 70 | const std::vector<numeric::LabeledThresholdParam>& newParams) const; |
| 71 | |
| 72 | void makeDiscreteThreshold( |
| 73 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
| 74 | const std::vector<TriggerAction>& triggerActions, |
| 75 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 76 | const Sensors& sensors, |
| 77 | const discrete::LabeledThresholdParam& thresholdParam) const; |
| 78 | |
| 79 | void makeNumericThreshold( |
| 80 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
| 81 | const std::vector<TriggerAction>& triggerActions, |
| 82 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 83 | const Sensors& sensors, |
| 84 | const numeric::LabeledThresholdParam& thresholdParam) const; |
| 85 | |
| 86 | void makeOnChangeThreshold( |
| 87 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
| 88 | const std::vector<TriggerAction>& triggerActions, |
| 89 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 90 | const Sensors& sensors) const; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 91 | }; |