xref: /openbmc/telemetry/src/trigger_factory.hpp (revision 973b4bb0)
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::string& triggerId,
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;
46 
47   private:
48     std::shared_ptr<sdbusplus::asio::connection> bus;
49     std::shared_ptr<sdbusplus::asio::object_server> objServer;
50     SensorCache& sensorCache;
51 
52     Sensors getSensors(
53         const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
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,
61         const std::string& triggerId,
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::string& triggerId,
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,
77         const std::string& triggerId,
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,
85         const std::string& triggerId,
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,
93         const std::string& triggerId,
94         const std::vector<TriggerAction>& triggerActions,
95         const std::shared_ptr<std::vector<std::string>>& reportIds,
96         const Sensors& sensors) const;
97 };
98