xref: /openbmc/telemetry/src/trigger_manager.hpp (revision 32305f14)
1 #pragma once
2 
3 #include "interfaces/report_manager.hpp"
4 #include "interfaces/trigger_factory.hpp"
5 #include "interfaces/trigger_manager.hpp"
6 #include "trigger.hpp"
7 #include "utils/dbus_path_utils.hpp"
8 
9 #include <sdbusplus/asio/object_server.hpp>
10 
11 #include <memory>
12 #include <vector>
13 
14 class TriggerManager : public interfaces::TriggerManager
15 {
16   public:
17     TriggerManager(
18         std::unique_ptr<interfaces::TriggerFactory> triggerFactory,
19         std::unique_ptr<interfaces::JsonStorage> triggerStorage,
20         const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
21 
22     TriggerManager(const TriggerManager&) = delete;
23     TriggerManager(TriggerManager&&) = delete;
24     TriggerManager& operator=(const TriggerManager&) = delete;
25     TriggerManager& operator=(TriggerManager&&) = delete;
26 
27     void removeTrigger(const interfaces::Trigger* trigger) override;
28 
29     static void verifyReportIds(const std::vector<std::string>& newReportIds);
30     static void verifyThresholdParams(
31         const LabeledTriggerThresholdParams& thresholdParams);
32 
33   private:
34     std::unique_ptr<interfaces::TriggerFactory> triggerFactory;
35     std::unique_ptr<interfaces::JsonStorage> triggerStorage;
36     std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface;
37     std::vector<std::unique_ptr<interfaces::Trigger>> triggers;
38 
39     void verifyAddTrigger(
40         const std::vector<std::string>& reportIds,
41         const LabeledTriggerThresholdParams& thresholdParams) const;
42 
43     interfaces::Trigger&
44         addTrigger(const std::string& triggerId, const std::string& triggerName,
45                    const std::vector<std::string>& triggerActions,
46                    const std::vector<LabeledSensorInfo>& labeledSensors,
47                    const std::vector<std::string>& reportIds,
48                    const LabeledTriggerThresholdParams& labeledThresholdParams);
49     void loadFromPersistent();
50 
51   public:
52     static constexpr size_t maxTriggers{TELEMETRY_MAX_TRIGGERS};
53     static constexpr const char* triggerManagerIfaceName =
54         "xyz.openbmc_project.Telemetry.TriggerManager";
55     static constexpr const char* triggerManagerPath =
56         "/xyz/openbmc_project/Telemetry/Triggers";
57     static constexpr std::string_view triggerNameDefault = "Trigger";
58 
59     static_assert(!triggerNameDefault.empty(),
60                   "Default trigger name cannot be empty.");
61 };
62