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 | |
| 26 | Zone::Zone(sdbusplus::bus::bus& bus, |
| 27 | const ZoneDefinition& def) : |
| 28 | _bus(bus), |
| 29 | _fullSpeed(std::get<fullSpeedPos>(def)), |
| 30 | _zoneNum(std::get<zoneNumPos>(def)) |
| 31 | { |
| 32 | auto& fanDefs = std::get<fanListPos>(def); |
| 33 | |
| 34 | for (auto& def : fanDefs) |
| 35 | { |
| 36 | _fans.emplace_back(std::make_unique<Fan>(bus, def)); |
| 37 | } |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame^] | 38 | |
| 39 | // Setup signal trigger for property changes
|
| 40 | for (auto& event : std::get<setSpeedEventsPos>(def))
|
| 41 | {
|
| 42 | for (auto& prop : event)
|
| 43 | {
|
| 44 | _signalEvents.emplace_back(
|
| 45 | std::make_unique<SignalEvent>(this,
|
| 46 | std::get<handlerObjPos>(prop)
|
| 47 | ));
|
| 48 | _matches.emplace_back(bus,
|
| 49 | std::get<signaturePos>(prop).c_str(),
|
| 50 | signalHandler,
|
| 51 | _signalEvents.back().get());
|
| 52 | }
|
| 53 | } |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | void Zone::setSpeed(uint64_t speed) |
| 58 | { |
| 59 | for (auto& fan : _fans) |
| 60 | { |
| 61 | fan->setSpeed(speed); |
| 62 | } |
| 63 | } |
| 64 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame^] | 65 | int Zone::signalHandler(sd_bus_message* msg, |
| 66 | void* data, |
| 67 | sd_bus_error* err) |
| 68 | { |
| 69 | auto sdbpMsg = sdbusplus::message::message(msg); |
| 70 | auto& signalEvent = *static_cast<SignalEvent*>(data); |
| 71 | std::get<zoneObjPos>(signalEvent)->handleEvent( |
| 72 | sdbpMsg, |
| 73 | std::get<handlerObjPos>(signalEvent)); |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | void Zone::handleEvent(sdbusplus::message::message& msg, |
| 78 | const Handler& handler) |
| 79 | { |
| 80 | // Handle the callback |
| 81 | handler(_bus, msg, *this); |
| 82 | } |
| 83 | |
| 84 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | } |