Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -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 | |
| 18 | #include "json_config.hpp" |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 19 | #include "trust_group.hpp" |
| 20 | #include "types.hpp" |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 21 | |
| 22 | #include <nlohmann/json.hpp> |
| 23 | #include <sdbusplus/bus.hpp> |
| 24 | |
| 25 | namespace phosphor::fan::monitor |
| 26 | { |
| 27 | |
| 28 | using json = nlohmann::json; |
| 29 | |
| 30 | constexpr auto confAppName = "monitor"; |
| 31 | constexpr auto confFileName = "config.json"; |
| 32 | |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 33 | // Trust group class handler function |
| 34 | using trustHandler = std::function<CreateGroupFunction( |
| 35 | const std::vector<trust::GroupDefinition>&)>; |
| 36 | |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 37 | /** |
| 38 | * @brief Get the JSON object |
| 39 | * |
| 40 | * @param[in] bus - The dbus bus object |
| 41 | * |
| 42 | * @return JSON object |
| 43 | * A JSON object created after loading the JSON configuration file |
| 44 | */ |
| 45 | inline const json getJsonObj(sdbusplus::bus::bus& bus) |
| 46 | { |
| 47 | return fan::JsonConfig::load( |
| 48 | fan::JsonConfig::getConfFile(bus, confAppName, confFileName)); |
| 49 | } |
| 50 | |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 51 | /** |
| 52 | * @brief Get any configured trust groups |
| 53 | * |
| 54 | * @param[in] obj - JSON object to parse from |
| 55 | * |
| 56 | * @return List of functions applied on trust groups |
| 57 | */ |
| 58 | const std::vector<CreateGroupFunction> getTrustGrps(const json& obj); |
| 59 | |
Matthew Barth | 22ab93b | 2020-06-08 10:47:56 -0500 | [diff] [blame^] | 60 | /** |
| 61 | * @brief Get the configured sensor definitions that make up a fan |
| 62 | * |
| 63 | * @param[in] sensor - JSON object containing a list of sensors |
| 64 | * |
| 65 | * @return List of sensor definition data that make up a fan being monitored |
| 66 | */ |
| 67 | const std::vector<SensorDefinition> getSensorDefs(const json& sensors); |
| 68 | |
| 69 | /** |
| 70 | * @brief Get the configured fan definitions to be monitored |
| 71 | * |
| 72 | * @param[in] obj - JSON object to parse from |
| 73 | * |
| 74 | * @return List of fan definition data on the fans to be monitored |
| 75 | */ |
| 76 | const std::vector<FanDefinition> getFanDefs(const json& obj); |
| 77 | |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 78 | } // namespace phosphor::fan::monitor |