Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 1 | #include <sdbusplus/exception.hpp> |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 2 | #include "tach_sensor.hpp" |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 3 | #include "fan_enclosure.hpp" |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 4 | |
| 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace fan |
| 9 | { |
| 10 | namespace presence |
| 11 | { |
| 12 | |
| 13 | bool TachSensor::isPresent() |
| 14 | { |
Matthew Barth | d640382 | 2017-02-17 17:10:19 -0600 | [diff] [blame] | 15 | return (tach != 0); |
Matthew Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 16 | } |
| 17 | |
Matthew Barth | cd4f4d1 | 2017-02-17 17:48:56 -0600 | [diff] [blame] | 18 | // Tach signal callback handler |
| 19 | int 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 | |
| 28 | void 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 Barth | 293477d | 2017-02-17 15:39:36 -0600 | [diff] [blame] | 52 | } // namespace presence |
| 53 | } // namespace fan |
| 54 | } // namespace phosphor |