blob: d6e51bc998887930df2f3cae957d3fd5c9ca168f [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#include "trigger.hpp"
2
Krzysztof Grobelny753e4b32021-02-11 12:58:58 +00003#include "types/types.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01004
5Trigger::Trigger(
6 boost::asio::io_context& ioc,
7 const std::shared_ptr<sdbusplus::asio::object_server>& objServer,
8 const std::string& nameIn, const bool isDiscrete, const bool logToJournal,
9 const bool logToRedfish, const bool updateReport,
10 const std::vector<std::pair<sdbusplus::message::object_path, std::string>>&
11 sensorsIn,
12 const std::vector<std::string>& reportNamesIn,
13 const TriggerThresholdParams& thresholdParamsIn,
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010014 std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholdsIn,
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010015 interfaces::TriggerManager& triggerManager) :
16 name(nameIn),
17 path(triggerDir + name), persistent(false), sensors(sensorsIn),
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010018 reportNames(reportNamesIn), thresholdParams(thresholdParamsIn),
19 thresholds(std::move(thresholdsIn))
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010020{
21 deleteIface = objServer->add_unique_interface(
22 path, deleteIfaceName, [this, &ioc, &triggerManager](auto& dbusIface) {
23 dbusIface.register_method("Delete", [this, &ioc, &triggerManager] {
24 boost::asio::post(ioc, [this, &triggerManager] {
25 triggerManager.removeTrigger(this);
26 });
27 });
28 });
29
30 triggerIface = objServer->add_unique_interface(
31 path, triggerIfaceName,
32 [this, isDiscrete, logToJournal, logToRedfish,
33 updateReport](auto& dbusIface) {
34 dbusIface.register_property_r(
35 "Persistent", persistent,
36 sdbusplus::vtable::property_::emits_change,
37 [](const auto& x) { return x; });
38 dbusIface.register_property_r(
39 "Thresholds", thresholdParams,
40 sdbusplus::vtable::property_::emits_change,
41 [](const auto& x) { return x; });
42 dbusIface.register_property_r(
43 "Sensors", sensors, sdbusplus::vtable::property_::emits_change,
44 [](const auto& x) { return x; });
45 dbusIface.register_property_r(
46 "ReportNames", reportNames,
47 sdbusplus::vtable::property_::emits_change,
48 [](const auto& x) { return x; });
49 dbusIface.register_property_r("Discrete", isDiscrete,
50 sdbusplus::vtable::property_::const_,
51 [](const auto& x) { return x; });
52 dbusIface.register_property_r("LogToJournal", logToJournal,
53 sdbusplus::vtable::property_::const_,
54 [](const auto& x) { return x; });
55 dbusIface.register_property_r("LogToRedfish", logToRedfish,
56 sdbusplus::vtable::property_::const_,
57 [](const auto& x) { return x; });
58 dbusIface.register_property_r("UpdateReport", updateReport,
59 sdbusplus::vtable::property_::const_,
60 [](const auto& x) { return x; });
61 });
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010062
63 for (const auto& threshold : thresholds)
64 {
65 threshold->initialize();
66 }
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010067}