blob: 597fdd998611bdfad1c09f3619e7533c82cdf4ea [file] [log] [blame]
Matthew Bartha227a162020-08-05 10:51:45 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
Matthew Barth06764942021-03-04 09:28:40 -060018#include "json_parser.hpp"
19#include "profile.hpp"
20
Matthew Bartha227a162020-08-05 10:51:45 -050021#include <nlohmann/json.hpp>
22#include <sdbusplus/bus.hpp>
Matthew Barth06764942021-03-04 09:28:40 -060023#include <sdeventplus/event.hpp>
Matthew Bartha227a162020-08-05 10:51:45 -050024
25namespace phosphor::fan::control::json
26{
27
28using json = nlohmann::json;
29
30/**
31 * @class Manager - Represents the fan control manager's configuration
32 *
33 * A fan control manager configuration is optional, therefore the "manager.json"
34 * file is also optional. The manager configuration is used to populate
35 * fan control's manager parameters which are used in how the application
36 * operates, not in how the fans are controlled.
37 *
38 * When no manager configuration exists, the fan control application starts,
39 * processes any configured events and then begins controlling fans according
40 * to those events.
41 */
42class Manager
43{
44 public:
45 Manager() = delete;
46 Manager(const Manager&) = delete;
47 Manager(Manager&&) = delete;
48 Manager& operator=(const Manager&) = delete;
49 Manager& operator=(Manager&&) = delete;
50 ~Manager() = default;
51
52 /**
53 * Constructor
54 * Parses and populates the fan control manager attributes from a json file
55 *
56 * @param[in] bus - sdbusplus bus object
Matthew Barth06764942021-03-04 09:28:40 -060057 * @param[in] event - sdeventplus event loop
Matthew Bartha227a162020-08-05 10:51:45 -050058 */
Matthew Barth06764942021-03-04 09:28:40 -060059 Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
Matthew Bartha227a162020-08-05 10:51:45 -050060
61 /**
62 * @brief Get the configured power on delay(OPTIONAL)
63 *
64 * @return Power on delay in seconds
65 * Configured power on delay in seconds, otherwise 0
66 */
67 unsigned int getPowerOnDelay();
68
69 private:
70 /* JSON file name for manager configuration attributes */
71 static constexpr auto confFileName = "manager.json";
72
73 /* The parsed JSON object */
74 json _jsonObj;
Matthew Barth06764942021-03-04 09:28:40 -060075
76 /* List of profiles configured */
77 const std::map<configKey, std::unique_ptr<Profile>> _profiles;
78
79 /* List of active profiles */
80 std::vector<std::string> _activeProfiles;
Matthew Bartha227a162020-08-05 10:51:45 -050081};
82
83} // namespace phosphor::fan::control::json