Matthew Barth | d87f89f | 2020-07-30 10:41:32 -0500 | [diff] [blame] | 1 | /** |
| 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 Barth | 2331d18 | 2020-08-18 15:00:27 -0500 | [diff] [blame] | 18 | #include "json/profile.hpp" |
| 19 | #include "json_config.hpp" |
Matthew Barth | 23ac24c | 2020-08-04 13:55:43 -0500 | [diff] [blame] | 20 | #include "types.hpp" |
| 21 | |
Matthew Barth | 2331d18 | 2020-08-18 15:00:27 -0500 | [diff] [blame] | 22 | #include <nlohmann/json.hpp> |
Matthew Barth | 23ac24c | 2020-08-04 13:55:43 -0500 | [diff] [blame] | 23 | #include <sdbusplus/bus.hpp> |
| 24 | |
Matthew Barth | 2331d18 | 2020-08-18 15:00:27 -0500 | [diff] [blame] | 25 | #include <map> |
| 26 | #include <memory> |
| 27 | |
Matthew Barth | d87f89f | 2020-07-30 10:41:32 -0500 | [diff] [blame] | 28 | namespace phosphor::fan::control |
Matthew Barth | 167d2dd | 2020-08-04 12:19:16 -0500 | [diff] [blame] | 29 | { |
| 30 | |
Matthew Barth | 2331d18 | 2020-08-18 15:00:27 -0500 | [diff] [blame] | 31 | /* Application name to be appended to the path for loading a JSON config file */ |
Matthew Barth | 167d2dd | 2020-08-04 12:19:16 -0500 | [diff] [blame] | 32 | constexpr auto confAppName = "control"; |
| 33 | |
Matthew Barth | 23ac24c | 2020-08-04 13:55:43 -0500 | [diff] [blame] | 34 | /** |
Matthew Barth | 2331d18 | 2020-08-18 15:00:27 -0500 | [diff] [blame] | 35 | * @brief Load the configuration of a given JSON class object type |
| 36 | * |
| 37 | * @param[in] bus - The dbus bus object |
| 38 | * @param[in] isOptional - JSON configuration file is optional or not |
| 39 | * Defaults to false |
| 40 | * |
| 41 | * @return Map of configuration entries |
| 42 | * Map of configuration names to their corresponding configuration object |
| 43 | */ |
| 44 | template <typename T> |
| 45 | std::map<std::string, std::unique_ptr<T>> getConfig(sdbusplus::bus::bus& bus, |
| 46 | bool isOptional = false) |
| 47 | { |
| 48 | std::map<std::string, std::unique_ptr<T>> config; |
| 49 | |
| 50 | auto confFile = fan::JsonConfig::getConfFile(bus, confAppName, |
| 51 | T::confFileName, isOptional); |
| 52 | if (!confFile.empty()) |
| 53 | { |
| 54 | for (const auto& entry : fan::JsonConfig::load(confFile)) |
| 55 | { |
| 56 | auto obj = std::make_unique<T>(bus, entry); |
| 57 | config.emplace(obj->getName(), std::move(obj)); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return config; |
| 62 | } |
| 63 | |
| 64 | /** |
Matthew Barth | 23ac24c | 2020-08-04 13:55:43 -0500 | [diff] [blame] | 65 | * @brief Get the configuration definitions for zone groups |
| 66 | * |
| 67 | * @param[in] bus - The dbus bus object |
| 68 | * |
| 69 | * @return List of zone group objects |
| 70 | * Generated list of zone groups including their control configurations |
| 71 | */ |
| 72 | const std::vector<ZoneGroup> getZoneGroups(sdbusplus::bus::bus& bus); |
| 73 | |
Matthew Barth | 2dc5aba | 2020-08-04 14:23:34 -0500 | [diff] [blame] | 74 | /** |
| 75 | * @brief Get the delay(in seconds) to allow the fans to ramp up to the defined |
| 76 | * power on speed |
| 77 | * |
| 78 | * @param[in] bus - The dbus bus object |
| 79 | * |
| 80 | * @return Time to delay in seconds |
| 81 | * Amount of time to delay in seconds after a power on |
| 82 | */ |
| 83 | const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus); |
| 84 | |
Matthew Barth | 167d2dd | 2020-08-04 12:19:16 -0500 | [diff] [blame] | 85 | } // namespace phosphor::fan::control |