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  * @class Represents a fan control zone, which is a group of fans
17  * that behave the same.
18  */
19 class 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 
60         /**
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 
74         /**
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 
88     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;
109 
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,
143                           const EventData& eventData);
144 };
145 
146 }
147 }
148 }
149