Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 16 | #include <chrono> |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame] | 17 | #include <phosphor-logging/log.hpp> |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/elog.hpp> |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame] | 19 | #include <phosphor-logging/elog-errors.hpp> |
| 20 | #include <xyz/openbmc_project/Common/error.hpp> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 21 | #include "zone.hpp" |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 22 | #include "utility.hpp" |
Matthew Barth | d953bb2 | 2017-08-22 10:45:28 -0500 | [diff] [blame] | 23 | #include "sdbusplus.hpp" |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 24 | |
| 25 | namespace phosphor |
| 26 | { |
| 27 | namespace fan |
| 28 | { |
| 29 | namespace control |
| 30 | { |
| 31 | |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 32 | using namespace std::chrono; |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 33 | using namespace phosphor::fan; |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 34 | using namespace phosphor::logging; |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame] | 35 | using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: |
| 36 | Error::InternalFailure; |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 37 | |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 38 | Zone::Zone(Mode mode, |
| 39 | sdbusplus::bus::bus& bus, |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 40 | phosphor::fan::event::EventPtr& events, |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 41 | const ZoneDefinition& def) : |
| 42 | _bus(bus), |
| 43 | _fullSpeed(std::get<fullSpeedPos>(def)), |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 44 | _zoneNum(std::get<zoneNumPos>(def)), |
Matthew Barth | e0ca13e | 2017-06-13 16:29:09 -0500 | [diff] [blame] | 45 | _defFloorSpeed(std::get<floorSpeedPos>(def)), |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 46 | _defCeilingSpeed(std::get<fullSpeedPos>(def)), |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 47 | _incDelay(std::get<incDelayPos>(def)), |
| 48 | _decInterval(std::get<decIntervalPos>(def)), |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 49 | _incTimer(events, [this](){ this->incTimerExpired(); }), |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 50 | _decTimer(events, [this](){ this->decTimerExpired(); }), |
| 51 | _sdEvents(events) |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 52 | { |
| 53 | auto& fanDefs = std::get<fanListPos>(def); |
| 54 | |
| 55 | for (auto& def : fanDefs) |
| 56 | { |
| 57 | _fans.emplace_back(std::make_unique<Fan>(bus, def)); |
| 58 | } |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 59 | |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 60 | // Do not enable set speed events when in init mode |
| 61 | if (mode != Mode::init) |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 62 | { |
Matthew Barth | ccc7770 | 2017-07-28 13:43:04 -0500 | [diff] [blame] | 63 | // Setup signal trigger for set speed events |
| 64 | for (auto& event : std::get<setSpeedEventsPos>(def)) |
| 65 | { |
| 66 | initEvent(event); |
| 67 | } |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 68 | // Start timer for fan speed decreases |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 69 | if (!_decTimer.running() && _decInterval != seconds::zero()) |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 70 | { |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 71 | _decTimer.start(_decInterval, |
Matthew Barth | d953bb2 | 2017-08-22 10:45:28 -0500 | [diff] [blame] | 72 | util::Timer::TimerType::repeating); |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 73 | } |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 74 | } |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 77 | void Zone::setSpeed(uint64_t speed) |
| 78 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 79 | if (_isActive) |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 80 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 81 | _targetSpeed = speed; |
| 82 | for (auto& fan : _fans) |
| 83 | { |
| 84 | fan->setSpeed(_targetSpeed); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void Zone::setFullSpeed() |
| 90 | { |
| 91 | if (_fullSpeed != 0) |
| 92 | { |
| 93 | _targetSpeed = _fullSpeed; |
| 94 | for (auto& fan : _fans) |
| 95 | { |
| 96 | fan->setSpeed(_targetSpeed); |
| 97 | } |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 101 | void Zone::setActiveAllow(const Group* group, bool isActiveAllow) |
| 102 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 103 | _active[*(group)] = isActiveAllow; |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 104 | if (!isActiveAllow) |
| 105 | { |
| 106 | _isActive = false; |
| 107 | } |
| 108 | else |
| 109 | { |
| 110 | // Check all entries are set to allow control active |
| 111 | auto actPred = [](auto const& entry) {return entry.second;}; |
| 112 | _isActive = std::all_of(_active.begin(), |
| 113 | _active.end(), |
| 114 | actPred); |
| 115 | } |
| 116 | } |
| 117 | |
Matthew Barth | e59fdf7 | 2017-09-27 09:33:42 -0500 | [diff] [blame] | 118 | void Zone::setServiceOwner(const Group* group, |
| 119 | const std::string& name, |
| 120 | const bool hasOwner) |
| 121 | { |
| 122 | try |
| 123 | { |
| 124 | auto& sNames = _services.at(*group); |
| 125 | auto it = std::find_if( |
| 126 | sNames.begin(), |
| 127 | sNames.end(), |
| 128 | [&name](auto const& entry) |
| 129 | { |
| 130 | return name == std::get<namePos>(entry); |
| 131 | } |
| 132 | ); |
| 133 | if (it != std::end(sNames)) |
| 134 | { |
| 135 | std::get<hasOwnerPos>(*it) = hasOwner; |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | _services[*group].emplace_back(name, hasOwner); |
| 140 | } |
| 141 | } |
| 142 | catch (const std::out_of_range& oore) |
| 143 | { |
| 144 | _services[*group].emplace_back(name, hasOwner); |
| 145 | } |
| 146 | } |
| 147 | |
Matthew Barth | b4a7cb9 | 2017-06-28 15:29:50 -0500 | [diff] [blame] | 148 | void Zone::setFloor(uint64_t speed) |
| 149 | { |
| 150 | _floorSpeed = speed; |
| 151 | // Floor speed above target, update target to floor speed |
| 152 | if (_targetSpeed < _floorSpeed) |
| 153 | { |
| 154 | requestSpeedIncrease(_floorSpeed - _targetSpeed); |
| 155 | } |
| 156 | } |
| 157 | |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 158 | void Zone::requestSpeedIncrease(uint64_t targetDelta) |
| 159 | { |
| 160 | // Only increase speed when delta is higher than |
| 161 | // the current increase delta for the zone and currently under ceiling |
| 162 | if (targetDelta > _incSpeedDelta && |
| 163 | _targetSpeed < _ceilingSpeed) |
| 164 | { |
Matthew Barth | 4e72854 | 2017-09-14 16:47:55 -0500 | [diff] [blame] | 165 | auto requestTarget = getRequestSpeedBase(); |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 166 | requestTarget = (targetDelta - _incSpeedDelta) + requestTarget; |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 167 | _incSpeedDelta = targetDelta; |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 168 | // Target speed can not go above a defined ceiling speed |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 169 | if (requestTarget > _ceilingSpeed) |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 170 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 171 | requestTarget = _ceilingSpeed; |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 172 | } |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 173 | // Cancel current timer countdown |
| 174 | if (_incTimer.running()) |
| 175 | { |
| 176 | _incTimer.stop(); |
| 177 | } |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 178 | setSpeed(requestTarget); |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 179 | // Start timer countdown for fan speed increase |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 180 | _incTimer.start(_incDelay, |
Matthew Barth | d953bb2 | 2017-08-22 10:45:28 -0500 | [diff] [blame] | 181 | util::Timer::TimerType::oneshot); |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 182 | } |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void Zone::incTimerExpired() |
| 186 | { |
| 187 | // Clear increase delta when timer expires allowing additional speed |
| 188 | // increase requests or speed decreases to occur |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 189 | _incSpeedDelta = 0; |
| 190 | } |
| 191 | |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 192 | void Zone::requestSpeedDecrease(uint64_t targetDelta) |
| 193 | { |
| 194 | // Only decrease the lowest target delta requested |
| 195 | if (_decSpeedDelta == 0 || targetDelta < _decSpeedDelta) |
| 196 | { |
| 197 | _decSpeedDelta = targetDelta; |
| 198 | } |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 199 | } |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 200 | |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 201 | void Zone::decTimerExpired() |
| 202 | { |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 203 | // Only decrease speeds when no requested increases exist and |
| 204 | // the increase timer is not running (i.e. not in the middle of increasing) |
| 205 | if (_incSpeedDelta == 0 && !_incTimer.running()) |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 206 | { |
Matthew Barth | 4e72854 | 2017-09-14 16:47:55 -0500 | [diff] [blame] | 207 | auto requestTarget = getRequestSpeedBase(); |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 208 | // Target speed can not go below the defined floor speed |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 209 | if ((requestTarget < _decSpeedDelta) || |
| 210 | (requestTarget - _decSpeedDelta < _floorSpeed)) |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 211 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 212 | requestTarget = _floorSpeed; |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 213 | } |
| 214 | else |
| 215 | { |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 216 | requestTarget = requestTarget - _decSpeedDelta; |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 217 | } |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 218 | setSpeed(requestTarget); |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 219 | } |
| 220 | // Clear decrease delta when timer expires |
| 221 | _decSpeedDelta = 0; |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 222 | // Decrease timer is restarted since its repeating |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Matthew Barth | ccc7770 | 2017-07-28 13:43:04 -0500 | [diff] [blame] | 225 | void Zone::initEvent(const SetSpeedEvent& event) |
Matthew Barth | 1bf0ce4 | 2017-06-23 16:16:30 -0500 | [diff] [blame] | 226 | { |
Matthew Barth | 336f18a | 2017-09-26 09:15:56 -0500 | [diff] [blame] | 227 | sdbusplus::message::message nullMsg{nullptr}; |
| 228 | |
Matthew Barth | 67967f9 | 2017-09-22 12:43:57 -0500 | [diff] [blame] | 229 | for (auto& sig : std::get<signalsPos>(event)) |
Matthew Barth | ccc7770 | 2017-07-28 13:43:04 -0500 | [diff] [blame] | 230 | { |
Matthew Barth | 336f18a | 2017-09-26 09:15:56 -0500 | [diff] [blame] | 231 | // Initialize the event signal using handler |
| 232 | std::get<sigHandlerPos>(sig)(_bus, nullMsg, *this); |
| 233 | // Setup signal matches of the property for event |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 234 | std::unique_ptr<EventData> eventData = |
| 235 | std::make_unique<EventData>( |
| 236 | EventData |
| 237 | { |
| 238 | std::get<groupPos>(event), |
Matthew Barth | 336f18a | 2017-09-26 09:15:56 -0500 | [diff] [blame] | 239 | std::get<sigMatchPos>(sig), |
| 240 | std::get<sigHandlerPos>(sig), |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 241 | std::get<actionsPos>(event) |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 242 | } |
| 243 | ); |
Matthew Barth | 336f18a | 2017-09-26 09:15:56 -0500 | [diff] [blame] | 244 | std::unique_ptr<sdbusplus::server::match::match> match = nullptr; |
| 245 | if (!std::get<sigMatchPos>(sig).empty()) |
| 246 | { |
| 247 | match = std::make_unique<sdbusplus::server::match::match>( |
| 248 | _bus, |
| 249 | std::get<sigMatchPos>(sig).c_str(), |
| 250 | std::bind(std::mem_fn(&Zone::handleEvent), |
| 251 | this, |
| 252 | std::placeholders::_1, |
| 253 | eventData.get()) |
| 254 | ); |
| 255 | } |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 256 | _signalEvents.emplace_back(std::move(eventData), std::move(match)); |
Matthew Barth | ccc7770 | 2017-07-28 13:43:04 -0500 | [diff] [blame] | 257 | } |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 258 | // Attach a timer to run the action of an event |
| 259 | auto eventTimer = std::get<timerPos>(event); |
| 260 | if (std::get<intervalPos>(eventTimer) != seconds(0)) |
| 261 | { |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 262 | // Associate event data with timer |
| 263 | std::unique_ptr<EventData> eventData = |
| 264 | std::make_unique<EventData>( |
| 265 | EventData |
| 266 | { |
| 267 | std::get<groupPos>(event), |
| 268 | "", |
| 269 | nullptr, |
| 270 | std::get<actionsPos>(event) |
| 271 | } |
| 272 | ); |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 273 | std::unique_ptr<util::Timer> timer = |
| 274 | std::make_unique<util::Timer>( |
| 275 | _sdEvents, |
| 276 | [this, |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 277 | action = &(std::get<actionsPos>(event)), |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 278 | group = &(std::get<groupPos>(event))]() |
| 279 | { |
| 280 | this->timerExpired(*group, *action); |
| 281 | }); |
| 282 | if (!timer->running()) |
| 283 | { |
| 284 | timer->start(std::get<intervalPos>(eventTimer), |
Matthew Barth | 7b7ceb8 | 2017-10-04 12:59:50 -0500 | [diff] [blame] | 285 | std::get<typePos>(eventTimer)); |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 286 | } |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 287 | addTimer(std::move(eventData), std::move(timer)); |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 288 | } |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 289 | // Run action functions for initial event state |
| 290 | std::for_each( |
| 291 | std::get<actionsPos>(event).begin(), |
| 292 | std::get<actionsPos>(event).end(), |
| 293 | [this, &event](auto const& action) |
| 294 | { |
| 295 | action(*this, |
| 296 | std::get<groupPos>(event)); |
| 297 | }); |
Matthew Barth | 1bf0ce4 | 2017-06-23 16:16:30 -0500 | [diff] [blame] | 298 | } |
| 299 | |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 300 | void Zone::removeEvent(const SetSpeedEvent& event) |
| 301 | { |
| 302 | // Find the signal event to be removed |
| 303 | auto it = std::find_if( |
| 304 | _signalEvents.begin(), |
| 305 | _signalEvents.end(), |
| 306 | [&event](auto const& se) |
| 307 | { |
| 308 | auto seEventData = *std::get<signalEventDataPos>(se); |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 309 | if (std::get<eventActionsPos>(seEventData).size() != |
| 310 | std::get<actionsPos>(event).size()) |
| 311 | { |
| 312 | return false; |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | // TODO openbmc/openbmc#2328 - Use the action function target |
| 317 | // for comparison |
| 318 | auto actsEqual = [](auto const& a1, |
| 319 | auto const& a2) |
| 320 | { |
| 321 | return a1.target_type().name() == |
| 322 | a2.target_type().name(); |
| 323 | }; |
| 324 | return |
| 325 | ( |
| 326 | std::get<eventGroupPos>(seEventData) == |
| 327 | std::get<groupPos>(event) && |
| 328 | std::equal(std::get<actionsPos>(event).begin(), |
| 329 | std::get<actionsPos>(event).end(), |
| 330 | std::get<eventActionsPos>(seEventData).begin(), |
| 331 | actsEqual) |
| 332 | ); |
| 333 | } |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 334 | }); |
| 335 | if (it != std::end(_signalEvents)) |
| 336 | { |
| 337 | std::get<signalEventDataPos>(*it).reset(); |
Matthew Barth | 336f18a | 2017-09-26 09:15:56 -0500 | [diff] [blame] | 338 | if (std::get<signalMatchPos>(*it) != nullptr) |
| 339 | { |
| 340 | std::get<signalMatchPos>(*it).reset(); |
| 341 | } |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 342 | _signalEvents.erase(it); |
| 343 | } |
| 344 | } |
| 345 | |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 346 | std::vector<TimerEvent>::iterator Zone::findTimer( |
| 347 | const Group& eventGroup, |
| 348 | const std::vector<Action>& eventActions) |
| 349 | { |
| 350 | for (auto it = _timerEvents.begin(); it != _timerEvents.end(); ++it) |
| 351 | { |
| 352 | auto teEventData = *std::get<timerEventDataPos>(*it); |
| 353 | if (std::get<eventActionsPos>(teEventData).size() == |
| 354 | eventActions.size()) |
| 355 | { |
| 356 | // TODO openbmc/openbmc#2328 - Use the action function target |
| 357 | // for comparison |
| 358 | auto actsEqual = [](auto const& a1, |
| 359 | auto const& a2) |
| 360 | { |
| 361 | return a1.target_type().name() == |
| 362 | a2.target_type().name(); |
| 363 | }; |
| 364 | if (std::get<eventGroupPos>(teEventData) == eventGroup && |
| 365 | std::equal(eventActions.begin(), |
| 366 | eventActions.end(), |
| 367 | std::get<eventActionsPos>(teEventData).begin(), |
| 368 | actsEqual)) |
| 369 | { |
| 370 | return it; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | return _timerEvents.end(); |
| 376 | } |
| 377 | |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 378 | void Zone::timerExpired(Group eventGroup, std::vector<Action> eventActions) |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 379 | { |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 380 | // Perform the actions |
| 381 | std::for_each(eventActions.begin(), |
| 382 | eventActions.end(), |
| 383 | [this, &eventGroup](auto const& action) |
| 384 | { |
| 385 | action(*this, eventGroup); |
| 386 | }); |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 387 | } |
| 388 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 389 | void Zone::handleEvent(sdbusplus::message::message& msg, |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 390 | const EventData* eventData) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 391 | { |
| 392 | // Handle the callback |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 393 | std::get<eventHandlerPos>(*eventData)(_bus, msg, *this); |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 394 | // Perform the actions |
| 395 | std::for_each( |
| 396 | std::get<eventActionsPos>(*eventData).begin(), |
| 397 | std::get<eventActionsPos>(*eventData).end(), |
| 398 | [this, &eventData](auto const& action) |
| 399 | { |
| 400 | action(*this, |
| 401 | std::get<eventGroupPos>(*eventData)); |
| 402 | }); |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | } |