blob: 40dfcfde8800ea3b1ae0f4ffe619e6ecd3f50df3 [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01003#include "interfaces/report_manager.hpp"
Wludzik, Jozef1477fe62021-01-02 11:56:10 +01004#include "interfaces/sensor.hpp"
Szymon Dompke94f71c52021-12-10 07:16:33 +01005#include "interfaces/threshold.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01006#include "interfaces/trigger_factory.hpp"
Wludzik, Jozef1477fe62021-01-02 11:56:10 +01007#include "sensor_cache.hpp"
Szymon Dompke94f71c52021-12-10 07:16:33 +01008#include "utils/dbus_mapper.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01009
10#include <sdbusplus/asio/object_server.hpp>
11
12class TriggerFactory : public interfaces::TriggerFactory
13{
14 public:
15 TriggerFactory(std::shared_ptr<sdbusplus::asio::connection> bus,
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010016 std::shared_ptr<sdbusplus::asio::object_server> objServer,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010017 SensorCache& sensorCache);
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010018
Cezary Zwolak4416fce2021-03-17 03:21:06 +010019 std::unique_ptr<interfaces::Trigger>
Szymon Dompkee28aa532021-10-27 12:33:12 +020020 make(const std::string& id, const std::string& name,
Szymon Dompke20013012021-07-23 09:54:20 +020021 const std::vector<std::string>& triggerActions,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010022 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010023 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 Grobelnyfbeb5bf2022-01-03 09:41:29 +010031 const SensorsInfo& sensorsInfo) const override;
Szymon Dompke94f71c52021-12-10 07:16:33 +010032 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, Jozef76833cb2020-12-21 14:42:41 +010045
46 private:
47 std::shared_ptr<sdbusplus::asio::connection> bus;
48 std::shared_ptr<sdbusplus::asio::object_server> objServer;
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010049 SensorCache& sensorCache;
50
Szymon Dompke94f71c52021-12-10 07:16:33 +010051 Sensors getSensors(
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000052 const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
Szymon Dompke94f71c52021-12-10 07:16:33 +010053
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, Jozef76833cb2020-12-21 14:42:41 +010091};