blob: 2c76c3a6a84cd87353307900fff47ef3d16f22b6 [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"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01007
8#include <sdbusplus/asio/object_server.hpp>
9
10#include <memory>
11#include <vector>
12
13class TriggerManager : public interfaces::TriggerManager
14{
15 public:
16 TriggerManager(
17 std::unique_ptr<interfaces::TriggerFactory> triggerFactory,
Cezary Zwolaka4e67612021-02-18 13:16:16 +010018 std::unique_ptr<interfaces::JsonStorage> triggerStorage,
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010019 const std::shared_ptr<sdbusplus::asio::object_server>& objServer);
20
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010021 TriggerManager(const TriggerManager&) = delete;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010022 TriggerManager(TriggerManager&&) = delete;
Krzysztof Grobelny31db7f72021-12-21 12:26:22 +010023 TriggerManager& operator=(const TriggerManager&) = delete;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010024 TriggerManager& operator=(TriggerManager&&) = delete;
25
26 void removeTrigger(const interfaces::Trigger* trigger) override;
27
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010028 static void verifyReportIds(const std::vector<std::string>& newReportIds);
29
30 std::vector<std::string>
31 getTriggerIdsForReport(const std::string& reportId) const override;
32
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010033 private:
34 std::unique_ptr<interfaces::TriggerFactory> triggerFactory;
Cezary Zwolaka4e67612021-02-18 13:16:16 +010035 std::unique_ptr<interfaces::JsonStorage> triggerStorage;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010036 std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface;
37 std::vector<std::unique_ptr<interfaces::Trigger>> triggers;
38
Szymon Dompkee28aa532021-10-27 12:33:12 +020039 void verifyAddTrigger(const std::string& triggerId,
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010040 const std::string& triggerName,
41 const std::vector<std::string>& newReportIds) const;
Cezary Zwolak4416fce2021-03-17 03:21:06 +010042
43 interfaces::Trigger&
Szymon Dompkee28aa532021-10-27 12:33:12 +020044 addTrigger(const std::string& triggerId, const std::string& triggerName,
Szymon Dompke20013012021-07-23 09:54:20 +020045 const std::vector<std::string>& triggerActions,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010046 const std::vector<LabeledSensorInfo>& labeledSensors,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010047 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010048 const LabeledTriggerThresholdParams& labeledThresholdParams);
49 void loadFromPersistent();
50
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010051 public:
52 static constexpr size_t maxTriggers{TELEMETRY_MAX_TRIGGERS};
Szymon Dompkee28aa532021-10-27 12:33:12 +020053 static constexpr size_t maxTriggerIdLength{
54 TELEMETRY_MAX_DBUS_PATH_LENGTH -
55 std::string_view(Trigger::triggerDir).length()};
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010056 static constexpr const char* triggerManagerIfaceName =
57 "xyz.openbmc_project.Telemetry.TriggerManager";
58 static constexpr const char* triggerManagerPath =
59 "/xyz/openbmc_project/Telemetry/Triggers";
Szymon Dompkee28aa532021-10-27 12:33:12 +020060 static constexpr const char* triggerNameDefault = "Trigger";
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010061};