1 #include "trigger_manager.hpp" 2 3 TriggerManager::TriggerManager( 4 std::unique_ptr<interfaces::TriggerFactory> triggerFactoryIn, 5 const std::shared_ptr<sdbusplus::asio::object_server>& objServer) : 6 triggerFactory(std::move(triggerFactoryIn)) 7 { 8 managerIface = objServer->add_unique_interface( 9 triggerManagerPath, triggerManagerIfaceName, [this](auto& iface) { 10 iface.register_method( 11 "AddTrigger", 12 [this]( 13 boost::asio::yield_context& yield, const std::string& name, 14 bool isDiscrete, bool logToJournal, bool logToRedfish, 15 bool updateReport, 16 const std::vector<std::pair<sdbusplus::message::object_path, 17 std::string>>& sensors, 18 const std::vector<std::string>& reportNames, 19 const TriggerThresholdParams& thresholds) { 20 if (isDiscrete) 21 { 22 throw sdbusplus::exception::SdBusError( 23 static_cast<int>(std::errc::not_supported), 24 "Only numeric threshold is supported"); 25 } 26 27 if (triggers.size() >= maxTriggers) 28 { 29 throw sdbusplus::exception::SdBusError( 30 static_cast<int>(std::errc::too_many_files_open), 31 "Reached maximal trigger count"); 32 } 33 34 for (const auto& trigger : triggers) 35 { 36 if (trigger->getName() == name) 37 { 38 throw sdbusplus::exception::SdBusError( 39 static_cast<int>(std::errc::file_exists), 40 "Duplicate trigger"); 41 } 42 } 43 44 triggers.emplace_back(triggerFactory->make( 45 yield, name, isDiscrete, logToJournal, logToRedfish, 46 updateReport, sensors, reportNames, thresholds, *this)); 47 return triggers.back()->getPath(); 48 }); 49 }); 50 } 51 52 void TriggerManager::removeTrigger(const interfaces::Trigger* trigger) 53 { 54 triggers.erase( 55 std::remove_if(triggers.begin(), triggers.end(), 56 [trigger](const auto& x) { return trigger == x.get(); }), 57 triggers.end()); 58 } 59