Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <string> |
| 4 | #include <vector> |
| 5 | #include <memory> |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 6 | #include <nlohmann/json.hpp> |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 7 | |
| 8 | #include "config.h" |
| 9 | #include "rpolicy.hpp" |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 10 | #include "fan.hpp" |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 11 | #include "psensor.hpp" |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace fan |
| 16 | { |
| 17 | namespace presence |
| 18 | { |
| 19 | |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 20 | using json = nlohmann::json; |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 21 | using policies = std::vector<std::unique_ptr<RedundancyPolicy>>; |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 22 | // Presence method handler function |
| 23 | using methodHandler = std::function< |
| 24 | std::unique_ptr<PresenceSensor>(size_t, const json&)>; |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 25 | |
| 26 | class JsonConfig |
| 27 | { |
| 28 | public: |
| 29 | |
| 30 | JsonConfig() = delete; |
| 31 | JsonConfig(const JsonConfig&) = delete; |
| 32 | JsonConfig(JsonConfig&&) = delete; |
| 33 | JsonConfig& operator=(const JsonConfig&) = delete; |
| 34 | JsonConfig& operator=(JsonConfig&&) = delete; |
| 35 | ~JsonConfig() = default; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * Parses and populates the fan presence policies from a json file |
| 40 | * |
| 41 | * @param[in] jsonFile - json configuration file |
| 42 | */ |
| 43 | explicit JsonConfig(const std::string& jsonFile); |
| 44 | |
| 45 | /** |
| 46 | * @brief Get the json config based fan presence policies |
| 47 | * |
| 48 | * @return - The fan presence policies |
| 49 | */ |
| 50 | static const policies& get(); |
| 51 | |
| 52 | private: |
| 53 | |
| 54 | /* Fan presence policies */ |
| 55 | static policies _policies; |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 56 | |
| 57 | /* List of Fan objects to have presence policies */ |
| 58 | std::vector<Fan> _fans; |
| 59 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 60 | /* Presence methods mapping to their associated handler function */ |
| 61 | static const std::map<std::string, methodHandler> _methods; |
| 62 | |
| 63 | /* List of fan presence sensors */ |
| 64 | std::vector<std::unique_ptr<PresenceSensor>> _sensors; |
| 65 | |
Matthew Barth | 4a94dec | 2019-11-15 10:40:47 -0600 | [diff] [blame] | 66 | /** |
| 67 | * @brief Process the json config to extract the defined fan presence |
| 68 | * policies. |
| 69 | * |
| 70 | * @param[in] jsonConf - parsed json configuration data |
| 71 | */ |
| 72 | void process(const json& jsonConf); |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 73 | }; |
| 74 | |
Matthew Barth | e756663 | 2019-11-18 16:13:04 -0600 | [diff] [blame] | 75 | /** |
| 76 | * Methods of fan presence detection function declarations |
| 77 | */ |
| 78 | namespace method |
| 79 | { |
| 80 | /** |
| 81 | * @brief Fan presence detection method by tach feedback |
| 82 | * |
| 83 | * @param[in] fanIndex - fan object index to add tach method |
| 84 | * @param[in] method - json properties for a tach method |
| 85 | * |
| 86 | * @return - A presence sensor to detect fan presence by tach feedback |
| 87 | */ |
| 88 | std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, |
| 89 | const json& method); |
| 90 | |
| 91 | /** |
| 92 | * @brief Fan presence detection method by gpio |
| 93 | * |
| 94 | * @param[in] fanIndex - fan object index to add gpio method |
| 95 | * @param[in] method - json properties for a gpio method |
| 96 | * |
| 97 | * @return - A presence sensor to detect fan presence by gpio |
| 98 | */ |
| 99 | std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, |
| 100 | const json& method); |
| 101 | |
| 102 | } // namespace method |
| 103 | |
Matthew Barth | fd05d64 | 2019-11-14 15:01:57 -0600 | [diff] [blame] | 104 | } // namespace presence |
| 105 | } // namespace fan |
| 106 | } // namespace phosphor |