Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 3 | #include "report.hpp" |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 4 | #include "types/duration_types.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 5 | #include "types/trigger_types.hpp" |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 6 | #include "utils/dbus_path_utils.hpp" |
| 7 | #include "utils/transform.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 8 | |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 9 | #include <sdbusplus/message.hpp> |
| 10 | |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 11 | #include <chrono> |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 12 | #include <utility> |
| 13 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 14 | using sdbusplus::message::object_path; |
| 15 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 16 | class TriggerParams |
| 17 | { |
| 18 | public: |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 19 | TriggerParams() |
| 20 | { |
| 21 | reportsProperty = |
| 22 | utils::transform(reportIdsProperty, [](const auto& id) { |
| 23 | return utils::pathAppend(utils::constants::reportDirPath, id); |
| 24 | }); |
| 25 | } |
| 26 | |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 27 | TriggerParams& id(std::string val) |
| 28 | { |
| 29 | idProperty = std::move(val); |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | const std::string& id() const |
| 34 | { |
| 35 | return idProperty; |
| 36 | } |
| 37 | |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 38 | TriggerParams& name(std::string val) |
| 39 | { |
| 40 | nameProperty = std::move(val); |
| 41 | return *this; |
| 42 | } |
| 43 | |
| 44 | const std::string& name() const |
| 45 | { |
| 46 | return nameProperty; |
| 47 | } |
| 48 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 49 | TriggerParams& triggerActions(const std::vector<TriggerAction>& val) |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 50 | { |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 51 | triggerActionsProperty = val; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 52 | return *this; |
| 53 | } |
| 54 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 55 | const std::vector<TriggerAction>& triggerActions() const |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 56 | { |
Szymon Dompke | 2001301 | 2021-07-23 09:54:20 +0200 | [diff] [blame] | 57 | return triggerActionsProperty; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 60 | const std::vector<LabeledSensorInfo>& sensors() const |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 61 | { |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 62 | return labeledSensorsProperty; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 65 | const std::vector<std::string>& reportIds() const |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 66 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 67 | return reportIdsProperty; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 70 | TriggerParams& reportIds(std::vector<std::string> val) |
| 71 | { |
| 72 | reportIdsProperty = std::move(val); |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 73 | reportsProperty = utils::transform<std::vector>( |
| 74 | reportIdsProperty, [](const auto& id) { |
| 75 | return utils::pathAppend(utils::constants::reportDirPath, id); |
| 76 | }); |
| 77 | 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 Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 88 | return *this; |
| 89 | } |
| 90 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 91 | TriggerParams& thresholdParams(LabeledTriggerThresholdParams val) |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 92 | { |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 93 | labeledThresholdsProperty = std::move(val); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 94 | return *this; |
| 95 | } |
| 96 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 97 | const LabeledTriggerThresholdParams& thresholdParams() const |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 98 | { |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 99 | return labeledThresholdsProperty; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | private: |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 103 | std::string idProperty = "Trigger1"; |
| 104 | std::string nameProperty = "My Numeric Trigger"; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 105 | std::vector<TriggerAction> triggerActionsProperty = { |
| 106 | TriggerAction::UpdateReport}; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 107 | std::vector<LabeledSensorInfo> labeledSensorsProperty = { |
| 108 | {"service1", "/xyz/openbmc_project/sensors/temperature/BMC_Temp", |
| 109 | "metadata1"}}; |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame^] | 110 | std::vector<std::string> reportIdsProperty = {"Report1", |
| 111 | "Prefixed/Report2"}; |
| 112 | std::vector<object_path> reportsProperty; |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 113 | LabeledTriggerThresholdParams labeledThresholdsProperty = |
| 114 | std::vector<numeric::LabeledThresholdParam>{ |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 115 | numeric::LabeledThresholdParam{numeric::Type::lowerCritical, |
| 116 | Milliseconds(10).count(), |
| 117 | numeric::Direction::decreasing, 0.5}, |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 118 | numeric::LabeledThresholdParam{ |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 119 | numeric::Type::upperCritical, Milliseconds(10).count(), |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 120 | numeric::Direction::increasing, 90.2}}; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 121 | }; |