summaryrefslogtreecommitdiffstats
path: root/cooling-type/cooling_type.hpp
blob: aa02bfae846796d918d9d8a95dab286a8a9a045a (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
#pragma once
#include "utility.hpp"
#include <libevdev/libevdev.h>

namespace phosphor
{
namespace cooling
{
namespace type
{

constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";

struct FreeEvDev
{
    void operator()(struct libevdev* device) const
    {
        libevdev_free(device);
    }
};

class CoolingType
{
        using Property = std::string;
        using Value = sdbusplus::message::variant<bool>;
        // 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:
        CoolingType() = delete;
        ~CoolingType() = default;
        CoolingType(const CoolingType&) = delete;
        CoolingType(CoolingType&&) = default;
        CoolingType& operator=(const CoolingType&) = delete;
        CoolingType& operator=(CoolingType&&) = default;

        /**
         * @brief Constructs Cooling Type Object
         *
         * @param[in] bus - Dbus bus object
         */
        CoolingType(sdbusplus::bus::bus& bus) : bus(bus)
        {
            //TODO: Issue openbmc/openbmc#1531 - means to default properties.
        }

        /**
         * @brief Sets airCooled to true.
         */
        void setAirCooled();
        /**
         * @brief Sets waterCooled to true.
         */
        void setWaterCooled();
        /**
         * @brief Updates the inventory properties for CoolingType.
         *
         * @param[in] path - Path to object to update
         */
        void updateInventory(const std::string& path);
        /**
         * @brief Setup and read the GPIO device for reading cooling type.
         *
         * @param[in] path - Path to the GPIO device file to read
         * @param[in] pin  - Event/key code to read (pin)
         */
        void readGpio(const std::string& path, unsigned int pin);

    private:
        /** @brief Connection for sdbusplus bus */
        sdbusplus::bus::bus& bus;
        // File descriptor for the GPIO file we are going to read.
        phosphor::fan::util::FileDescriptor gpioFd = -1;
        bool airCooled = false;
        bool waterCooled = false;

        /**
         * @brief Construct the inventory object map for CoolingType.
         *
         * @param[in] objpath - Path to object to update
         *
         * @return The inventory object map to update inventory
         */
        ObjectMap getObjectMap(const std::string& objpath);

};

}
}
}

// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud