blob: 91e249dd9c2bce32ee3526dcda61fb4ff68d0233 [file] [log] [blame]
Matthew Barthcd4f4d12017-02-17 17:48:56 -06001#include <sdbusplus/exception.hpp>
Matthew Barth293477d2017-02-17 15:39:36 -06002#include "tach_sensor.hpp"
Matthew Barthcd4f4d12017-02-17 17:48:56 -06003#include "fan_enclosure.hpp"
Matthew Barth293477d2017-02-17 15:39:36 -06004
5
6namespace phosphor
7{
8namespace fan
9{
10namespace presence
11{
12
13bool TachSensor::isPresent()
14{
Matthew Barthd6403822017-02-17 17:10:19 -060015 return (tach != 0);
Matthew Barth293477d2017-02-17 15:39:36 -060016}
17
Matthew Barthcd4f4d12017-02-17 17:48:56 -060018// Tach signal callback handler
19int TachSensor::handleTachChangeSignal(sd_bus_message* msg,
20 void* usrData,
21 sd_bus_error* err)
22{
23 auto sdbpMsg = sdbusplus::message::message(msg);
24 static_cast<TachSensor*>(usrData)->handleTachChange(sdbpMsg, err);
25 return 0;
26}
27
28void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg,
29 sd_bus_error* err)
30{
31 std::string msgSensor;
32 std::map<std::string, sdbusplus::message::variant<int64_t>> msgData;
33 sdbpMsg.read(msgSensor, msgData);
34
35 // TODO openbmc/phosphor-fan-presence#5
36 // Update to use 'arg0namespace' match option to reduce dbus traffic
37 // Find interface with value property
38 if (msgSensor.compare("xyz.openbmc_project.Sensor.Value") == 0)
39 {
40 // Find the 'Value' property containing tach
41 auto valPropMap = msgData.find("Value");
42 if (valPropMap != msgData.end())
43 {
44 tach = sdbusplus::message::variant_ns::get<int64_t>(
45 valPropMap->second);
46 }
47 }
48 // Update inventory according to latest tach reported
49 fanEnc.updInventory();
50}
51
Matthew Barth293477d2017-02-17 15:39:36 -060052} // namespace presence
53} // namespace fan
54} // namespace phosphor