blob: 3a35b248a71e6e1bc5354b5e4f460c2d223c686f [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
26Zone::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 Barth38a93a82017-05-11 14:12:27 -050038
Matthew Barth17d1fe22017-05-11 15:00:36 -050039 // Setup signal trigger for set speed events
40 for (auto& event : std::get<setSpeedEventsPos>(def))
41 {
42 for (auto& prop : std::get<propChangeListPos>(event))
43 {
44 _signalEvents.emplace_back(
45 std::make_unique<SignalEvent>(this,
46 EventData
47 {
48 std::get<groupPos>(event),
49 std::get<handlerObjPos>(prop),
50 std::get<actionPos>(event)
51 }));
52 _matches.emplace_back(bus,
53 std::get<signaturePos>(prop).c_str(),
54 signalHandler,
55 _signalEvents.back().get());
56 }
Matthew Barth38a93a82017-05-11 14:12:27 -050057 }
Matt Spinler7f88fe62017-04-10 14:39:02 -050058}
59
60
61void Zone::setSpeed(uint64_t speed)
62{
63 for (auto& fan : _fans)
64 {
65 fan->setSpeed(speed);
66 }
67}
68
Matthew Barth38a93a82017-05-11 14:12:27 -050069int Zone::signalHandler(sd_bus_message* msg,
70 void* data,
71 sd_bus_error* err)
72{
73 auto sdbpMsg = sdbusplus::message::message(msg);
74 auto& signalEvent = *static_cast<SignalEvent*>(data);
75 std::get<zoneObjPos>(signalEvent)->handleEvent(
76 sdbpMsg,
Matthew Barth17d1fe22017-05-11 15:00:36 -050077 std::get<eventDataPos>(signalEvent));
Matthew Barth38a93a82017-05-11 14:12:27 -050078 return 0;
79}
80
81void Zone::handleEvent(sdbusplus::message::message& msg,
Matthew Barth17d1fe22017-05-11 15:00:36 -050082 const EventData& eventData)
Matthew Barth38a93a82017-05-11 14:12:27 -050083{
84 // Handle the callback
Matthew Barth17d1fe22017-05-11 15:00:36 -050085 std::get<eventHandlerPos>(eventData)(_bus, msg, *this);
86 // Perform the action
87 std::get<eventActionPos>(eventData)(*this,
88 std::get<eventGroupPos>(eventData));
Matthew Barth38a93a82017-05-11 14:12:27 -050089}
90
Matt Spinler7f88fe62017-04-10 14:39:02 -050091}
92}
93}