Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #include "trigger.hpp" |
| 2 | |
Krzysztof Grobelny | 753e4b3 | 2021-02-11 12:58:58 +0000 | [diff] [blame] | 3 | #include "types/types.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 4 | |
| 5 | Trigger::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, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 14 | std::vector<std::shared_ptr<interfaces::Threshold>>&& thresholdsIn, |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 15 | interfaces::TriggerManager& triggerManager) : |
| 16 | name(nameIn), |
| 17 | path(triggerDir + name), persistent(false), sensors(sensorsIn), |
Wludzik, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 18 | reportNames(reportNamesIn), thresholdParams(thresholdParamsIn), |
| 19 | thresholds(std::move(thresholdsIn)) |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 20 | { |
| 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, Jozef | 1477fe6 | 2021-01-02 11:56:10 +0100 | [diff] [blame] | 62 | |
| 63 | for (const auto& threshold : thresholds) |
| 64 | { |
| 65 | threshold->initialize(); |
| 66 | } |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 67 | } |