blob: ac91463952cb49429f801eb2135597da4f66c257 [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;
29
30constexpr auto confAppName = "monitor";
31constexpr auto confFileName = "config.json";
32
Matthew Barth9ea8bee2020-06-04 14:27:19 -050033// Trust group class handler function
34using trustHandler = std::function<CreateGroupFunction(
35 const std::vector<trust::GroupDefinition>&)>;
Matthew Barth3ad14342020-06-08 16:17:42 -050036// Fan monitoring condition handler function
37using condHandler = std::function<Condition(const json&)>;
Matthew Barth9ea8bee2020-06-04 14:27:19 -050038
Matthew Barthccaf2db2020-06-04 13:09:35 -050039/**
40 * @brief Get the JSON object
41 *
42 * @param[in] bus - The dbus bus object
43 *
44 * @return JSON object
45 * A JSON object created after loading the JSON configuration file
46 */
47inline const json getJsonObj(sdbusplus::bus::bus& bus)
48{
49 return fan::JsonConfig::load(
50 fan::JsonConfig::getConfFile(bus, confAppName, confFileName));
51}
52
Matthew Barth9ea8bee2020-06-04 14:27:19 -050053/**
54 * @brief Get any configured trust groups
55 *
56 * @param[in] obj - JSON object to parse from
57 *
58 * @return List of functions applied on trust groups
59 */
60const std::vector<CreateGroupFunction> getTrustGrps(const json& obj);
61
Matthew Barth22ab93b2020-06-08 10:47:56 -050062/**
63 * @brief Get the configured sensor definitions that make up a fan
64 *
65 * @param[in] sensor - JSON object containing a list of sensors
66 *
67 * @return List of sensor definition data that make up a fan being monitored
68 */
69const std::vector<SensorDefinition> getSensorDefs(const json& sensors);
70
71/**
72 * @brief Get the configured fan definitions to be monitored
73 *
74 * @param[in] obj - JSON object to parse from
75 *
76 * @return List of fan definition data on the fans to be monitored
77 */
78const std::vector<FanDefinition> getFanDefs(const json& obj);
79
Matthew Barthccaf2db2020-06-04 13:09:35 -050080} // namespace phosphor::fan::monitor