trigger_factory.cpp (9f14591205aa47cf3e99c44cc8a0469cb87ed8da) trigger_factory.cpp (f763c9e3bbe0f86a4a41e7bb0dc70bffde0af9b2)
1#include "trigger_factory.hpp"
2
1#include "trigger_factory.hpp"
2
3#include "discrete_threshold.hpp"
3#include "numeric_threshold.hpp"
4#include "numeric_threshold.hpp"
5#include "on_change_threshold.hpp"
4#include "sensor.hpp"
5#include "trigger.hpp"
6#include "trigger_actions.hpp"
7#include "utils/dbus_mapper.hpp"
8
9TriggerFactory::TriggerFactory(
10 std::shared_ptr<sdbusplus::asio::connection> bus,
11 std::shared_ptr<sdbusplus::asio::object_server> objServer,

--- 7 unchanged lines hidden (view full) ---

19 boost::asio::yield_context& yield, const std::string& name, bool isDiscrete,
20 bool logToJournal, bool logToRedfish, bool updateReport,
21 const std::vector<std::pair<sdbusplus::message::object_path, std::string>>&
22 sensorPaths,
23 const std::vector<std::string>& reportNames,
24 const TriggerThresholdParams& thresholdParams,
25 interfaces::TriggerManager& triggerManager) const
26{
6#include "sensor.hpp"
7#include "trigger.hpp"
8#include "trigger_actions.hpp"
9#include "utils/dbus_mapper.hpp"
10
11TriggerFactory::TriggerFactory(
12 std::shared_ptr<sdbusplus::asio::connection> bus,
13 std::shared_ptr<sdbusplus::asio::object_server> objServer,

--- 7 unchanged lines hidden (view full) ---

21 boost::asio::yield_context& yield, const std::string& name, bool isDiscrete,
22 bool logToJournal, bool logToRedfish, bool updateReport,
23 const std::vector<std::pair<sdbusplus::message::object_path, std::string>>&
24 sensorPaths,
25 const std::vector<std::string>& reportNames,
26 const TriggerThresholdParams& thresholdParams,
27 interfaces::TriggerManager& triggerManager) const
28{
27 if (isDiscrete)
28 {
29 throw std::runtime_error("Not implemented!");
30 }
31
32 auto [sensors, sensorNames] = getSensors(yield, sensorPaths);
33 std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
34
29 auto [sensors, sensorNames] = getSensors(yield, sensorPaths);
30 std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
31
35 const auto& params =
36 std::get<std::vector<numeric::ThresholdParam>>(thresholdParams);
37 for (const auto& [typeStr, dwellTime, directionStr, value] : params)
32 if (isDiscrete)
38 {
33 {
39 numeric::Type type = numeric::stringToType(typeStr);
40 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
41 if (logToJournal)
34 const auto& params =
35 std::get<std::vector<discrete::ThresholdParam>>(thresholdParams);
36 for (const auto& [thresholdName, severityStr, dwellTime,
37 thresholdValue] : params)
42 {
38 {
43 actions.emplace_back(
44 std::make_unique<action::LogToJournal>(type, value));
39 discrete::Severity severity =
40 discrete::stringToSeverity(severityStr);
41 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
42 if (logToJournal)
43 {
44 actions.emplace_back(
45 std::make_unique<action::discrete::LogToJournal>(severity));
46 }
47 if (logToRedfish)
48 {
49 actions.emplace_back(
50 std::make_unique<action::discrete::LogToRedfish>(severity));
51 }
52 if (updateReport)
53 {
54 actions.emplace_back(std::make_unique<action::UpdateReport>(
55 reportManager, reportNames));
56 }
57
58 thresholds.emplace_back(std::make_shared<DiscreteThreshold>(
59 bus->get_io_context(), sensors, sensorNames, std::move(actions),
60 std::chrono::milliseconds(dwellTime), thresholdValue,
61 thresholdName));
45 }
62 }
46 if (logToRedfish)
63 if (params.empty())
47 {
64 {
48 actions.emplace_back(
49 std::make_unique<action::LogToRedfish>(type, value));
65 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
66 if (logToJournal)
67 {
68 actions.emplace_back(
69 std::make_unique<
70 action::discrete::onChange::LogToJournal>());
71 }
72 if (logToRedfish)
73 {
74 actions.emplace_back(
75 std::make_unique<
76 action::discrete::onChange::LogToRedfish>());
77 }
78 if (updateReport)
79 {
80 actions.emplace_back(std::make_unique<action::UpdateReport>(
81 reportManager, reportNames));
82 }
83
84 thresholds.emplace_back(std::make_shared<OnChangeThreshold>(
85 sensors, sensorNames, std::move(actions)));
50 }
86 }
51 if (updateReport)
87 }
88 else
89 {
90 const auto& params =
91 std::get<std::vector<numeric::ThresholdParam>>(thresholdParams);
92 for (const auto& [typeStr, dwellTime, directionStr, value] : params)
52 {
93 {
53 actions.emplace_back(std::make_unique<action::UpdateReport>(
54 reportManager, reportNames));
55 }
94 numeric::Type type = numeric::stringToType(typeStr);
95 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
96 if (logToJournal)
97 {
98 actions.emplace_back(
99 std::make_unique<action::numeric::LogToJournal>(type,
100 value));
101 }
102 if (logToRedfish)
103 {
104 actions.emplace_back(
105 std::make_unique<action::numeric::LogToRedfish>(type,
106 value));
107 }
108 if (updateReport)
109 {
110 actions.emplace_back(std::make_unique<action::UpdateReport>(
111 reportManager, reportNames));
112 }
56
113
57 thresholds.emplace_back(std::make_shared<NumericThreshold>(
58 bus->get_io_context(), sensors, sensorNames, std::move(actions),
59 std::chrono::milliseconds(dwellTime),
60 numeric::stringToDirection(directionStr), value));
114 thresholds.emplace_back(std::make_shared<NumericThreshold>(
115 bus->get_io_context(), sensors, sensorNames, std::move(actions),
116 std::chrono::milliseconds(dwellTime),
117 numeric::stringToDirection(directionStr), value));
118 }
61 }
62
63 return std::make_unique<Trigger>(
64 bus->get_io_context(), objServer, name, isDiscrete, logToJournal,
65 logToRedfish, updateReport, sensorPaths, reportNames, thresholdParams,
66 std::move(thresholds), triggerManager);
67}
68

--- 36 unchanged lines hidden ---
119 }
120
121 return std::make_unique<Trigger>(
122 bus->get_io_context(), objServer, name, isDiscrete, logToJournal,
123 logToRedfish, updateReport, sensorPaths, reportNames, thresholdParams,
124 std::move(thresholds), triggerManager);
125}
126

--- 36 unchanged lines hidden ---