blob: 2e7ad72ea89814c0719019c84eb4710e61672d54 [file] [log] [blame]
Matthew Barthfd05d642019-11-14 15:01:57 -06001#pragma once
2
3#include <string>
4#include <vector>
5#include <memory>
Matthew Barth4a94dec2019-11-15 10:40:47 -06006#include <nlohmann/json.hpp>
Matthew Barthfd05d642019-11-14 15:01:57 -06007
8#include "config.h"
9#include "rpolicy.hpp"
Matthew Barth4a94dec2019-11-15 10:40:47 -060010#include "fan.hpp"
Matthew Barthfd05d642019-11-14 15:01:57 -060011
12namespace phosphor
13{
14namespace fan
15{
16namespace presence
17{
18
Matthew Barth4a94dec2019-11-15 10:40:47 -060019using json = nlohmann::json;
Matthew Barthfd05d642019-11-14 15:01:57 -060020using policies = std::vector<std::unique_ptr<RedundancyPolicy>>;
21
22class JsonConfig
23{
24 public:
25
26 JsonConfig() = delete;
27 JsonConfig(const JsonConfig&) = delete;
28 JsonConfig(JsonConfig&&) = delete;
29 JsonConfig& operator=(const JsonConfig&) = delete;
30 JsonConfig& operator=(JsonConfig&&) = delete;
31 ~JsonConfig() = default;
32
33 /**
34 * Constructor
35 * Parses and populates the fan presence policies from a json file
36 *
37 * @param[in] jsonFile - json configuration file
38 */
39 explicit JsonConfig(const std::string& jsonFile);
40
41 /**
42 * @brief Get the json config based fan presence policies
43 *
44 * @return - The fan presence policies
45 */
46 static const policies& get();
47
48 private:
49
50 /* Fan presence policies */
51 static policies _policies;
Matthew Barth4a94dec2019-11-15 10:40:47 -060052
53 /* List of Fan objects to have presence policies */
54 std::vector<Fan> _fans;
55
56 /**
57 * @brief Process the json config to extract the defined fan presence
58 * policies.
59 *
60 * @param[in] jsonConf - parsed json configuration data
61 */
62 void process(const json& jsonConf);
Matthew Barthfd05d642019-11-14 15:01:57 -060063};
64
65} // namespace presence
66} // namespace fan
67} // namespace phosphor