17f88fe61SMatt Spinler /** 27f88fe61SMatt Spinler * Copyright © 2017 IBM Corporation 37f88fe61SMatt Spinler * 47f88fe61SMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License"); 57f88fe61SMatt Spinler * you may not use this file except in compliance with the License. 67f88fe61SMatt Spinler * You may obtain a copy of the License at 77f88fe61SMatt Spinler * 87f88fe61SMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0 97f88fe61SMatt Spinler * 107f88fe61SMatt Spinler * Unless required by applicable law or agreed to in writing, software 117f88fe61SMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS, 127f88fe61SMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137f88fe61SMatt Spinler * See the License for the specific language governing permissions and 147f88fe61SMatt Spinler * limitations under the License. 157f88fe61SMatt Spinler */ 167f88fe61SMatt Spinler #include "zone.hpp" 177f88fe61SMatt Spinler 187f88fe61SMatt Spinler namespace phosphor 197f88fe61SMatt Spinler { 207f88fe61SMatt Spinler namespace fan 217f88fe61SMatt Spinler { 227f88fe61SMatt Spinler namespace control 237f88fe61SMatt Spinler { 247f88fe61SMatt Spinler 257f88fe61SMatt Spinler 267f88fe61SMatt Spinler Zone::Zone(sdbusplus::bus::bus& bus, 277f88fe61SMatt Spinler const ZoneDefinition& def) : 287f88fe61SMatt Spinler _bus(bus), 297f88fe61SMatt Spinler _fullSpeed(std::get<fullSpeedPos>(def)), 307f88fe61SMatt Spinler _zoneNum(std::get<zoneNumPos>(def)) 317f88fe61SMatt Spinler { 327f88fe61SMatt Spinler auto& fanDefs = std::get<fanListPos>(def); 337f88fe61SMatt Spinler 347f88fe61SMatt Spinler for (auto& def : fanDefs) 357f88fe61SMatt Spinler { 367f88fe61SMatt Spinler _fans.emplace_back(std::make_unique<Fan>(bus, def)); 377f88fe61SMatt Spinler } 3838a93a8aSMatthew Barth 39*17d1fe23SMatthew Barth // Setup signal trigger for set speed events 4038a93a8aSMatthew Barth for (auto& event : std::get<setSpeedEventsPos>(def)) 4138a93a8aSMatthew Barth { 42*17d1fe23SMatthew Barth for (auto& prop : std::get<propChangeListPos>(event)) 4338a93a8aSMatthew Barth { 4438a93a8aSMatthew Barth _signalEvents.emplace_back( 4538a93a8aSMatthew Barth std::make_unique<SignalEvent>(this, 46*17d1fe23SMatthew Barth EventData 47*17d1fe23SMatthew Barth { 48*17d1fe23SMatthew Barth std::get<groupPos>(event), 49*17d1fe23SMatthew Barth std::get<handlerObjPos>(prop), 50*17d1fe23SMatthew Barth std::get<actionPos>(event) 51*17d1fe23SMatthew Barth })); 5238a93a8aSMatthew Barth _matches.emplace_back(bus, 5338a93a8aSMatthew Barth std::get<signaturePos>(prop).c_str(), 5438a93a8aSMatthew Barth signalHandler, 5538a93a8aSMatthew Barth _signalEvents.back().get()); 5638a93a8aSMatthew Barth } 5738a93a8aSMatthew Barth } 587f88fe61SMatt Spinler } 597f88fe61SMatt Spinler 607f88fe61SMatt Spinler 617f88fe61SMatt Spinler void Zone::setSpeed(uint64_t speed) 627f88fe61SMatt Spinler { 637f88fe61SMatt Spinler for (auto& fan : _fans) 647f88fe61SMatt Spinler { 657f88fe61SMatt Spinler fan->setSpeed(speed); 667f88fe61SMatt Spinler } 677f88fe61SMatt Spinler } 687f88fe61SMatt Spinler 6938a93a8aSMatthew Barth int Zone::signalHandler(sd_bus_message* msg, 7038a93a8aSMatthew Barth void* data, 7138a93a8aSMatthew Barth sd_bus_error* err) 7238a93a8aSMatthew Barth { 7338a93a8aSMatthew Barth auto sdbpMsg = sdbusplus::message::message(msg); 7438a93a8aSMatthew Barth auto& signalEvent = *static_cast<SignalEvent*>(data); 7538a93a8aSMatthew Barth std::get<zoneObjPos>(signalEvent)->handleEvent( 7638a93a8aSMatthew Barth sdbpMsg, 77*17d1fe23SMatthew Barth std::get<eventDataPos>(signalEvent)); 7838a93a8aSMatthew Barth return 0; 7938a93a8aSMatthew Barth } 8038a93a8aSMatthew Barth 8138a93a8aSMatthew Barth void Zone::handleEvent(sdbusplus::message::message& msg, 82*17d1fe23SMatthew Barth const EventData& eventData) 8338a93a8aSMatthew Barth { 8438a93a8aSMatthew Barth // Handle the callback 85*17d1fe23SMatthew Barth std::get<eventHandlerPos>(eventData)(_bus, msg, *this); 86*17d1fe23SMatthew Barth // Perform the action 87*17d1fe23SMatthew Barth std::get<eventActionPos>(eventData)(*this, 88*17d1fe23SMatthew Barth std::get<eventGroupPos>(eventData)); 8938a93a8aSMatthew Barth } 9038a93a8aSMatthew Barth 917f88fe61SMatt Spinler } 927f88fe61SMatt Spinler } 937f88fe61SMatt Spinler } 94