summaryrefslogtreecommitdiffstats
path: root/fan_enclosure.hpp
blob: 8f5cfdf67502c4c4483172bc81ffe756dc8e9650 (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
111
112
113
114
#pragma once

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


namespace phosphor
{
namespace fan
{
namespace presence
{

/**
 * @brief Specifies the defined presence states of a fan enclosure
 */
typedef enum presenceState
{
    NOT_PRESENT,
    PRESENT,
    UNKNOWN
} presenceState;

/**
 * @class FanEnclosure
 * @brief OpenBMC fan enclosure inventory presence implementation
 * @details Inventory is based on the fan enclosure being present or not. This
 * class represents that fan enclosure and updates its presences status within
 * its inventory object based on the status of all its sensors.
 */
class FanEnclosure
{
    using Property = std::string;
    using Value = sdbusplus::message::variant<bool, int64_t, std::string>;
    // Association between property and its value
    using PropertyMap = std::map<Property, Value>;
    using Interface = std::string;
    // Association between interface and the dbus property
    using InterfaceMap = std::map<Interface, PropertyMap>;
    using Object = sdbusplus::message::object_path;
    // Association between object and the interface
    using ObjectMap = std::map<Object, InterfaceMap>;

    public:
        FanEnclosure() = delete;
        FanEnclosure(const FanEnclosure&) = delete;
        FanEnclosure(FanEnclosure&&) = default;
        FanEnclosure& operator=(const FanEnclosure&) = delete;
        FanEnclosure& operator=(FanEnclosure&&) = delete;
        ~FanEnclosure() = default;

        /**
         * @brief Constructs Fan Enclosure Object
         *
         * @param[in] bus - Dbus bus object
         * @param[in] fanProp - Fan enclosure properties
         */
        FanEnclosure(sdbusplus::bus::bus& bus,
                     const phosphor::fan::Properties& fanProp) :
                        bus(bus),
                        invPath(std::get<0>(fanProp)),
                        fanDesc(std::get<1>(fanProp))
        {
            //Add this fan to inventory
            updInventory();
        }

        /**
         * @brief Update inventory when the determined presence of this fan
         * enclosure has changed
         */
        void updInventory();
        /**
         * @brief Add a sensor association to this fan enclosure
         *
         * @param[in] sensor - Sensor associated to this fan enclosure
         */
        void addSensor(
            std::unique_ptr<Sensor>&& sensor);

    private:
        /** @brief Connection for sdbusplus bus */
        sdbusplus::bus::bus& bus;
        /** @brief Inventory path for this fan enclosure */
        const std::string invPath;
        /** @brief Description used as 'PrettyName' on inventory object */
        const std::string fanDesc;
        /** @brief List of sensors associated with this fan enclosure */
        std::vector<std::unique_ptr<Sensor>> sensors;
        /** @brief Last known presence state of this fan enclosure */
        presenceState presState = UNKNOWN;

        /**
         * @brief Get the current presence state based on all sensors
         *
         * @return Current presence state determined from all sensors
         */
        presenceState getCurPresState();

        /**
         * @brief Construct the inventory object map
         *
         * @param[in] Current presence state
         *
         * @return The inventory object map to update inventory
         */
        ObjectMap getObjectMap(bool curPresState);

};

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