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" |
Matt Spinler | ac1efc1 | 2020-10-27 10:20:11 -0500 | [diff] [blame] | 19 | #include "power_off_action.hpp" |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 20 | #include "trust_group.hpp" |
| 21 | #include "types.hpp" |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 22 | |
| 23 | #include <nlohmann/json.hpp> |
| 24 | #include <sdbusplus/bus.hpp> |
| 25 | |
| 26 | namespace phosphor::fan::monitor |
| 27 | { |
| 28 | |
| 29 | using json = nlohmann::json; |
Matt Spinler | f06ab07 | 2020-10-14 12:58:22 -0500 | [diff] [blame] | 30 | class PowerOffRule; |
| 31 | class PowerInterfaceBase; |
Matt Spinler | ac1efc1 | 2020-10-27 10:20:11 -0500 | [diff] [blame] | 32 | class System; |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 33 | |
| 34 | constexpr auto confAppName = "monitor"; |
| 35 | constexpr auto confFileName = "config.json"; |
| 36 | |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 37 | // Trust group class handler function |
| 38 | using trustHandler = std::function<CreateGroupFunction( |
| 39 | const std::vector<trust::GroupDefinition>&)>; |
Matthew Barth | 3ad1434 | 2020-06-08 16:17:42 -0500 | [diff] [blame] | 40 | // Fan monitoring condition handler function |
| 41 | using condHandler = std::function<Condition(const json&)>; |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 42 | |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 43 | /** |
| 44 | * @brief Get the JSON object |
| 45 | * |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 46 | * @return JSON object |
| 47 | * A JSON object created after loading the JSON configuration file |
| 48 | */ |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame] | 49 | inline const json getJsonObj() |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 50 | { |
| 51 | return fan::JsonConfig::load( |
Mike Capps | 808d7fe | 2022-06-13 10:12:16 -0400 | [diff] [blame] | 52 | fan::JsonConfig::getConfFile(confAppName, confFileName)); |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Matthew Barth | 9ea8bee | 2020-06-04 14:27:19 -0500 | [diff] [blame] | 55 | /** |
| 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 | */ |
| 62 | const std::vector<CreateGroupFunction> getTrustGrps(const json& obj); |
| 63 | |
Matthew Barth | 22ab93b | 2020-06-08 10:47:56 -0500 | [diff] [blame] | 64 | /** |
| 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 | */ |
| 71 | const 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 | */ |
| 80 | const std::vector<FanDefinition> getFanDefs(const json& obj); |
| 81 | |
Matt Spinler | f06ab07 | 2020-10-14 12:58:22 -0500 | [diff] [blame] | 82 | /** |
| 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 | * |
Matt Spinler | ac1efc1 | 2020-10-27 10:20:11 -0500 | [diff] [blame] | 89 | * @param[in] func - Optional user defined function that gets called |
| 90 | * right before a power off occurs. |
| 91 | * |
Matt Spinler | f06ab07 | 2020-10-14 12:58:22 -0500 | [diff] [blame] | 92 | * @return std::vector<std::unique_ptr<PowerOffRule>> - |
| 93 | * The PowerOffRule objects |
| 94 | */ |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 95 | std::vector<std::unique_ptr<PowerOffRule>> getPowerOffRules( |
| 96 | const json& obj, std::shared_ptr<PowerInterfaceBase>& powerInterface, |
| 97 | PowerOffAction::PrePowerOffFunc& func); |
Matt Spinler | f06ab07 | 2020-10-14 12:58:22 -0500 | [diff] [blame] | 98 | |
Matt Spinler | f13b42e | 2020-10-26 15:29:49 -0500 | [diff] [blame] | 99 | /** |
| 100 | * @brief Returns the 'num_nonfunc_rotors_before_error field |
| 101 | * |
| 102 | * @param[in] obj - JSON object to parse from |
| 103 | * |
| 104 | * @return optional<size_t> - The value, or std::nullopt if not present |
| 105 | */ |
| 106 | std::optional<size_t> getNumNonfuncRotorsBeforeError(const json& obj); |
| 107 | |
Matthew Barth | ccaf2db | 2020-06-04 13:09:35 -0500 | [diff] [blame] | 108 | } // namespace phosphor::fan::monitor |