Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <vector> |
| 3 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 5 | #include "fan.hpp" |
| 6 | #include "types.hpp" |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace fan |
| 11 | { |
| 12 | namespace control |
| 13 | { |
| 14 | |
| 15 | /** |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 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 | /** |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 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 | * |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 46 | * @param[in] mode - mode of fan control |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 47 | * @param[in] bus - the dbus object |
| 48 | * @param[in] def - the fan zone definition data |
| 49 | */ |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame^] | 50 | Zone(Mode mode, |
| 51 | sdbusplus::bus::bus& bus, |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 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 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 73 | /** |
| 74 | * @brief Sets a given object's property value |
| 75 | * |
| 76 | * @param[in] object - Name of the object containing the property |
| 77 | * @param[in] property - Property name |
| 78 | * @param[in] value - Property value |
| 79 | */ |
| 80 | void setPropertyValue(const char* object, |
| 81 | const char* property, |
| 82 | bool value) |
| 83 | { |
| 84 | _properties[object][property] = value; |
| 85 | }; |
| 86 | |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 87 | /** |
| 88 | * @brief Get the value of an object's property |
| 89 | * |
| 90 | * @param[in] object - Name of the object containing the property |
| 91 | * @param[in] property - Property name |
| 92 | * |
| 93 | * @return - The property value |
| 94 | */ |
| 95 | inline auto getPropertyValue(const std::string& object, |
| 96 | const std::string& property) |
| 97 | { |
| 98 | return _properties[object][property]; |
| 99 | }; |
| 100 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 101 | private: |
| 102 | |
| 103 | /** |
| 104 | * The dbus object |
| 105 | */ |
| 106 | sdbusplus::bus::bus& _bus; |
| 107 | |
| 108 | /** |
| 109 | * Full speed for the zone |
| 110 | */ |
| 111 | const uint64_t _fullSpeed; |
| 112 | |
| 113 | /** |
| 114 | * The zone number |
| 115 | */ |
| 116 | const size_t _zoneNum; |
| 117 | |
| 118 | /** |
| 119 | * The vector of fans in this zone |
| 120 | */ |
| 121 | std::vector<std::unique_ptr<Fan>> _fans; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * @brief Map of object property values |
| 125 | */ |
| 126 | std::map<std::string, std::map<std::string, bool>> _properties; |
| 127 | |
| 128 | /** |
| 129 | * @brief List of signal event arguments |
| 130 | */ |
| 131 | std::vector<std::unique_ptr<SignalEvent>> _signalEvents; |
| 132 | |
| 133 | /** |
| 134 | * @brief list of Dbus matches for callbacks |
| 135 | */ |
| 136 | std::vector<sdbusplus::server::match::match> _matches; |
| 137 | |
| 138 | /** |
| 139 | * @brief Dbus signal change handler |
| 140 | * |
| 141 | * @param[in] msg - Data associated with the subscribed signal |
| 142 | * @param[in] data - Pointer to the event sensor's data |
| 143 | * @param[in] err - Contains any sdbus error reference if occurred |
| 144 | */ |
| 145 | static int signalHandler(sd_bus_message* msg, |
| 146 | void* data, |
| 147 | sd_bus_error* err); |
| 148 | |
| 149 | /** |
| 150 | * @brief Envokes the assigned handler and action |
| 151 | * |
| 152 | * @param[in] msg - Expanded sdbusplus message data |
| 153 | * @param[in] eventData - The event's data |
| 154 | */ |
| 155 | void handleEvent(sdbusplus::message::message& msg, |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 156 | const EventData& eventData); |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | } |
| 160 | } |
| 161 | } |