xref: /openbmc/telemetry/src/trigger_factory.hpp (revision e6d4887453f0b23b46c012da7cb26f2beb38ef0e)
1 #pragma once
2 
3 #include "interfaces/report_manager.hpp"
4 #include "interfaces/sensor.hpp"
5 #include "interfaces/threshold.hpp"
6 #include "interfaces/trigger_factory.hpp"
7 #include "sensor_cache.hpp"
8 #include "utils/dbus_mapper.hpp"
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,
16                    std::shared_ptr<sdbusplus::asio::object_server> objServer,
17                    SensorCache& sensorCache);
18 
19     std::unique_ptr<interfaces::Trigger>
20         make(const std::string& id, const std::string& name,
21              const std::vector<std::string>& triggerActions,
22              const std::vector<std::string>& reportIds,
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,
31                               const SensorsInfo& sensorsInfo) const override;
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;
45 
46   private:
47     std::shared_ptr<sdbusplus::asio::connection> bus;
48     std::shared_ptr<sdbusplus::asio::object_server> objServer;
49     SensorCache& sensorCache;
50 
51     Sensors getSensors(
52         const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
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;
91 };
92