xref: /openbmc/telemetry/src/trigger.hpp (revision b7b7e1b603fd9df56a72547c8048d182a001d647)
1 #pragma once
2 
3 #include "interfaces/json_storage.hpp"
4 #include "interfaces/threshold.hpp"
5 #include "interfaces/trigger.hpp"
6 #include "interfaces/trigger_factory.hpp"
7 #include "interfaces/trigger_manager.hpp"
8 #include "types/trigger_types.hpp"
9 #include "utils/messanger.hpp"
10 
11 #include <boost/asio/io_context.hpp>
12 #include <sdbusplus/asio/object_server.hpp>
13 
14 #include <memory>
15 
16 class Trigger : public interfaces::Trigger
17 {
18   public:
19     Trigger(boost::asio::io_context& ioc,
20             const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
21             TriggerId&& id, const std::string& name,
22             const std::vector<TriggerAction>& triggerActions,
23             const std::shared_ptr<std::vector<std::string>> reportIds,
24             std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholds,
25             interfaces::TriggerManager& triggerManager,
26             interfaces::JsonStorage& triggerStorage,
27             const interfaces::TriggerFactory& triggerFactory,
28             Sensors sensorsIn);
29 
30     Trigger(const Trigger&) = delete;
31     Trigger(Trigger&&) = delete;
32     Trigger& operator=(const Trigger&) = delete;
33     Trigger& operator=(Trigger&&) = delete;
34 
35     std::string getId() const override
36     {
37         return *id;
38     }
39 
40     std::string getPath() const override
41     {
42         return path;
43     }
44 
45     bool storeConfiguration() const;
46 
47   private:
48     std::vector<LabeledSensorInfo> getLabeledSensorInfo() const;
49     std::vector<LabeledThresholdParam> getLabeledThresholds() const;
50     bool isDiscreate() const;
51 
52     const TriggerId id;
53     std::string name;
54     std::vector<TriggerAction> triggerActions;
55     std::string path;
56     bool persistent = false;
57     std::shared_ptr<std::vector<std::string>> reportIds;
58     std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
59     std::unique_ptr<sdbusplus::asio::dbus_interface> triggerIface;
60     std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
61 
62     interfaces::JsonStorage::FilePath fileName;
63     interfaces::JsonStorage& triggerStorage;
64     Sensors sensors;
65     utils::Messanger messanger;
66 
67   public:
68     static constexpr const char* triggerIfaceName =
69         "xyz.openbmc_project.Telemetry.Trigger";
70     static constexpr const char* triggerDir =
71         "/xyz/openbmc_project/Telemetry/Triggers/";
72     static constexpr const char* deleteIfaceName =
73         "xyz.openbmc_project.Object.Delete";
74     static constexpr size_t triggerVersion = 2;
75 };
76