blob: b9ac9b38138a2500c1fbc422e639a5f3b73a4396 [file] [log] [blame]
Matthew Barth293477d2017-02-17 15:39:36 -06001#pragma once
2
Matthew Barthd6403822017-02-17 17:10:19 -06003#include <sdbusplus/bus.hpp>
Matthew Barthcd4f4d12017-02-17 17:48:56 -06004#include <sdbusplus/server.hpp>
Matthew Barth293477d2017-02-17 15:39:36 -06005#include "sensor_base.hpp"
6
7
8namespace phosphor
9{
10namespace fan
11{
12namespace presence
13{
14
15class TachSensor : public Sensor
16{
17 public:
18 TachSensor() = delete;
19 TachSensor(const TachSensor&) = delete;
20 TachSensor(TachSensor&&) = delete;
21 TachSensor& operator=(const TachSensor&) = delete;
22 TachSensor& operator=(TachSensor&&) = delete;
23 ~TachSensor() = default;
24
Matthew Barthcd4f4d12017-02-17 17:48:56 -060025 TachSensor(
26 sdbusplus::bus::bus& bus,
27 const std::string& id,
28 FanEnclosure& fanEnc) :
29 Sensor(id, fanEnc),
30 bus(bus),
31 tachSignal(bus,
32 match(id).c_str(),
33 handleTachChangeSignal,
34 this)
Matthew Barthd6403822017-02-17 17:10:19 -060035 {
36 // Nothing to do here
37 }
38
Matthew Barth293477d2017-02-17 15:39:36 -060039 bool isPresent();
40
41 private:
Matthew Barthd6403822017-02-17 17:10:19 -060042 sdbusplus::bus::bus& bus;
Matthew Barthcd4f4d12017-02-17 17:48:56 -060043 sdbusplus::server::match::match tachSignal;
Matthew Barthd6403822017-02-17 17:10:19 -060044 int64_t tach = 0;
Matthew Barth293477d2017-02-17 15:39:36 -060045
Matthew Barthcd4f4d12017-02-17 17:48:56 -060046 static std::string match(std::string id)
47 {
48 return std::string("type='signal',"
49 "interface='org.freedesktop.DBus.Properties',"
50 "member='PropertiesChanged',"
51 "path='/xyz/openbmc_project/sensors/fan_tach/" +
52 id + "'");
53 }
54 // Tach signal callback handler
55 static int handleTachChangeSignal(sd_bus_message* msg,
56 void* data,
57 sd_bus_error* err);
58
59 void handleTachChange(sdbusplus::message::message& msg,
60 sd_bus_error* err);
61
Matthew Barth293477d2017-02-17 15:39:36 -060062};
63
64} // namespace presence
65} // namespace fan
66} // namespace phosphor