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