blob: c6b64ecee05da8d2b38249f7e3d042c6a657b76c [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"
Matt Spinlerac1efc12020-10-27 10:20:11 -050019#include "power_off_action.hpp"
Matthew Barth9ea8bee2020-06-04 14:27:19 -050020#include "trust_group.hpp"
21#include "types.hpp"
Matthew Barthccaf2db2020-06-04 13:09:35 -050022
23#include <nlohmann/json.hpp>
24#include <sdbusplus/bus.hpp>
25
26namespace phosphor::fan::monitor
27{
28
29using json = nlohmann::json;
Matt Spinlerf06ab072020-10-14 12:58:22 -050030class PowerOffRule;
31class PowerInterfaceBase;
Matt Spinlerac1efc12020-10-27 10:20:11 -050032class System;
Matthew Barthccaf2db2020-06-04 13:09:35 -050033
34constexpr auto confAppName = "monitor";
35constexpr auto confFileName = "config.json";
36
Matthew Barth9ea8bee2020-06-04 14:27:19 -050037// Trust group class handler function
38using trustHandler = std::function<CreateGroupFunction(
39 const std::vector<trust::GroupDefinition>&)>;
Matthew Barth3ad14342020-06-08 16:17:42 -050040// Fan monitoring condition handler function
41using condHandler = std::function<Condition(const json&)>;
Matthew Barth9ea8bee2020-06-04 14:27:19 -050042
Matthew Barthccaf2db2020-06-04 13:09:35 -050043/**
44 * @brief Get the JSON object
45 *
46 * @param[in] bus - The dbus bus object
47 *
48 * @return JSON object
49 * A JSON object created after loading the JSON configuration file
50 */
51inline const json getJsonObj(sdbusplus::bus::bus& bus)
52{
53 return fan::JsonConfig::load(
54 fan::JsonConfig::getConfFile(bus, confAppName, confFileName));
55}
56
Matthew Barth9ea8bee2020-06-04 14:27:19 -050057/**
58 * @brief Get any configured trust groups
59 *
60 * @param[in] obj - JSON object to parse from
61 *
62 * @return List of functions applied on trust groups
63 */
64const std::vector<CreateGroupFunction> getTrustGrps(const json& obj);
65
Matthew Barth22ab93b2020-06-08 10:47:56 -050066/**
67 * @brief Get the configured sensor definitions that make up a fan
68 *
69 * @param[in] sensor - JSON object containing a list of sensors
70 *
71 * @return List of sensor definition data that make up a fan being monitored
72 */
73const std::vector<SensorDefinition> getSensorDefs(const json& sensors);
74
75/**
76 * @brief Get the configured fan definitions to be monitored
77 *
78 * @param[in] obj - JSON object to parse from
79 *
80 * @return List of fan definition data on the fans to be monitored
81 */
82const std::vector<FanDefinition> getFanDefs(const json& obj);
83
Matt Spinlerf06ab072020-10-14 12:58:22 -050084/**
85 * @brief Get the configured power off rules
86 *
87 * @param[in] obj - JSON object to parse from
88 *
89 * @param[in] powerInterface - The power interface object to use
90 *
Matt Spinlerac1efc12020-10-27 10:20:11 -050091 * @param[in] func - Optional user defined function that gets called
92 * right before a power off occurs.
93 *
Matt Spinlerf06ab072020-10-14 12:58:22 -050094 * @return std::vector<std::unique_ptr<PowerOffRule>> -
95 * The PowerOffRule objects
96 */
97std::vector<std::unique_ptr<PowerOffRule>>
98 getPowerOffRules(const json& obj,
Matt Spinlerac1efc12020-10-27 10:20:11 -050099 std::shared_ptr<PowerInterfaceBase>& powerInterface,
100 PowerOffAction::PrePowerOffFunc& func);
Matt Spinlerf06ab072020-10-14 12:58:22 -0500101
Matt Spinlerf13b42e2020-10-26 15:29:49 -0500102/**
103 * @brief Returns the 'num_nonfunc_rotors_before_error field
104 *
105 * @param[in] obj - JSON object to parse from
106 *
107 * @return optional<size_t> - The value, or std::nullopt if not present
108 */
109std::optional<size_t> getNumNonfuncRotorsBeforeError(const json& obj);
110
Matthew Barthccaf2db2020-06-04 13:09:35 -0500111} // namespace phosphor::fan::monitor