Add TriggerManager and Trigger objects
Implemented initial version of Trigger and TriggerManager DBus
interfaces. Now DBus user is able to add new Trigger and delete it.
There is no support for other functionality added.
Tested:
- Built using yocto dependencies with success
- Unit tests passed
- Verified manually if Trigger and TriggerManager works as
expected
Change-Id: Ie68463526ecccc3be67cc7bfaaf9a9aa7326dee6
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
diff --git a/src/trigger_manager.cpp b/src/trigger_manager.cpp
new file mode 100644
index 0000000..cc164e4
--- /dev/null
+++ b/src/trigger_manager.cpp
@@ -0,0 +1,50 @@
+#include "trigger_manager.hpp"
+
+TriggerManager::TriggerManager(
+ std::unique_ptr<interfaces::TriggerFactory> triggerFactoryIn,
+ const std::shared_ptr<sdbusplus::asio::object_server>& objServer) :
+ triggerFactory(std::move(triggerFactoryIn))
+{
+ managerIface = objServer->add_unique_interface(
+ triggerManagerPath, triggerManagerIfaceName, [this](auto& iface) {
+ iface.register_method(
+ "AddTrigger",
+ [this](
+ const std::string& name, bool isDiscrete, bool logToJournal,
+ bool logToRedfish, bool updateReport,
+ const std::vector<std::pair<sdbusplus::message::object_path,
+ std::string>>& sensors,
+ const std::vector<std::string>& reportNames,
+ const TriggerThresholdParams& thresholds) {
+ if (triggers.size() >= maxTriggers)
+ {
+ throw sdbusplus::exception::SdBusError(
+ static_cast<int>(std::errc::too_many_files_open),
+ "Reached maximal trigger count");
+ }
+
+ for (const auto& trigger : triggers)
+ {
+ if (trigger->getName() == name)
+ {
+ throw sdbusplus::exception::SdBusError(
+ static_cast<int>(std::errc::file_exists),
+ "Duplicate trigger");
+ }
+ }
+
+ triggers.emplace_back(triggerFactory->make(
+ name, isDiscrete, logToJournal, logToRedfish,
+ updateReport, sensors, reportNames, thresholds, *this));
+ return triggers.back()->getPath();
+ });
+ });
+}
+
+void TriggerManager::removeTrigger(const interfaces::Trigger* trigger)
+{
+ triggers.erase(
+ std::remove_if(triggers.begin(), triggers.end(),
+ [trigger](const auto& x) { return trigger == x.get(); }),
+ triggers.end());
+}