blob: d8f3fe4455470e2c2fa4532400f88189d515757d [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/**
16 * @class Represents a fan control zone, which is a group of fans
17 * that behave the same.
18 */
19class Zone
20{
21 public:
22
23 Zone() = delete;
24 Zone(const Zone&) = delete;
25 Zone(Zone&&) = default;
26 Zone& operator=(const Zone&) = delete;
27 Zone& operator=(Zone&&) = delete;
28 ~Zone() = default;
29
30 /**
31 * Constructor
32 * Creates the appropriate fan objects based on
33 * the zone definition data passed in.
34 *
35 * @param[in] bus - the dbus object
36 * @param[in] def - the fan zone definition data
37 */
38 Zone(sdbusplus::bus::bus& bus,
39 const ZoneDefinition& def);
40
41 /**
42 * Sets all fans in the zone to the speed
43 * passed in
44 *
45 * @param[in] speed - the fan speed
46 */
47 void setSpeed(uint64_t speed);
48
49 /**
50 * Sets the zone to full speed
51 */
52 inline void setFullSpeed()
53 {
54 if (_fullSpeed != 0)
55 {
56 setSpeed(_fullSpeed);
57 }
58 }
59
Matthew Barth38a93a82017-05-11 14:12:27 -050060 /**
61 * @brief Sets a given object's property value
62 *
63 * @param[in] object - Name of the object containing the property
64 * @param[in] property - Property name
65 * @param[in] value - Property value
66 */
67 void setPropertyValue(const char* object,
68 const char* property,
69 bool value)
70 {
71 _properties[object][property] = value;
72 };
73
Matthew Barth17d1fe22017-05-11 15:00:36 -050074 /**
75 * @brief Get the value of an object's property
76 *
77 * @param[in] object - Name of the object containing the property
78 * @param[in] property - Property name
79 *
80 * @return - The property value
81 */
82 inline auto getPropertyValue(const std::string& object,
83 const std::string& property)
84 {
85 return _properties[object][property];
86 };
87
Matt Spinler7f88fe62017-04-10 14:39:02 -050088 private:
89
90 /**
91 * The dbus object
92 */
93 sdbusplus::bus::bus& _bus;
94
95 /**
96 * Full speed for the zone
97 */
98 const uint64_t _fullSpeed;
99
100 /**
101 * The zone number
102 */
103 const size_t _zoneNum;
104
105 /**
106 * The vector of fans in this zone
107 */
108 std::vector<std::unique_ptr<Fan>> _fans;
Matthew Barth38a93a82017-05-11 14:12:27 -0500109
110 /**
111 * @brief Map of object property values
112 */
113 std::map<std::string, std::map<std::string, bool>> _properties;
114
115 /**
116 * @brief List of signal event arguments
117 */
118 std::vector<std::unique_ptr<SignalEvent>> _signalEvents;
119
120 /**
121 * @brief list of Dbus matches for callbacks
122 */
123 std::vector<sdbusplus::server::match::match> _matches;
124
125 /**
126 * @brief Dbus signal change handler
127 *
128 * @param[in] msg - Data associated with the subscribed signal
129 * @param[in] data - Pointer to the event sensor's data
130 * @param[in] err - Contains any sdbus error reference if occurred
131 */
132 static int signalHandler(sd_bus_message* msg,
133 void* data,
134 sd_bus_error* err);
135
136 /**
137 * @brief Envokes the assigned handler and action
138 *
139 * @param[in] msg - Expanded sdbusplus message data
140 * @param[in] eventData - The event's data
141 */
142 void handleEvent(sdbusplus::message::message& msg,
Matthew Barth17d1fe22017-05-11 15:00:36 -0500143 const EventData& eventData);
Matt Spinler7f88fe62017-04-10 14:39:02 -0500144};
145
146}
147}
148}