blob: 601c00274780b21626e4f342fa5999dffa0449d8 [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
Matt Spinler7f88fe62017-04-10 14:39:02 -050074 private:
75
76 /**
77 * The dbus object
78 */
79 sdbusplus::bus::bus& _bus;
80
81 /**
82 * Full speed for the zone
83 */
84 const uint64_t _fullSpeed;
85
86 /**
87 * The zone number
88 */
89 const size_t _zoneNum;
90
91 /**
92 * The vector of fans in this zone
93 */
94 std::vector<std::unique_ptr<Fan>> _fans;
Matthew Barth38a93a82017-05-11 14:12:27 -050095
96 /**
97 * @brief Map of object property values
98 */
99 std::map<std::string, std::map<std::string, bool>> _properties;
100
101 /**
102 * @brief List of signal event arguments
103 */
104 std::vector<std::unique_ptr<SignalEvent>> _signalEvents;
105
106 /**
107 * @brief list of Dbus matches for callbacks
108 */
109 std::vector<sdbusplus::server::match::match> _matches;
110
111 /**
112 * @brief Dbus signal change handler
113 *
114 * @param[in] msg - Data associated with the subscribed signal
115 * @param[in] data - Pointer to the event sensor's data
116 * @param[in] err - Contains any sdbus error reference if occurred
117 */
118 static int signalHandler(sd_bus_message* msg,
119 void* data,
120 sd_bus_error* err);
121
122 /**
123 * @brief Envokes the assigned handler and action
124 *
125 * @param[in] msg - Expanded sdbusplus message data
126 * @param[in] eventData - The event's data
127 */
128 void handleEvent(sdbusplus::message::message& msg,
129 const Handler& handler);
Matt Spinler7f88fe62017-04-10 14:39:02 -0500130};
131
132}
133}
134}