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" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 7 | |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <vector> |
| 12 | |
| 13 | class TriggerManager : public interfaces::TriggerManager |
| 14 | { |
| 15 | public: |
| 16 | TriggerManager( |
| 17 | std::unique_ptr<interfaces::TriggerFactory> triggerFactory, |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 18 | std::unique_ptr<interfaces::JsonStorage> triggerStorage, |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 19 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer); |
| 20 | |
Krzysztof Grobelny | 31db7f7 | 2021-12-21 12:26:22 +0100 | [diff] [blame] | 21 | TriggerManager(const TriggerManager&) = delete; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 22 | TriggerManager(TriggerManager&&) = delete; |
Krzysztof Grobelny | 31db7f7 | 2021-12-21 12:26:22 +0100 | [diff] [blame] | 23 | TriggerManager& operator=(const TriggerManager&) = delete; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 24 | TriggerManager& operator=(TriggerManager&&) = delete; |
| 25 | |
| 26 | void removeTrigger(const interfaces::Trigger* trigger) override; |
| 27 | |
| 28 | private: |
| 29 | std::unique_ptr<interfaces::TriggerFactory> triggerFactory; |
Cezary Zwolak | a4e6761 | 2021-02-18 13:16:16 +0100 | [diff] [blame] | 30 | std::unique_ptr<interfaces::JsonStorage> triggerStorage; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 31 | std::unique_ptr<sdbusplus::asio::dbus_interface> managerIface; |
| 32 | std::vector<std::unique_ptr<interfaces::Trigger>> triggers; |
| 33 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 34 | void verifyAddTrigger(const std::string& triggerId, |
| 35 | const std::string& triggerName) const; |
| 36 | std::string generateId(const std::string& prefix, |
| 37 | const std::string& triggerName) const; |
| 38 | static void verifyTriggerIdLength(const std::string& triggerId); |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 39 | |
| 40 | interfaces::Trigger& |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 41 | addTrigger(const std::string& triggerId, const std::string& triggerName, |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 42 | const std::vector<std::string>& triggerActions, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 43 | const std::vector<LabeledSensorInfo>& labeledSensors, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 44 | const std::vector<std::string>& reportIds, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 45 | const LabeledTriggerThresholdParams& labeledThresholdParams); |
| 46 | void loadFromPersistent(); |
| 47 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 48 | public: |
| 49 | static constexpr size_t maxTriggers{TELEMETRY_MAX_TRIGGERS}; |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 50 | static constexpr size_t maxTriggerIdLength{ |
| 51 | TELEMETRY_MAX_DBUS_PATH_LENGTH - |
| 52 | std::string_view(Trigger::triggerDir).length()}; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 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 | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 57 | static constexpr const char* triggerNameDefault = "Trigger"; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 58 | }; |