1 #pragma once
2 #include "utility.hpp"
3 
4 #include <libevdev/libevdev.h>
5 
6 namespace phosphor
7 {
8 namespace cooling
9 {
10 namespace type
11 {
12 
13 struct FreeEvDev
14 {
15     void operator()(struct libevdev* device) const
16     {
17         libevdev_free(device);
18     }
19 };
20 
21 class CoolingType
22 {
23     using Property = std::string;
24     using Value = std::variant<bool>;
25     // Association between property and its value
26     using PropertyMap = std::map<Property, Value>;
27     using Interface = std::string;
28     // Association between interface and the dbus property
29     using InterfaceMap = std::map<Interface, PropertyMap>;
30     using Object = sdbusplus::message::object_path;
31     // Association between object and the interface
32     using ObjectMap = std::map<Object, InterfaceMap>;
33 
34   public:
35     CoolingType() = delete;
36     ~CoolingType() = default;
37     CoolingType(const CoolingType&) = delete;
38     CoolingType(CoolingType&&) = default;
39     CoolingType& operator=(const CoolingType&) = delete;
40     CoolingType& operator=(CoolingType&&) = default;
41 
42     /**
43      * @brief Constructs Cooling Type Object
44      *
45      * @param[in] bus - Dbus bus object
46      */
47     explicit CoolingType(sdbusplus::bus_t& bus) : bus(bus), gpioFd(-1)
48     {
49         // TODO: Issue openbmc/openbmc#1531 - means to default properties.
50     }
51 
52     /**
53      * @brief Sets airCooled to true.
54      */
55     void setAirCooled();
56     /**
57      * @brief Sets waterCooled to true.
58      */
59     void setWaterCooled();
60     /**
61      * @brief Updates the inventory properties for CoolingType.
62      *
63      * @param[in] path - Path to object to update
64      */
65     void updateInventory(const std::string& path);
66     /**
67      * @brief Setup and read the GPIO device for reading cooling type.
68      *
69      * @param[in] path - Path to the GPIO device file to read
70      * @param[in] pin  - Event/key code to read (pin)
71      */
72     void readGpio(const std::string& path, unsigned int pin);
73 
74   private:
75     /** @brief Connection for sdbusplus bus */
76     sdbusplus::bus_t& bus;
77     // File descriptor for the GPIO file we are going to read.
78     phosphor::fan::util::FileDescriptor gpioFd;
79     bool airCooled = false;
80     bool waterCooled = false;
81 
82     /**
83      * @brief Construct the inventory object map for CoolingType.
84      *
85      * @param[in] objpath - Path to object to update
86      *
87      * @return The inventory object map to update inventory
88      */
89     ObjectMap getObjectMap(const std::string& objpath);
90 };
91 
92 } // namespace type
93 } // namespace cooling
94 } // namespace phosphor
95 
96 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
97