xref: /openbmc/telemetry/src/trigger.hpp (revision fdb06a14)
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             const std::string& 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::string id;
49     std::string name;
50     std::vector<TriggerAction> triggerActions;
51     std::string path;
52     bool persistent = false;
53     std::shared_ptr<std::vector<std::string>> reportIds;
54     std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
55     std::unique_ptr<sdbusplus::asio::dbus_interface> triggerIface;
56     std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
57 
58     interfaces::JsonStorage::FilePath fileName;
59     interfaces::JsonStorage& triggerStorage;
60     Sensors sensors;
61     utils::Messanger messanger;
62 
63   public:
64     static constexpr const char* triggerIfaceName =
65         "xyz.openbmc_project.Telemetry.Trigger";
66     static constexpr const char* triggerDir =
67         "/xyz/openbmc_project/Telemetry/Triggers/";
68     static constexpr const char* deleteIfaceName =
69         "xyz.openbmc_project.Object.Delete";
70     static constexpr size_t triggerVersion = 1;
71 };
72