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 | */ |
| 16 | #include "zone.hpp" |
| 17 | |
| 18 | namespace phosphor |
| 19 | { |
| 20 | namespace fan |
| 21 | { |
| 22 | namespace control |
| 23 | { |
| 24 | |
| 25 | |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 26 | Zone::Zone(Mode mode, |
| 27 | sdbusplus::bus::bus& bus, |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 28 | const ZoneDefinition& def) : |
| 29 | _bus(bus), |
| 30 | _fullSpeed(std::get<fullSpeedPos>(def)), |
| 31 | _zoneNum(std::get<zoneNumPos>(def)) |
| 32 | { |
| 33 | auto& fanDefs = std::get<fanListPos>(def); |
| 34 | |
| 35 | for (auto& def : fanDefs) |
| 36 | { |
| 37 | _fans.emplace_back(std::make_unique<Fan>(bus, def)); |
| 38 | } |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 39 | |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 40 | // Do not enable set speed events when in init mode |
| 41 | if (mode != Mode::init) |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 42 | { |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 43 | // Setup signal trigger for set speed events |
| 44 | for (auto& event : std::get<setSpeedEventsPos>(def)) |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 45 | { |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 46 | for (auto& prop : std::get<propChangeListPos>(event)) |
| 47 | { |
| 48 | _signalEvents.emplace_back( |
| 49 | std::make_unique<SignalEvent>( |
| 50 | this, |
| 51 | EventData |
| 52 | { |
| 53 | std::get<groupPos>(event), |
| 54 | std::get<handlerObjPos>(prop), |
| 55 | std::get<actionPos>(event) |
| 56 | })); |
| 57 | _matches.emplace_back( |
| 58 | bus, |
| 59 | std::get<signaturePos>(prop).c_str(), |
| 60 | signalHandler, |
| 61 | _signalEvents.back().get()); |
| 62 | } |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 63 | } |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 64 | } |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | |
| 68 | void Zone::setSpeed(uint64_t speed) |
| 69 | { |
| 70 | for (auto& fan : _fans) |
| 71 | { |
| 72 | fan->setSpeed(speed); |
| 73 | } |
| 74 | } |
| 75 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 76 | int Zone::signalHandler(sd_bus_message* msg, |
| 77 | void* data, |
| 78 | sd_bus_error* err) |
| 79 | { |
| 80 | auto sdbpMsg = sdbusplus::message::message(msg); |
| 81 | auto& signalEvent = *static_cast<SignalEvent*>(data); |
| 82 | std::get<zoneObjPos>(signalEvent)->handleEvent( |
| 83 | sdbpMsg, |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 84 | std::get<eventDataPos>(signalEvent)); |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | void Zone::handleEvent(sdbusplus::message::message& msg, |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 89 | const EventData& eventData) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 90 | { |
| 91 | // Handle the callback |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 92 | std::get<eventHandlerPos>(eventData)(_bus, msg, *this); |
| 93 | // Perform the action |
| 94 | std::get<eventActionPos>(eventData)(*this, |
| 95 | std::get<eventGroupPos>(eventData)); |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | } |