blob: a2ad568e96296ae007e00e8ceb472ea26c94eaf6 [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,
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020037 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010038 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, Jozef76833cb2020-12-21 14:42:41 +010046
47 private:
48 std::shared_ptr<sdbusplus::asio::connection> bus;
49 std::shared_ptr<sdbusplus::asio::object_server> objServer;
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010050 SensorCache& sensorCache;
51
Szymon Dompke94f71c52021-12-10 07:16:33 +010052 Sensors getSensors(
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000053 const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
Szymon Dompke94f71c52021-12-10 07:16:33 +010054
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 Dompkeb7b7e1b2022-05-19 10:15:48 +020061 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010062 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 Dompkeb7b7e1b2022-05-19 10:15:48 +020069 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010070 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 Dompkeb7b7e1b2022-05-19 10:15:48 +020077 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010078 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 Dompkeb7b7e1b2022-05-19 10:15:48 +020085 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010086 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 Dompkeb7b7e1b2022-05-19 10:15:48 +020093 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010094 const std::vector<TriggerAction>& triggerActions,
95 const std::shared_ptr<std::vector<std::string>>& reportIds,
96 const Sensors& sensors) const;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010097};