blob: 1af0c22d3a35cb4c20c647d6df925cbe6746c72e [file] [log] [blame]
Matt Spinler7f88fe62017-04-10 14:39:02 -05001#pragma once
2#include <vector>
3#include <sdbusplus/bus.hpp>
Matthew Barth38a93a82017-05-11 14:12:27 -05004#include <sdbusplus/server.hpp>
Matt Spinler7f88fe62017-04-10 14:39:02 -05005#include "fan.hpp"
6#include "types.hpp"
7
8namespace phosphor
9{
10namespace fan
11{
12namespace control
13{
14
15/**
Matthew Barth14184132017-05-19 14:37:30 -050016 * The mode fan control will run in:
17 * - init - only do the initialization steps
18 * - control - run normal control algorithms
19 */
20enum class Mode
21{
22 init,
23 control
24};
25
26/**
Matt Spinler7f88fe62017-04-10 14:39:02 -050027 * @class Represents a fan control zone, which is a group of fans
28 * that behave the same.
29 */
30class 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 Barth14184132017-05-19 14:37:30 -050046 * @param[in] mode - mode of fan control
Matt Spinler7f88fe62017-04-10 14:39:02 -050047 * @param[in] bus - the dbus object
48 * @param[in] def - the fan zone definition data
49 */
Matthew Barth14184132017-05-19 14:37:30 -050050 Zone(Mode mode,
51 sdbusplus::bus::bus& bus,
Matt Spinler7f88fe62017-04-10 14:39:02 -050052 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 Barth38a93a82017-05-11 14:12:27 -050073 /**
Matthew Barth861d77c2017-05-22 14:18:25 -050074 * @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 Barth38a93a82017-05-11 14:12:27 -050082 * @brief Sets a given object's property value
83 *
84 * @param[in] object - Name of the object containing the property
Matthew Barthcec5ab72017-06-02 15:20:56 -050085 * @param[in] interface - Interface name containing the property
Matthew Barth38a93a82017-05-11 14:12:27 -050086 * @param[in] property - Property name
87 * @param[in] value - Property value
88 */
Matthew Barth9e741ed2017-06-02 16:29:09 -050089 template <typename T>
Matthew Barth38a93a82017-05-11 14:12:27 -050090 void setPropertyValue(const char* object,
Matthew Barthcec5ab72017-06-02 15:20:56 -050091 const char* interface,
Matthew Barth38a93a82017-05-11 14:12:27 -050092 const char* property,
Matthew Barth9e741ed2017-06-02 16:29:09 -050093 T value)
Matthew Barth38a93a82017-05-11 14:12:27 -050094 {
Matthew Barthcec5ab72017-06-02 15:20:56 -050095 _properties[object][interface][property] = value;
Matthew Barth38a93a82017-05-11 14:12:27 -050096 };
97
Matthew Barth17d1fe22017-05-11 15:00:36 -050098 /**
99 * @brief Get the value of an object's property
100 *
101 * @param[in] object - Name of the object containing the property
Matthew Barthcec5ab72017-06-02 15:20:56 -0500102 * @param[in] interface - Interface name containing the property
Matthew Barth17d1fe22017-05-11 15:00:36 -0500103 * @param[in] property - Property name
104 *
105 * @return - The property value
106 */
Matthew Barth9e741ed2017-06-02 16:29:09 -0500107 template <typename T>
Matthew Barth17d1fe22017-05-11 15:00:36 -0500108 inline auto getPropertyValue(const std::string& object,
Matthew Barthcec5ab72017-06-02 15:20:56 -0500109 const std::string& interface,
Matthew Barth17d1fe22017-05-11 15:00:36 -0500110 const std::string& property)
111 {
Matthew Barth9e741ed2017-06-02 16:29:09 -0500112 return sdbusplus::message::variant_ns::get<T>(
113 _properties[object][interface][property]);
Matthew Barth17d1fe22017-05-11 15:00:36 -0500114 };
115
Matt Spinler7f88fe62017-04-10 14:39:02 -0500116 private:
117
118 /**
119 * The dbus object
120 */
121 sdbusplus::bus::bus& _bus;
122
123 /**
124 * Full speed for the zone
125 */
126 const uint64_t _fullSpeed;
127
128 /**
129 * The zone number
130 */
131 const size_t _zoneNum;
132
133 /**
Matthew Barth861d77c2017-05-22 14:18:25 -0500134 * Automatic fan control active state
135 */
136 bool _isActive = true;
137
138 /**
Matt Spinler7f88fe62017-04-10 14:39:02 -0500139 * The vector of fans in this zone
140 */
141 std::vector<std::unique_ptr<Fan>> _fans;
Matthew Barth38a93a82017-05-11 14:12:27 -0500142
143 /**
144 * @brief Map of object property values
145 */
Matthew Barthcec5ab72017-06-02 15:20:56 -0500146 std::map<std::string,
147 std::map<std::string,
148 std::map<std::string,
Matthew Barth9e741ed2017-06-02 16:29:09 -0500149 PropertyVariantType>>> _properties;
Matthew Barth38a93a82017-05-11 14:12:27 -0500150
151 /**
Matthew Barth861d77c2017-05-22 14:18:25 -0500152 * @brief Map of active fan control allowed by groups
153 */
154 std::map<const Group*, bool> _active;
155
156 /**
Matthew Barth38a93a82017-05-11 14:12:27 -0500157 * @brief List of signal event arguments
158 */
Matthew Barth34f1bda2017-05-31 13:45:36 -0500159 std::vector<std::unique_ptr<EventData>> _signalEvents;
Matthew Barth38a93a82017-05-11 14:12:27 -0500160
161 /**
162 * @brief list of Dbus matches for callbacks
163 */
164 std::vector<sdbusplus::server::match::match> _matches;
165
166 /**
Matthew Barthdf3e8d62017-05-31 11:07:24 -0500167 * @brief Get a property value from the path/interface given
168 *
169 * @param[in] bus - the bus to use
170 * @param[in] path - the dbus path name
171 * @param[in] iface - the dbus interface name
172 * @param[in] prop - the property name
173 * @param[out] value - the value of the property
174 */
Matthew Barthdf3e8d62017-05-31 11:07:24 -0500175 static void getProperty(sdbusplus::bus::bus& bus,
176 const std::string& path,
177 const std::string& iface,
178 const std::string& prop,
Matthew Barth9e741ed2017-06-02 16:29:09 -0500179 PropertyVariantType& value);
Matthew Barthdf3e8d62017-05-31 11:07:24 -0500180
181 /**
Matthew Barth34f1bda2017-05-31 13:45:36 -0500182 * @brief Dbus signal change callback handler
Matthew Barth38a93a82017-05-11 14:12:27 -0500183 *
Matthew Barth34f1bda2017-05-31 13:45:36 -0500184 * @param[in] msg - Expanded sdbusplus message data
185 * @param[in] eventData - The single event's data
Matthew Barth38a93a82017-05-11 14:12:27 -0500186 */
Matthew Barth34f1bda2017-05-31 13:45:36 -0500187 void handleEvent(sdbusplus::message::message& msg,
188 const EventData* eventData);
Matt Spinler7f88fe62017-04-10 14:39:02 -0500189};
190
191}
192}
193}