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