summaryrefslogtreecommitdiffstats
path: root/tach_sensor.hpp
blob: b9ac9b38138a2500c1fbc422e639a5f3b73a4396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include "sensor_base.hpp"


namespace phosphor
{
namespace fan
{
namespace presence
{

class TachSensor : public Sensor
{
    public:
        TachSensor() = delete;
        TachSensor(const TachSensor&) = delete;
        TachSensor(TachSensor&&) = delete;
        TachSensor& operator=(const TachSensor&) = delete;
        TachSensor& operator=(TachSensor&&) = delete;
        ~TachSensor() = default;

        TachSensor(
            sdbusplus::bus::bus& bus,
            const std::string& id,
            FanEnclosure& fanEnc) :
                Sensor(id, fanEnc),
                bus(bus),
                tachSignal(bus,
                           match(id).c_str(),
                           handleTachChangeSignal,
                           this)
        {
            // Nothing to do here
        }

        bool isPresent();

    private:
        sdbusplus::bus::bus& bus;
        sdbusplus::server::match::match tachSignal;
        int64_t tach = 0;

        static std::string match(std::string id)
        {
            return std::string("type='signal',"
                               "interface='org.freedesktop.DBus.Properties',"
                               "member='PropertiesChanged',"
                               "path='/xyz/openbmc_project/sensors/fan_tach/" +
                               id + "'");
        }
        // Tach signal callback handler
        static int handleTachChangeSignal(sd_bus_message* msg,
                                          void* data,
                                          sd_bus_error* err);

        void handleTachChange(sdbusplus::message::message& msg,
                              sd_bus_error* err);

};

} // namespace presence
} // namespace fan
} // namespace phosphor
OpenPOWER on IntegriCloud