blob: 60da4418be3c1422f885f036b7fa0e8a5e414c71 [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 Barthf85dddc2017-06-02 11:31:06 -050033void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg)
Matthew Barthcd4f4d12017-02-17 17:48:56 -060034{
35 std::string msgSensor;
36 std::map<std::string, sdbusplus::message::variant<int64_t>> msgData;
37 sdbpMsg.read(msgSensor, msgData);
38
Matthew Barthf85dddc2017-06-02 11:31:06 -050039 // Find the 'Value' property containing tach
40 auto valPropMap = msgData.find("Value");
41 if (valPropMap != msgData.end())
Matthew Barthcd4f4d12017-02-17 17:48:56 -060042 {
Matthew Barthf85dddc2017-06-02 11:31:06 -050043 tach = sdbusplus::message::variant_ns::get<int64_t>(
44 valPropMap->second);
Matthew Barthcd4f4d12017-02-17 17:48:56 -060045 }
46 // Update inventory according to latest tach reported
47 fanEnc.updInventory();
48}
49
Matthew Barth293477d2017-02-17 15:39:36 -060050} // namespace presence
51} // namespace fan
52} // namespace phosphor