blob: 18fd627d9cdedd8c9b2890270e3c96e018eac3a7 [file] [log] [blame]
Matt Spinler7f88fe62017-04-10 14:39:02 -05001/**
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
18namespace phosphor
19{
20namespace fan
21{
22namespace control
23{
24
25
Matthew Barth14184132017-05-19 14:37:30 -050026Zone::Zone(Mode mode,
27 sdbusplus::bus::bus& bus,
Matt Spinler7f88fe62017-04-10 14:39:02 -050028 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 Barth38a93a82017-05-11 14:12:27 -050039
Matthew Barth14184132017-05-19 14:37:30 -050040 // Do not enable set speed events when in init mode
41 if (mode != Mode::init)
Matthew Barth17d1fe22017-05-11 15:00:36 -050042 {
Matthew Barth14184132017-05-19 14:37:30 -050043 // Setup signal trigger for set speed events
44 for (auto& event : std::get<setSpeedEventsPos>(def))
Matthew Barth17d1fe22017-05-11 15:00:36 -050045 {
Matthew Barth14184132017-05-19 14:37:30 -050046 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 Barth17d1fe22017-05-11 15:00:36 -050063 }
Matthew Barth38a93a82017-05-11 14:12:27 -050064 }
Matt Spinler7f88fe62017-04-10 14:39:02 -050065}
66
67
68void Zone::setSpeed(uint64_t speed)
69{
70 for (auto& fan : _fans)
71 {
72 fan->setSpeed(speed);
73 }
74}
75
Matthew Barth38a93a82017-05-11 14:12:27 -050076int 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 Barth17d1fe22017-05-11 15:00:36 -050084 std::get<eventDataPos>(signalEvent));
Matthew Barth38a93a82017-05-11 14:12:27 -050085 return 0;
86}
87
88void Zone::handleEvent(sdbusplus::message::message& msg,
Matthew Barth17d1fe22017-05-11 15:00:36 -050089 const EventData& eventData)
Matthew Barth38a93a82017-05-11 14:12:27 -050090{
91 // Handle the callback
Matthew Barth17d1fe22017-05-11 15:00:36 -050092 std::get<eventHandlerPos>(eventData)(_bus, msg, *this);
93 // Perform the action
94 std::get<eventActionPos>(eventData)(*this,
95 std::get<eventGroupPos>(eventData));
Matthew Barth38a93a82017-05-11 14:12:27 -050096}
97
Matt Spinler7f88fe62017-04-10 14:39:02 -050098}
99}
100}