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, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 37 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 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; |
| 51 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 52 | Sensors getSensors( |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 53 | const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 54 | |
| 55 | static std::vector<LabeledSensorInfo> |
| 56 | parseSensorTree(const std::vector<utils::SensorTree>& tree, |
| 57 | const SensorsInfo& sensorsInfo); |
| 58 | |
| 59 | void updateDiscreteThresholds( |
| 60 | std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 61 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 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, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 69 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 70 | const std::vector<TriggerAction>& triggerActions, |
| 71 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 72 | const Sensors& sensors, |
| 73 | const std::vector<numeric::LabeledThresholdParam>& newParams) const; |
| 74 | |
| 75 | void makeDiscreteThreshold( |
| 76 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 77 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 78 | const std::vector<TriggerAction>& triggerActions, |
| 79 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 80 | const Sensors& sensors, |
| 81 | const discrete::LabeledThresholdParam& thresholdParam) const; |
| 82 | |
| 83 | void makeNumericThreshold( |
| 84 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 85 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 86 | const std::vector<TriggerAction>& triggerActions, |
| 87 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 88 | const Sensors& sensors, |
| 89 | const numeric::LabeledThresholdParam& thresholdParam) const; |
| 90 | |
| 91 | void makeOnChangeThreshold( |
| 92 | std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds, |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 93 | const std::string& triggerId, |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 94 | const std::vector<TriggerAction>& triggerActions, |
| 95 | const std::shared_ptr<std::vector<std::string>>& reportIds, |
| 96 | const Sensors& sensors) const; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 97 | }; |