blob: c21478b5cc20b96a911d027683898fd1393fc15b [file] [log] [blame]
Matthew Barth5c15b792017-03-01 11:17:00 -06001/**
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 */
Matthew Barthcd4f4d12017-02-17 17:48:56 -060016#include <sdbusplus/exception.hpp>
Matthew Barth293477d2017-02-17 15:39:36 -060017#include "tach_sensor.hpp"
Matthew Barthcd4f4d12017-02-17 17:48:56 -060018#include "fan_enclosure.hpp"
Matthew Barth293477d2017-02-17 15:39:36 -060019
20
21namespace phosphor
22{
23namespace fan
24{
25namespace presence
26{
27
28bool TachSensor::isPresent()
29{
Matthew Barthd6403822017-02-17 17:10:19 -060030 return (tach != 0);
Matthew Barth293477d2017-02-17 15:39:36 -060031}
32
Matthew Barthcd4f4d12017-02-17 17:48:56 -060033// Tach signal callback handler
34int TachSensor::handleTachChangeSignal(sd_bus_message* msg,
35 void* usrData,
36 sd_bus_error* err)
37{
38 auto sdbpMsg = sdbusplus::message::message(msg);
39 static_cast<TachSensor*>(usrData)->handleTachChange(sdbpMsg, err);
40 return 0;
41}
42
43void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg,
44 sd_bus_error* err)
45{
46 std::string msgSensor;
47 std::map<std::string, sdbusplus::message::variant<int64_t>> msgData;
48 sdbpMsg.read(msgSensor, msgData);
49
50 // TODO openbmc/phosphor-fan-presence#5
51 // Update to use 'arg0namespace' match option to reduce dbus traffic
52 // Find interface with value property
53 if (msgSensor.compare("xyz.openbmc_project.Sensor.Value") == 0)
54 {
55 // Find the 'Value' property containing tach
56 auto valPropMap = msgData.find("Value");
57 if (valPropMap != msgData.end())
58 {
59 tach = sdbusplus::message::variant_ns::get<int64_t>(
60 valPropMap->second);
61 }
62 }
63 // Update inventory according to latest tach reported
64 fanEnc.updInventory();
65}
66
Matthew Barth293477d2017-02-17 15:39:36 -060067} // namespace presence
68} // namespace fan
69} // namespace phosphor