1 #pragma once
2 
3 #include "report.hpp"
4 #include "types/duration_types.hpp"
5 #include "types/trigger_types.hpp"
6 #include "utils/dbus_path_utils.hpp"
7 #include "utils/transform.hpp"
8 
9 #include <sdbusplus/message.hpp>
10 
11 #include <chrono>
12 #include <utility>
13 
14 using sdbusplus::message::object_path;
15 
16 class TriggerParams
17 {
18   public:
TriggerParams()19     TriggerParams()
20     {
21         reportsProperty = utils::transform(reportIdsProperty,
22                                            [](const auto& id) {
23             return utils::pathAppend(utils::constants::reportDirPath, id);
24         });
25     }
26 
id(std::string_view val)27     TriggerParams& id(std::string_view val)
28     {
29         idProperty = val;
30         return *this;
31     }
32 
id() const33     const std::string& id() const
34     {
35         return idProperty;
36     }
37 
name(std::string_view val)38     TriggerParams& name(std::string_view val)
39     {
40         nameProperty = val;
41         return *this;
42     }
43 
name() const44     const std::string& name() const
45     {
46         return nameProperty;
47     }
48 
triggerActions(const std::vector<TriggerAction> & val)49     TriggerParams& triggerActions(const std::vector<TriggerAction>& val)
50     {
51         triggerActionsProperty = val;
52         return *this;
53     }
54 
triggerActions() const55     const std::vector<TriggerAction>& triggerActions() const
56     {
57         return triggerActionsProperty;
58     }
59 
sensors() const60     const std::vector<LabeledSensorInfo>& sensors() const
61     {
62         return labeledSensorsProperty;
63     }
64 
reportIds() const65     const std::vector<std::string>& reportIds() const
66     {
67         return reportIdsProperty;
68     }
69 
reportIds(std::vector<std::string> val)70     TriggerParams& reportIds(std::vector<std::string> val)
71     {
72         reportIdsProperty = std::move(val);
73         reportsProperty = utils::transform<std::vector>(reportIdsProperty,
74                                                         [](const auto& id) {
75             return utils::pathAppend(utils::constants::reportDirPath, id);
76         });
77         return *this;
78     }
79 
reports() const80     const std::vector<object_path>& reports() const
81     {
82         return reportsProperty;
83     }
84 
reports(std::vector<object_path> val)85     TriggerParams& reports(std::vector<object_path> val)
86     {
87         reportsProperty = std::move(val);
88         return *this;
89     }
90 
thresholdParams(LabeledTriggerThresholdParams val)91     TriggerParams& thresholdParams(LabeledTriggerThresholdParams val)
92     {
93         labeledThresholdsProperty = std::move(val);
94         return *this;
95     }
96 
thresholdParams() const97     const LabeledTriggerThresholdParams& thresholdParams() const
98     {
99         return labeledThresholdsProperty;
100     }
101 
102   private:
103     std::string idProperty = "Trigger1";
104     std::string nameProperty = "My Numeric Trigger";
105     std::vector<TriggerAction> triggerActionsProperty = {
106         TriggerAction::UpdateReport};
107     std::vector<LabeledSensorInfo> labeledSensorsProperty = {
108         {"service1", "/xyz/openbmc_project/sensors/temperature/BMC_Temp",
109          "metadata1"}};
110     std::vector<std::string> reportIdsProperty = {"Report1",
111                                                   "Prefixed/Report2"};
112     std::vector<object_path> reportsProperty;
113     LabeledTriggerThresholdParams labeledThresholdsProperty =
114         std::vector<numeric::LabeledThresholdParam>{
115             numeric::LabeledThresholdParam{numeric::Type::lowerCritical,
116                                            Milliseconds(10).count(),
117                                            numeric::Direction::decreasing, 0.5},
118             numeric::LabeledThresholdParam{
119                 numeric::Type::upperCritical, Milliseconds(10).count(),
120                 numeric::Direction::increasing, 90.2}};
121 };
122