Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 3 | #include "interfaces/report_manager.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 4 | #include "interfaces/trigger_factory.hpp" |
| 5 | #include "interfaces/trigger_manager.hpp" |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 6 | #include "trigger.hpp" |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 7 | #include "utils/dbus_path_utils.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 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, |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 19 | std::unique_ptr<interfaces::JsonStorage> triggerStorage, |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 20 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer); |
| 21 | |
Krzysztof Grobelny | 31db7f7 | 2021-12-21 12:26:22 +0100 | [diff] [blame] | 22 | TriggerManager(const TriggerManager&) = delete; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 23 | TriggerManager(TriggerManager&&) = delete; |
Krzysztof Grobelny | 31db7f7 | 2021-12-21 12:26:22 +0100 | [diff] [blame] | 24 | TriggerManager& operator=(const TriggerManager&) = delete; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 25 | TriggerManager& operator=(TriggerManager&&) = delete; |
| 26 | |
| 27 | void removeTrigger(const interfaces::Trigger* trigger) override; |
| 28 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 29 | static void verifyReportIds(const std::vector<std::string>& newReportIds); |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 30 | static void verifyThresholdParams( |
| 31 | const LabeledTriggerThresholdParams& thresholdParams); |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 32 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 33 | private: |
| 34 | std::unique_ptr<interfaces::TriggerFactory> triggerFactory; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 35 | std::unique_ptr<interfaces::JsonStorage> triggerStorage; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 36 | std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface; |
| 37 | std::vector<std::unique_ptr<interfaces::Trigger>> triggers; |
| 38 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 39 | void verifyAddTrigger( |
| 40 | const std::vector<std::string>& reportIds, |
| 41 | const LabeledTriggerThresholdParams& thresholdParams) const; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 42 | |
| 43 | interfaces::Trigger& |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 44 | addTrigger(const std::string& triggerId, const std::string& triggerName, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 45 | const std::vector<std::string>& triggerActions, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 46 | const std::vector<LabeledSensorInfo>& labeledSensors, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 47 | const std::vector<std::string>& reportIds, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 48 | const LabeledTriggerThresholdParams& labeledThresholdParams); |
| 49 | void loadFromPersistent(); |
| 50 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 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"; |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 57 | static constexpr std::string_view triggerNameDefault = "Trigger"; |
| 58 | |
| 59 | static_assert(!triggerNameDefault.empty(), |
| 60 | "Default trigger name cannot be empty."); |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 61 | }; |