blob: b39941c2c79000efc76427ae0f4d04404c4a755d [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02003#include "report.hpp"
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +01004#include "types/duration_types.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00005#include "types/trigger_types.hpp"
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02006#include "utils/dbus_path_utils.hpp"
7#include "utils/transform.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01008
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +00009#include <sdbusplus/message.hpp>
10
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010011#include <chrono>
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010012#include <utility>
13
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020014using sdbusplus::message::object_path;
15
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010016class TriggerParams
17{
18 public:
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020019 TriggerParams()
20 {
Patrick Williams3a1c2972023-05-10 07:51:04 -050021 reportsProperty = utils::transform(reportIdsProperty,
22 [](const auto& id) {
23 return utils::pathAppend(utils::constants::reportDirPath, id);
24 });
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020025 }
26
Szymon Dompke32305f12022-07-05 15:37:21 +020027 TriggerParams& id(std::string_view val)
Szymon Dompkee28aa532021-10-27 12:33:12 +020028 {
Szymon Dompke32305f12022-07-05 15:37:21 +020029 idProperty = val;
Szymon Dompkee28aa532021-10-27 12:33:12 +020030 return *this;
31 }
32
33 const std::string& id() const
34 {
35 return idProperty;
36 }
37
Szymon Dompke32305f12022-07-05 15:37:21 +020038 TriggerParams& name(std::string_view val)
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010039 {
Szymon Dompke32305f12022-07-05 15:37:21 +020040 nameProperty = val;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010041 return *this;
42 }
43
44 const std::string& name() const
45 {
46 return nameProperty;
47 }
48
Szymon Dompke94f71c52021-12-10 07:16:33 +010049 TriggerParams& triggerActions(const std::vector<TriggerAction>& val)
Szymon Dompkef763c9e2021-03-12 09:19:22 +010050 {
Szymon Dompke20013012021-07-23 09:54:20 +020051 triggerActionsProperty = val;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010052 return *this;
53 }
54
Szymon Dompke94f71c52021-12-10 07:16:33 +010055 const std::vector<TriggerAction>& triggerActions() const
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010056 {
Szymon Dompke20013012021-07-23 09:54:20 +020057 return triggerActionsProperty;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010058 }
59
Cezary Zwolak4416fce2021-03-17 03:21:06 +010060 const std::vector<LabeledSensorInfo>& sensors() const
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010061 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010062 return labeledSensorsProperty;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010063 }
64
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010065 const std::vector<std::string>& reportIds() const
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010066 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010067 return reportIdsProperty;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010068 }
69
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010070 TriggerParams& reportIds(std::vector<std::string> val)
71 {
72 reportIdsProperty = std::move(val);
Patrick Williams3a1c2972023-05-10 07:51:04 -050073 reportsProperty = utils::transform<std::vector>(reportIdsProperty,
74 [](const auto& id) {
75 return utils::pathAppend(utils::constants::reportDirPath, id);
76 });
Szymon Dompke1cdd7e42022-06-08 14:43:13 +020077 return *this;
78 }
79
80 const std::vector<object_path>& reports() const
81 {
82 return reportsProperty;
83 }
84
85 TriggerParams& reports(std::vector<object_path> val)
86 {
87 reportsProperty = std::move(val);
Szymon Dompkeb4ef22e2022-02-07 15:15:12 +010088 return *this;
89 }
90
Cezary Zwolak4416fce2021-03-17 03:21:06 +010091 TriggerParams& thresholdParams(LabeledTriggerThresholdParams val)
Szymon Dompkef763c9e2021-03-12 09:19:22 +010092 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010093 labeledThresholdsProperty = std::move(val);
Szymon Dompkef763c9e2021-03-12 09:19:22 +010094 return *this;
95 }
96
Cezary Zwolak4416fce2021-03-17 03:21:06 +010097 const LabeledTriggerThresholdParams& thresholdParams() const
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010098 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010099 return labeledThresholdsProperty;
Wludzik, Jozef76833cb2020-12-21 14:42:41 +0100100 }
101
102 private:
Szymon Dompkee28aa532021-10-27 12:33:12 +0200103 std::string idProperty = "Trigger1";
104 std::string nameProperty = "My Numeric Trigger";
Szymon Dompke94f71c52021-12-10 07:16:33 +0100105 std::vector<TriggerAction> triggerActionsProperty = {
106 TriggerAction::UpdateReport};
Cezary Zwolak4416fce2021-03-17 03:21:06 +0100107 std::vector<LabeledSensorInfo> labeledSensorsProperty = {
108 {"service1", "/xyz/openbmc_project/sensors/temperature/BMC_Temp",
109 "metadata1"}};
Szymon Dompke1cdd7e42022-06-08 14:43:13 +0200110 std::vector<std::string> reportIdsProperty = {"Report1",
111 "Prefixed/Report2"};
112 std::vector<object_path> reportsProperty;
Cezary Zwolak4416fce2021-03-17 03:21:06 +0100113 LabeledTriggerThresholdParams labeledThresholdsProperty =
114 std::vector<numeric::LabeledThresholdParam>{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000115 numeric::LabeledThresholdParam{numeric::Type::lowerCritical,
116 Milliseconds(10).count(),
117 numeric::Direction::decreasing, 0.5},
Cezary Zwolak4416fce2021-03-17 03:21:06 +0100118 numeric::LabeledThresholdParam{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000119 numeric::Type::upperCritical, Milliseconds(10).count(),
Cezary Zwolak4416fce2021-03-17 03:21:06 +0100120 numeric::Direction::increasing, 90.2}};
Wludzik, Jozef76833cb2020-12-21 14:42:41 +0100121};