blob: e63633413ce11d37499cfe9bc3e683bd5c4e83b7 [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
Cezary Zwolaka4e67612021-02-18 13:16:16 +01003#include "interfaces/json_storage.hpp"
Wludzik, Jozef1477fe62021-01-02 11:56:10 +01004#include "interfaces/threshold.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01005#include "interfaces/trigger.hpp"
Szymon Dompke94f71c52021-12-10 07:16:33 +01006#include "interfaces/trigger_factory.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01007#include "interfaces/trigger_manager.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00008#include "types/trigger_types.hpp"
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +01009#include "utils/messanger.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010010
11#include <boost/asio/io_context.hpp>
12#include <sdbusplus/asio/object_server.hpp>
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020013#include <sdbusplus/message.hpp>
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010014
15#include <memory>
16
17class Trigger : public interfaces::Trigger
18{
19 public:
Cezary Zwolak4416fce2021-03-17 03:21:06 +010020 Trigger(boost::asio::io_context& ioc,
21 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020022 TriggerId&& id, const std::string& name,
Szymon Dompke94f71c52021-12-10 07:16:33 +010023 const std::vector<TriggerAction>& triggerActions,
24 const std::shared_ptr<std::vector<std::string>> reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010025 std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholds,
26 interfaces::TriggerManager& triggerManager,
Szymon Dompke94f71c52021-12-10 07:16:33 +010027 interfaces::JsonStorage& triggerStorage,
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010028 const interfaces::TriggerFactory& triggerFactory,
29 Sensors sensorsIn);
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010030
31 Trigger(const Trigger&) = delete;
32 Trigger(Trigger&&) = delete;
33 Trigger& operator=(const Trigger&) = delete;
34 Trigger& operator=(Trigger&&) = delete;
35
Szymon Dompkee28aa532021-10-27 12:33:12 +020036 std::string getId() const override
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010037 {
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020038 return *id;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010039 }
40
41 std::string getPath() const override
42 {
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020043 return path.str;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010044 }
45
Cezary Zwolaka4e67612021-02-18 13:16:16 +010046 bool storeConfiguration() const;
47
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010048 private:
Krzysztof Grobelny55824552022-02-18 16:15:31 +010049 std::vector<LabeledSensorInfo> getLabeledSensorInfo() const;
50 std::vector<LabeledThresholdParam> getLabeledThresholds() const;
51 bool isDiscreate() const;
52
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020053 const TriggerId id;
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020054 const sdbusplus::message::object_path path;
Szymon Dompkee28aa532021-10-27 12:33:12 +020055 std::string name;
Szymon Dompke94f71c52021-12-10 07:16:33 +010056 std::vector<TriggerAction> triggerActions;
Cezary Zwolaka4e67612021-02-18 13:16:16 +010057 bool persistent = false;
Szymon Dompke94f71c52021-12-10 07:16:33 +010058 std::shared_ptr<std::vector<std::string>> reportIds;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010059 std::unique_ptr<sdbusplus::asio::dbus_interface> deleteIface;
60 std::unique_ptr<sdbusplus::asio::dbus_interface> triggerIface;
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010061 std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010062
Cezary Zwolaka4e67612021-02-18 13:16:16 +010063 interfaces::JsonStorage::FilePath fileName;
64 interfaces::JsonStorage& triggerStorage;
Szymon Dompke94f71c52021-12-10 07:16:33 +010065 Sensors sensors;
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +010066 utils::Messanger messanger;
Cezary Zwolaka4e67612021-02-18 13:16:16 +010067
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010068 public:
69 static constexpr const char* triggerIfaceName =
70 "xyz.openbmc_project.Telemetry.Trigger";
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010071 static constexpr const char* deleteIfaceName =
72 "xyz.openbmc_project.Object.Delete";
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020073 static constexpr size_t triggerVersion = 2;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010074};