blob: ba53fda00ec42ce9df8041d3e9c1a61e7258e93f [file] [log] [blame]
Matthew Barthccaf2db2020-06-04 13:09:35 -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
18#include "json_config.hpp"
Matthew Barth9ea8bee2020-06-04 14:27:19 -050019#include "trust_group.hpp"
20#include "types.hpp"
Matthew Barthccaf2db2020-06-04 13:09:35 -050021
22#include <nlohmann/json.hpp>
23#include <sdbusplus/bus.hpp>
24
25namespace phosphor::fan::monitor
26{
27
28using json = nlohmann::json;
Matt Spinlerf06ab072020-10-14 12:58:22 -050029class PowerOffRule;
30class PowerInterfaceBase;
Matthew Barthccaf2db2020-06-04 13:09:35 -050031
32constexpr auto confAppName = "monitor";
33constexpr auto confFileName = "config.json";
34
Matthew Barth9ea8bee2020-06-04 14:27:19 -050035// Trust group class handler function
36using trustHandler = std::function<CreateGroupFunction(
37 const std::vector<trust::GroupDefinition>&)>;
Matthew Barth3ad14342020-06-08 16:17:42 -050038// Fan monitoring condition handler function
39using condHandler = std::function<Condition(const json&)>;
Matthew Barth9ea8bee2020-06-04 14:27:19 -050040
Matthew Barthccaf2db2020-06-04 13:09:35 -050041/**
42 * @brief Get the JSON object
43 *
44 * @param[in] bus - The dbus bus object
45 *
46 * @return JSON object
47 * A JSON object created after loading the JSON configuration file
48 */
49inline const json getJsonObj(sdbusplus::bus::bus& bus)
50{
51 return fan::JsonConfig::load(
52 fan::JsonConfig::getConfFile(bus, confAppName, confFileName));
53}
54
Matthew Barth9ea8bee2020-06-04 14:27:19 -050055/**
56 * @brief Get any configured trust groups
57 *
58 * @param[in] obj - JSON object to parse from
59 *
60 * @return List of functions applied on trust groups
61 */
62const std::vector<CreateGroupFunction> getTrustGrps(const json& obj);
63
Matthew Barth22ab93b2020-06-08 10:47:56 -050064/**
65 * @brief Get the configured sensor definitions that make up a fan
66 *
67 * @param[in] sensor - JSON object containing a list of sensors
68 *
69 * @return List of sensor definition data that make up a fan being monitored
70 */
71const std::vector<SensorDefinition> getSensorDefs(const json& sensors);
72
73/**
74 * @brief Get the configured fan definitions to be monitored
75 *
76 * @param[in] obj - JSON object to parse from
77 *
78 * @return List of fan definition data on the fans to be monitored
79 */
80const std::vector<FanDefinition> getFanDefs(const json& obj);
81
Matt Spinlerf06ab072020-10-14 12:58:22 -050082/**
83 * @brief Get the configured power off rules
84 *
85 * @param[in] obj - JSON object to parse from
86 *
87 * @param[in] powerInterface - The power interface object to use
88 *
89 * @return std::vector<std::unique_ptr<PowerOffRule>> -
90 * The PowerOffRule objects
91 */
92std::vector<std::unique_ptr<PowerOffRule>>
93 getPowerOffRules(const json& obj,
94 std::shared_ptr<PowerInterfaceBase>& powerInterface);
95
Matt Spinlerf13b42e2020-10-26 15:29:49 -050096/**
97 * @brief Returns the 'num_nonfunc_rotors_before_error field
98 *
99 * @param[in] obj - JSON object to parse from
100 *
101 * @return optional<size_t> - The value, or std::nullopt if not present
102 */
103std::optional<size_t> getNumNonfuncRotorsBeforeError(const json& obj);
104
Matthew Barthccaf2db2020-06-04 13:09:35 -0500105} // namespace phosphor::fan::monitor