Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <vector> |
| 3 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 5 | #include "fan.hpp" |
| 6 | #include "types.hpp" |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace fan |
| 11 | { |
| 12 | namespace control |
| 13 | { |
| 14 | |
| 15 | /** |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 16 | * The mode fan control will run in: |
| 17 | * - init - only do the initialization steps |
| 18 | * - control - run normal control algorithms |
| 19 | */ |
| 20 | enum class Mode |
| 21 | { |
| 22 | init, |
| 23 | control |
| 24 | }; |
| 25 | |
| 26 | /** |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 27 | * @class Represents a fan control zone, which is a group of fans |
| 28 | * that behave the same. |
| 29 | */ |
| 30 | class Zone |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | Zone() = delete; |
| 35 | Zone(const Zone&) = delete; |
| 36 | Zone(Zone&&) = default; |
| 37 | Zone& operator=(const Zone&) = delete; |
| 38 | Zone& operator=(Zone&&) = delete; |
| 39 | ~Zone() = default; |
| 40 | |
| 41 | /** |
| 42 | * Constructor |
| 43 | * Creates the appropriate fan objects based on |
| 44 | * the zone definition data passed in. |
| 45 | * |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 46 | * @param[in] mode - mode of fan control |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 47 | * @param[in] bus - the dbus object |
| 48 | * @param[in] def - the fan zone definition data |
| 49 | */ |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 50 | Zone(Mode mode, |
| 51 | sdbusplus::bus::bus& bus, |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 52 | const ZoneDefinition& def); |
| 53 | |
| 54 | /** |
| 55 | * Sets all fans in the zone to the speed |
| 56 | * passed in |
| 57 | * |
| 58 | * @param[in] speed - the fan speed |
| 59 | */ |
| 60 | void setSpeed(uint64_t speed); |
| 61 | |
| 62 | /** |
| 63 | * Sets the zone to full speed |
| 64 | */ |
| 65 | inline void setFullSpeed() |
| 66 | { |
| 67 | if (_fullSpeed != 0) |
| 68 | { |
| 69 | setSpeed(_fullSpeed); |
| 70 | } |
| 71 | } |
| 72 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 73 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 74 | * @brief Sets the automatic fan control allowed active state |
| 75 | * |
| 76 | * @param[in] group - A group that affects the active state |
| 77 | * @param[in] isActiveAllow - Active state according to group |
| 78 | */ |
| 79 | void setActiveAllow(const Group* group, bool isActiveAllow); |
| 80 | |
| 81 | /** |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 82 | * @brief Sets a given object's property value |
| 83 | * |
| 84 | * @param[in] object - Name of the object containing the property |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 85 | * @param[in] interface - Interface name containing the property |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 86 | * @param[in] property - Property name |
| 87 | * @param[in] value - Property value |
| 88 | */ |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 89 | template <typename T> |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 90 | void setPropertyValue(const char* object, |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 91 | const char* interface, |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 92 | const char* property, |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 93 | T value) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 94 | { |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 95 | _properties[object][interface][property] = value; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 98 | /** |
| 99 | * @brief Get the value of an object's property |
| 100 | * |
| 101 | * @param[in] object - Name of the object containing the property |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 102 | * @param[in] interface - Interface name containing the property |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 103 | * @param[in] property - Property name |
| 104 | * |
| 105 | * @return - The property value |
| 106 | */ |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 107 | template <typename T> |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 108 | inline auto getPropertyValue(const std::string& object, |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 109 | const std::string& interface, |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 110 | const std::string& property) |
| 111 | { |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 112 | return sdbusplus::message::variant_ns::get<T>( |
| 113 | _properties[object][interface][property]); |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 116 | /** |
| 117 | * @brief Get the default floor speed |
| 118 | * |
| 119 | * @return - The defined default floor speed |
| 120 | */ |
| 121 | inline auto getDefFloor() |
| 122 | { |
| 123 | return _defFloorSpeed; |
| 124 | }; |
| 125 | |
Matthew Barth | 4af419c | 2017-06-12 13:39:31 -0500 | [diff] [blame] | 126 | /** |
| 127 | * @brief Set the floor speed to the given speed |
| 128 | * |
| 129 | * @param[in] speed - Speed to set the floor to |
| 130 | */ |
| 131 | inline void setFloor(uint64_t speed) |
| 132 | { |
| 133 | _floorSpeed = speed; |
| 134 | }; |
| 135 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 136 | private: |
| 137 | |
| 138 | /** |
| 139 | * The dbus object |
| 140 | */ |
| 141 | sdbusplus::bus::bus& _bus; |
| 142 | |
| 143 | /** |
| 144 | * Full speed for the zone |
| 145 | */ |
| 146 | const uint64_t _fullSpeed; |
| 147 | |
| 148 | /** |
| 149 | * The zone number |
| 150 | */ |
| 151 | const size_t _zoneNum; |
| 152 | |
| 153 | /** |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 154 | * The default floor speed for the zone |
| 155 | */ |
| 156 | const uint64_t _defFloorSpeed; |
| 157 | |
| 158 | /** |
Matthew Barth | 4af419c | 2017-06-12 13:39:31 -0500 | [diff] [blame] | 159 | * The floor speed to not go below |
| 160 | */ |
| 161 | uint64_t _floorSpeed = _defFloorSpeed; |
| 162 | |
| 163 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 164 | * Automatic fan control active state |
| 165 | */ |
| 166 | bool _isActive = true; |
| 167 | |
| 168 | /** |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 169 | * The vector of fans in this zone |
| 170 | */ |
| 171 | std::vector<std::unique_ptr<Fan>> _fans; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * @brief Map of object property values |
| 175 | */ |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 176 | std::map<std::string, |
| 177 | std::map<std::string, |
| 178 | std::map<std::string, |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 179 | PropertyVariantType>>> _properties; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 180 | |
| 181 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 182 | * @brief Map of active fan control allowed by groups |
| 183 | */ |
| 184 | std::map<const Group*, bool> _active; |
| 185 | |
| 186 | /** |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 187 | * @brief List of signal event arguments |
| 188 | */ |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 189 | std::vector<std::unique_ptr<EventData>> _signalEvents; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * @brief list of Dbus matches for callbacks |
| 193 | */ |
| 194 | std::vector<sdbusplus::server::match::match> _matches; |
| 195 | |
| 196 | /** |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 197 | * @brief Get a property value from the path/interface given |
| 198 | * |
| 199 | * @param[in] bus - the bus to use |
| 200 | * @param[in] path - the dbus path name |
| 201 | * @param[in] iface - the dbus interface name |
| 202 | * @param[in] prop - the property name |
| 203 | * @param[out] value - the value of the property |
| 204 | */ |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 205 | static void getProperty(sdbusplus::bus::bus& bus, |
| 206 | const std::string& path, |
| 207 | const std::string& iface, |
| 208 | const std::string& prop, |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 209 | PropertyVariantType& value); |
Matthew Barth | df3e8d6 | 2017-05-31 11:07:24 -0500 | [diff] [blame] | 210 | |
| 211 | /** |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 212 | * @brief Dbus signal change callback handler |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 213 | * |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 214 | * @param[in] msg - Expanded sdbusplus message data |
| 215 | * @param[in] eventData - The single event's data |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 216 | */ |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 217 | void handleEvent(sdbusplus::message::message& msg, |
| 218 | const EventData* eventData); |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | } |
| 222 | } |
| 223 | } |