#include "preconditions.hpp" #include "zone.hpp" #include #include namespace phosphor { namespace fan { namespace control { namespace precondition { using namespace phosphor::fan; using namespace phosphor::logging; Action property_states_match(std::vector&& pg, std::vector&& sse) { return [pg = std::move(pg), sse = std::move(sse)](auto& zone, auto& group) { // Compare given precondition entries auto precondState = std::all_of(pg.begin(), pg.end(), [&zone](const auto& entry) { try { return zone.getPropValueVariant( std::get(entry), std::get(entry), std::get(entry)) == std::get(entry); } catch (const std::out_of_range& oore) { // Default to property variants not equal when not found return false; } }); if (precondState) { log( "Preconditions passed, init the associated events", entry("EVENT_COUNT=%u", sse.size())); // Init the events when all the precondition(s) are true std::for_each(sse.begin(), sse.end(), [&zone](const auto& entry) { zone.initEvent(entry); }); } else { log( "Preconditions not met for events, events removed if present", entry("EVENT_COUNT=%u", sse.size())); // Unsubscribe the events' signals when any precondition is false std::for_each(sse.begin(), sse.end(), [&zone](const auto& entry) { zone.removeEvent(entry); }); zone.setFullSpeed(); } // Update group's fan control active allowed zone.setActiveAllow(&group, precondState); }; } Action services_missing_owner(std::vector&& sse) { return [sse = std::move(sse)](auto& zone, auto& group) { // Set/update the services of the group zone.setServices(&group); const auto& services = zone.getGroupServices(&group); auto precondState = std::any_of(services.begin(), services.end(), [](const auto& s) { return !std::get(s); }); if (precondState) { // Init the events when all the precondition(s) are true std::for_each(sse.begin(), sse.end(), [&zone](const auto& entry) { zone.initEvent(entry); }); } else { // Unsubscribe the events' signals when any precondition is false std::for_each(sse.begin(), sse.end(), [&zone](const auto& entry) { zone.removeEvent(entry); }); } }; } } // namespace precondition } // namespace control } // namespace fan } // namespace phosphor