xref: /openbmc/telemetry/src/trigger_factory.hpp (revision 94f71c51)
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                    interfaces::ReportManager& reportManager);
19 
20     std::unique_ptr<interfaces::Trigger>
21         make(const std::string& id, const std::string& name,
22              const std::vector<std::string>& triggerActions,
23              const std::vector<std::string>& reportIds,
24              interfaces::TriggerManager& triggerManager,
25              interfaces::JsonStorage& triggerStorage,
26              const LabeledTriggerThresholdParams& labeledThresholdParams,
27              const std::vector<LabeledSensorInfo>& labeledSensorsinfo)
28             const override;
29 
30     std::vector<LabeledSensorInfo>
31         getLabeledSensorsInfo(boost::asio::yield_context& yield,
32                               const SensorsInfo& sensorsInfo) const override;
33     std::vector<LabeledSensorInfo>
34         getLabeledSensorsInfo(const SensorsInfo& sensorsInfo) const override;
35 
36     void updateThresholds(
37         std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
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     interfaces::ReportManager& reportManager;
52 
53     Sensors getSensors(
54         const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const;
55 
56     static std::vector<LabeledSensorInfo>
57         parseSensorTree(const std::vector<utils::SensorTree>& tree,
58                         const SensorsInfo& sensorsInfo);
59 
60     void updateDiscreteThresholds(
61         std::vector<std::shared_ptr<interfaces::Threshold>>& currentThresholds,
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::vector<TriggerAction>& triggerActions,
70         const std::shared_ptr<std::vector<std::string>>& reportIds,
71         const Sensors& sensors,
72         const std::vector<numeric::LabeledThresholdParam>& newParams) const;
73 
74     void makeDiscreteThreshold(
75         std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
76         const std::vector<TriggerAction>& triggerActions,
77         const std::shared_ptr<std::vector<std::string>>& reportIds,
78         const Sensors& sensors,
79         const discrete::LabeledThresholdParam& thresholdParam) const;
80 
81     void makeNumericThreshold(
82         std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
83         const std::vector<TriggerAction>& triggerActions,
84         const std::shared_ptr<std::vector<std::string>>& reportIds,
85         const Sensors& sensors,
86         const numeric::LabeledThresholdParam& thresholdParam) const;
87 
88     void makeOnChangeThreshold(
89         std::vector<std::shared_ptr<interfaces::Threshold>>& thresholds,
90         const std::vector<TriggerAction>& triggerActions,
91         const std::shared_ptr<std::vector<std::string>>& reportIds,
92         const Sensors& sensors) const;
93 };
94