xref: /openbmc/telemetry/src/trigger.hpp (revision e28aa53dc1492f09a64dc9f1dbfd5b6dba06e31f)
1 #pragma once
2 
3 #include "interfaces/json_storage.hpp"
4 #include "interfaces/threshold.hpp"
5 #include "interfaces/trigger.hpp"
6 #include "interfaces/trigger_manager.hpp"
7 #include "types/trigger_types.hpp"
8 
9 #include <boost/asio/io_context.hpp>
10 #include <sdbusplus/asio/object_server.hpp>
11 
12 #include <memory>
13 
14 class Trigger : public interfaces::Trigger
15 {
16   public:
17     Trigger(boost::asio::io_context& ioc,
18             const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
19             const std::string& id, const std::string& name,
20             const std::vector<std::string>& triggerActions,
21             const std::vector<std::string>& reportNames,
22             const std::vector<LabeledSensorInfo>& LabeledSensorsInfoIn,
23             const LabeledTriggerThresholdParams& labeledThresholdParamsIn,
24             std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholds,
25             interfaces::TriggerManager& triggerManager,
26             interfaces::JsonStorage& triggerStorage);
27 
28     Trigger(const Trigger&) = delete;
29     Trigger(Trigger&&) = delete;
30     Trigger& operator=(const Trigger&) = delete;
31     Trigger& operator=(Trigger&&) = delete;
32 
33     std::string getId() const override
34     {
35         return id;
36     }
37 
38     std::string getPath() const override
39     {
40         return path;
41     }
42 
43     bool storeConfiguration() const;
44 
45   private:
46     std::string id;
47     std::string name;
48     std::vector<std::string> triggerActions;
49     std::string path;
50     bool persistent = false;
51     std::vector<std::string> reportNames;
52     std::vector<LabeledSensorInfo> labeledSensorsInfo;
53     LabeledTriggerThresholdParams labeledThresholdParams;
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 
61   public:
62     static constexpr const char* triggerIfaceName =
63         "xyz.openbmc_project.Telemetry.Trigger";
64     static constexpr const char* triggerDir =
65         "/xyz/openbmc_project/Telemetry/Triggers/";
66     static constexpr const char* deleteIfaceName =
67         "xyz.openbmc_project.Object.Delete";
68     static constexpr size_t triggerVersion = 0;
69 };
70