1 /**
2  * Copyright © 2020 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "config_base.hpp"
19 
20 #include <nlohmann/json.hpp>
21 #include <sdbusplus/bus.hpp>
22 
23 namespace phosphor::fan::control::json
24 {
25 
26 using json = nlohmann::json;
27 
28 /**
29  * @class Fan - Represents a configured fan control fan object
30  *
31  * A fan object contains the configured attributes for a fan within the system
32  * that will be controlled by the fan control application. These configuration
33  * attributes include, but are not limited to, the cooling zone in which the
34  * fan is included, what sensors make up the fan, the target interface to be
35  * used in setting a speed, and any profiles(OPTIONAL) the fan should be
36  * included in.
37  *
38  * (When no profile for a fan is given, the fan defaults to always be included)
39  *
40  */
41 class Fan : public ConfigBase
42 {
43   public:
44     /* JSON file name for fans */
45     static constexpr auto confFileName = "fans.json";
46 
47     Fan() = delete;
48     Fan(const Fan&) = delete;
49     Fan(Fan&&) = delete;
50     Fan& operator=(const Fan&) = delete;
51     Fan& operator=(Fan&&) = delete;
52     ~Fan() = default;
53 
54     /**
55      * Constructor
56      * Parses and populates a zone fan from JSON object data
57      *
58      * @param[in] bus - sdbusplus bus object
59      * @param[in] jsonObj - JSON object
60      */
61     Fan(sdbusplus::bus::bus& bus, const json& jsonObj);
62 
63     /**
64      * @brief Get the zone
65      *
66      * @return Zone this fan belongs in
67      */
68     inline const auto& getZone() const
69     {
70         return _zone;
71     }
72 
73     /**
74      * @brief Get the list of sensors
75      *
76      * @return List of sensors with `Target` property
77      */
78     inline const auto& getSensors() const
79     {
80         return _sensors;
81     }
82 
83     /**
84      * @brief Get the sensors' interface
85      *
86      * @return Interface containing `Target` to use on sensors
87      */
88     inline const auto& getInterface() const
89     {
90         return _interface;
91     }
92 
93   private:
94     /* The zone this fan belongs to */
95     std::string _zone;
96 
97     /**
98      * Sensors containing the `Target` property on
99      * dbus that make up the fan
100      */
101     std::vector<std::string> _sensors;
102 
103     /**
104      * Interface containing the `Target` property
105      * to use in controlling the fan's speed
106      */
107     std::string _interface;
108 
109     /**
110      * @brief Parse and set the fan's zone
111      *
112      * @param[in] jsonObj - JSON object for the fan
113      *
114      * Sets the zone this fan is included in.
115      */
116     void setZone(const json& jsonObj);
117 
118     /**
119      * @brief Parse and set the fan's sensor list
120      *
121      * @param[in] jsonObj - JSON object for the fan
122      *
123      * Sets the list of sensors that contain a `Target` property on dbus
124      * that make up this fan.
125      */
126     void setSensors(const json& jsonObj);
127 
128     /**
129      * @brief Parse and set the fan's sensor interface
130      *
131      * @param[in] jsonObj - JSON object for the fan
132      *
133      * Sets the sensor interface to use when setting the `Target` property
134      */
135     void setInterface(const json& jsonObj);
136 };
137 
138 } // namespace phosphor::fan::control::json
139