blob: 4db6941b89a851897bdc7642961da48f51ceda46 [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01003#include "interfaces/report_manager.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01004#include "interfaces/trigger_factory.hpp"
5#include "interfaces/trigger_manager.hpp"
Szymon Dompkee28aa532021-10-27 12:33:12 +02006#include "trigger.hpp"
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02007#include "utils/dbus_path_utils.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01008
9#include <sdbusplus/asio/object_server.hpp>
10
11#include <memory>
12#include <vector>
13
14class TriggerManager : public interfaces::TriggerManager
15{
16 public:
17 TriggerManager(
18 std::unique_ptr<interfaces::TriggerFactory> triggerFactory,
Cezary Zwolaka4e67612021-02-18 13:16:16 +010019 std::unique_ptr<interfaces::JsonStorage> triggerStorage,
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010020 const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
21
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010022 TriggerManager(const TriggerManager&) = delete;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010023 TriggerManager(TriggerManager&&) = delete;
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010024 TriggerManager& operator=(const TriggerManager&) = delete;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010025 TriggerManager& operator=(TriggerManager&&) = delete;
26
27 void removeTrigger(const interfaces::Trigger* trigger) override;
28
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010029 static void verifyReportIds(const std::vector<std::string>& newReportIds);
30
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010031 private:
32 std::unique_ptr<interfaces::TriggerFactory> triggerFactory;
Cezary Zwolaka4e67612021-02-18 13:16:16 +010033 std::unique_ptr<interfaces::JsonStorage> triggerStorage;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010034 std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface;
35 std::vector<std::unique_ptr<interfaces::Trigger>> triggers;
36
Szymon Dompkee28aa532021-10-27 12:33:12 +020037 void verifyAddTrigger(const std::string& triggerId,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010038 const std::string& triggerName,
39 const std::vector<std::string>& newReportIds) const;
Cezary Zwolak4416fce2021-03-17 03:21:06 +010040
41 interfaces::Trigger&
Szymon Dompkee28aa532021-10-27 12:33:12 +020042 addTrigger(const std::string& triggerId, const std::string& triggerName,
Szymon Dompke20013012021-07-23 09:54:20 +020043 const std::vector<std::string>& triggerActions,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010044 const std::vector<LabeledSensorInfo>& labeledSensors,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010045 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010046 const LabeledTriggerThresholdParams& labeledThresholdParams);
47 void loadFromPersistent();
48
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010049 public:
50 static constexpr size_t maxTriggers{TELEMETRY_MAX_TRIGGERS};
Szymon Dompkee28aa532021-10-27 12:33:12 +020051 static constexpr size_t maxTriggerIdLength{
52 TELEMETRY_MAX_DBUS_PATH_LENGTH -
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020053 utils::constants::triggerDirStr.length()};
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010054 static constexpr const char* triggerManagerIfaceName =
55 "xyz.openbmc_project.Telemetry.TriggerManager";
56 static constexpr const char* triggerManagerPath =
57 "/xyz/openbmc_project/Telemetry/Triggers";
Szymon Dompkee28aa532021-10-27 12:33:12 +020058 static constexpr const char* triggerNameDefault = "Trigger";
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010059};