blob: 29d16972c6e9d20ddadaf5427fade63475c23274 [file] [log] [blame]
Matthew Barthd87f89f2020-07-30 10:41:32 -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 Barth2331d182020-08-18 15:00:27 -050018#include "json/profile.hpp"
19#include "json_config.hpp"
Matthew Barth23ac24c2020-08-04 13:55:43 -050020#include "types.hpp"
21
Matthew Barth2331d182020-08-18 15:00:27 -050022#include <nlohmann/json.hpp>
Matthew Barth23ac24c2020-08-04 13:55:43 -050023#include <sdbusplus/bus.hpp>
24
Matthew Barth2331d182020-08-18 15:00:27 -050025#include <map>
26#include <memory>
27
Matthew Barthd87f89f2020-07-30 10:41:32 -050028namespace phosphor::fan::control
Matthew Barth167d2dd2020-08-04 12:19:16 -050029{
30
Matthew Barth2331d182020-08-18 15:00:27 -050031/* Application name to be appended to the path for loading a JSON config file */
Matthew Barth167d2dd2020-08-04 12:19:16 -050032constexpr auto confAppName = "control";
33
Matthew Barth23ac24c2020-08-04 13:55:43 -050034/**
Matthew Barth2331d182020-08-18 15:00:27 -050035 * @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 */
44template <typename T>
45std::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 Barth23ac24c2020-08-04 13:55:43 -050065 * @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 */
72const std::vector<ZoneGroup> getZoneGroups(sdbusplus::bus::bus& bus);
73
Matthew Barth2dc5aba2020-08-04 14:23:34 -050074/**
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 */
83const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus);
84
Matthew Barth167d2dd2020-08-04 12:19:16 -050085} // namespace phosphor::fan::control