1 #pragma once 2 #include <vector> 3 #include <sdbusplus/bus.hpp> 4 #include <sdbusplus/server.hpp> 5 #include "fan.hpp" 6 #include "types.hpp" 7 8 namespace phosphor 9 { 10 namespace fan 11 { 12 namespace control 13 { 14 15 /** 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 /** 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 * 46 * @param[in] mode - mode of fan control 47 * @param[in] bus - the dbus object 48 * @param[in] def - the fan zone definition data 49 */ 50 Zone(Mode mode, 51 sdbusplus::bus::bus& bus, 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 73 /** 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 /** 82 * @brief Sets a given object's property value 83 * 84 * @param[in] object - Name of the object containing the property 85 * @param[in] property - Property name 86 * @param[in] value - Property value 87 */ 88 void setPropertyValue(const char* object, 89 const char* property, 90 bool value) 91 { 92 _properties[object][property] = value; 93 }; 94 95 /** 96 * @brief Get the value of an object's property 97 * 98 * @param[in] object - Name of the object containing the property 99 * @param[in] property - Property name 100 * 101 * @return - The property value 102 */ 103 inline auto getPropertyValue(const std::string& object, 104 const std::string& property) 105 { 106 return _properties[object][property]; 107 }; 108 109 private: 110 111 /** 112 * The dbus object 113 */ 114 sdbusplus::bus::bus& _bus; 115 116 /** 117 * Full speed for the zone 118 */ 119 const uint64_t _fullSpeed; 120 121 /** 122 * The zone number 123 */ 124 const size_t _zoneNum; 125 126 /** 127 * Automatic fan control active state 128 */ 129 bool _isActive = true; 130 131 /** 132 * The vector of fans in this zone 133 */ 134 std::vector<std::unique_ptr<Fan>> _fans; 135 136 /** 137 * @brief Map of object property values 138 */ 139 std::map<std::string, std::map<std::string, bool>> _properties; 140 141 /** 142 * @brief Map of active fan control allowed by groups 143 */ 144 std::map<const Group*, bool> _active; 145 146 /** 147 * @brief List of signal event arguments 148 */ 149 std::vector<std::unique_ptr<EventData>> _signalEvents; 150 151 /** 152 * @brief list of Dbus matches for callbacks 153 */ 154 std::vector<sdbusplus::server::match::match> _matches; 155 156 /** 157 * @brief Get a property value from the path/interface given 158 * 159 * @param[in] bus - the bus to use 160 * @param[in] path - the dbus path name 161 * @param[in] iface - the dbus interface name 162 * @param[in] prop - the property name 163 * @param[out] value - the value of the property 164 */ 165 template <typename T> 166 static void getProperty(sdbusplus::bus::bus& bus, 167 const std::string& path, 168 const std::string& iface, 169 const std::string& prop, 170 T& value); 171 172 /** 173 * @brief Dbus signal change callback handler 174 * 175 * @param[in] msg - Expanded sdbusplus message data 176 * @param[in] eventData - The single event's data 177 */ 178 void handleEvent(sdbusplus::message::message& msg, 179 const EventData* eventData); 180 }; 181 182 } 183 } 184 } 185