summaryrefslogtreecommitdiffstats
path: root/presence/tach.hpp
blob: 4f02521edf266b9c08269bbb9b8c6c99a71c3781 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once

#include <sdbusplus/message.hpp>
#include <sdbusplus/bus/match.hpp>
#include <string>
#include <vector>
#include "psensor.hpp"
#include "sdbusplus.hpp"

namespace phosphor
{
namespace fan
{
namespace presence
{
class RedundancyPolicy;

/**
 * @class Tach
 * @brief Fan tach sensor presence implementation.
 *
 * The Tach class uses one or more tach speed indicators
 * to determine presence state.
 */
class Tach : public PresenceSensor
{
    public:
        /**
         * @brief
         *
         * Cannot move or copy due to this ptr as context
         * for sdbus callbacks.
         */
        Tach() = delete;
        Tach(const Tach&) = delete;
        Tach& operator=(const Tach&) = delete;
        Tach(Tach&&) = delete;
        Tach& operator=(Tach&&) = delete;
        ~Tach() = default;

        /**
         * @brief ctor
         *
         * @param[in] sensors - Fan tach sensors for this psensor.
         */
        Tach(const std::vector<std::string>& sensors);

        /**
         * @brief start
         *
         * Register for dbus signal callbacks on fan
         * tach sensor change.  Query initial tach speeds.
         *
         * @return The current sensor state.
         */
        bool start() override;

        /**
         * @brief stop
         *
         * De-register dbus signal callbacks.
         */
        void stop() override;

        /**
         * @brief Check the sensor.
         *
         * Query the tach speeds.
         */
        bool present() override;

    private :
        /**
         * @brief Get the policy associated with this sensor.
         */
        virtual RedundancyPolicy& getPolicy() = 0;

        /**
         * @brief Properties changed handler for tach sensor updates.
         *
         * @param[in] sensor - The sensor that changed.
         * @param[in] props - The properties that changed.
         */
        void propertiesChanged(
            size_t sensor,
            const phosphor::fan::util::Properties<int64_t>& props);

        /**
         * @brief Properties changed handler for tach sensor updates.
         *
         * @param[in] sensor - The sensor that changed.
         * @param[in] msg - The sdbusplus signal message.
         */
        void propertiesChanged(
            size_t sensor,
            sdbusplus::message::message& msg);

        /** @brief array of tach sensors dbus matches, and tach values. */
        std::vector<std::tuple<
            std::string,
            std::unique_ptr<sdbusplus::bus::match::match>,
            int64_t>> state;

        /** The current state of the sensor. */
        bool currentState;
};

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