1 #include "actions.hpp" 2 3 namespace phosphor 4 { 5 namespace fan 6 { 7 namespace control 8 { 9 namespace action 10 { 11 12 using namespace phosphor::fan; 13 14 Action call_actions_based_on_timer(TimerConf&& tConf, 15 std::vector<Action>&& actions) 16 { 17 return [tConf = std::move(tConf), 18 actions = std::move(actions)](control::Zone& zone, 19 const Group& group) 20 { 21 try 22 { 23 auto it = zone.getTimerEvents().find(__func__); 24 if (it != zone.getTimerEvents().end()) 25 { 26 auto& timers = it->second; 27 auto timerIter = zone.findTimer(group, actions, timers); 28 if (timerIter == timers.end()) 29 { 30 // No timer exists yet for action, add timer 31 zone.addTimer(__func__, group, actions, tConf); 32 } 33 else if (timerIter != timers.end()) 34 { 35 // Remove any timer for this group 36 timers.erase(timerIter); 37 if (timers.empty()) 38 { 39 zone.getTimerEvents().erase(it); 40 } 41 } 42 } 43 else 44 { 45 // No timer exists yet for event, add timer 46 zone.addTimer(__func__, group, actions, tConf); 47 } 48 } 49 catch (const std::out_of_range& oore) 50 { 51 // Group not found, no timers set 52 } 53 }; 54 } 55 56 void default_floor_on_missing_owner(Zone& zone, const Group& group) 57 { 58 // Set/update the services of the group 59 zone.setServices(&group); 60 auto services = zone.getGroupServices(&group); 61 auto defFloor = std::any_of( 62 services.begin(), 63 services.end(), 64 [](const auto& s) 65 { 66 return !std::get<hasOwnerPos>(s); 67 }); 68 if (defFloor) 69 { 70 zone.setFloor(zone.getDefFloor()); 71 } 72 // Update fan control floor change allowed 73 zone.setFloorChangeAllow(&group, !defFloor); 74 } 75 76 Action set_speed_on_missing_owner(uint64_t speed) 77 { 78 return [speed](control::Zone& zone, const Group& group) 79 { 80 // Set/update the services of the group 81 zone.setServices(&group); 82 auto services = zone.getGroupServices(&group); 83 auto missingOwner = std::any_of( 84 services.begin(), 85 services.end(), 86 [](const auto& s) 87 { 88 return !std::get<hasOwnerPos>(s); 89 }); 90 if (missingOwner) 91 { 92 zone.setSpeed(speed); 93 } 94 // Update group's fan control active allowed based on action results 95 zone.setActiveAllow(&group, !missingOwner); 96 }; 97 } 98 99 void set_request_speed_base_with_max(control::Zone& zone, 100 const Group& group) 101 { 102 int64_t base = 0; 103 std::for_each( 104 group.begin(), 105 group.end(), 106 [&zone, &base](auto const& entry) 107 { 108 try 109 { 110 auto value = zone.template getPropertyValue<int64_t>( 111 std::get<pathPos>(entry), 112 std::get<intfPos>(entry), 113 std::get<propPos>(entry)); 114 base = std::max(base, value); 115 } 116 catch (const std::out_of_range& oore) 117 { 118 // Property value not found, base request speed unchanged 119 } 120 }); 121 // A request speed base of 0 defaults to the current target speed 122 zone.setRequestSpeedBase(base); 123 } 124 125 } // namespace action 126 } // namespace control 127 } // namespace fan 128 } // namespace phosphor 129