1ccaf2db9SMatthew Barth /** 2ccaf2db9SMatthew Barth * Copyright © 2020 IBM Corporation 3ccaf2db9SMatthew Barth * 4ccaf2db9SMatthew Barth * Licensed under the Apache License, Version 2.0 (the "License"); 5ccaf2db9SMatthew Barth * you may not use this file except in compliance with the License. 6ccaf2db9SMatthew Barth * You may obtain a copy of the License at 7ccaf2db9SMatthew Barth * 8ccaf2db9SMatthew Barth * http://www.apache.org/licenses/LICENSE-2.0 9ccaf2db9SMatthew Barth * 10ccaf2db9SMatthew Barth * Unless required by applicable law or agreed to in writing, software 11ccaf2db9SMatthew Barth * distributed under the License is distributed on an "AS IS" BASIS, 12ccaf2db9SMatthew Barth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ccaf2db9SMatthew Barth * See the License for the specific language governing permissions and 14ccaf2db9SMatthew Barth * limitations under the License. 15ccaf2db9SMatthew Barth */ 16ccaf2db9SMatthew Barth #pragma once 17ccaf2db9SMatthew Barth 18ccaf2db9SMatthew Barth #include "json_config.hpp" 19*ac1efc11SMatt Spinler #include "power_off_action.hpp" 209ea8bee7SMatthew Barth #include "trust_group.hpp" 219ea8bee7SMatthew Barth #include "types.hpp" 22ccaf2db9SMatthew Barth 23ccaf2db9SMatthew Barth #include <nlohmann/json.hpp> 24ccaf2db9SMatthew Barth #include <sdbusplus/bus.hpp> 25ccaf2db9SMatthew Barth 26ccaf2db9SMatthew Barth namespace phosphor::fan::monitor 27ccaf2db9SMatthew Barth { 28ccaf2db9SMatthew Barth 29ccaf2db9SMatthew Barth using json = nlohmann::json; 30f06ab07cSMatt Spinler class PowerOffRule; 31f06ab07cSMatt Spinler class PowerInterfaceBase; 32*ac1efc11SMatt Spinler class System; 33ccaf2db9SMatthew Barth 34ccaf2db9SMatthew Barth constexpr auto confAppName = "monitor"; 35ccaf2db9SMatthew Barth constexpr auto confFileName = "config.json"; 36ccaf2db9SMatthew Barth 379ea8bee7SMatthew Barth // Trust group class handler function 389ea8bee7SMatthew Barth using trustHandler = std::function<CreateGroupFunction( 399ea8bee7SMatthew Barth const std::vector<trust::GroupDefinition>&)>; 403ad14346SMatthew Barth // Fan monitoring condition handler function 413ad14346SMatthew Barth using condHandler = std::function<Condition(const json&)>; 429ea8bee7SMatthew Barth 43ccaf2db9SMatthew Barth /** 44ccaf2db9SMatthew Barth * @brief Get the JSON object 45ccaf2db9SMatthew Barth * 46ccaf2db9SMatthew Barth * @param[in] bus - The dbus bus object 47ccaf2db9SMatthew Barth * 48ccaf2db9SMatthew Barth * @return JSON object 49ccaf2db9SMatthew Barth * A JSON object created after loading the JSON configuration file 50ccaf2db9SMatthew Barth */ 51ccaf2db9SMatthew Barth inline const json getJsonObj(sdbusplus::bus::bus& bus) 52ccaf2db9SMatthew Barth { 53ccaf2db9SMatthew Barth return fan::JsonConfig::load( 54ccaf2db9SMatthew Barth fan::JsonConfig::getConfFile(bus, confAppName, confFileName)); 55ccaf2db9SMatthew Barth } 56ccaf2db9SMatthew Barth 579ea8bee7SMatthew Barth /** 589ea8bee7SMatthew Barth * @brief Get any configured trust groups 599ea8bee7SMatthew Barth * 609ea8bee7SMatthew Barth * @param[in] obj - JSON object to parse from 619ea8bee7SMatthew Barth * 629ea8bee7SMatthew Barth * @return List of functions applied on trust groups 639ea8bee7SMatthew Barth */ 649ea8bee7SMatthew Barth const std::vector<CreateGroupFunction> getTrustGrps(const json& obj); 659ea8bee7SMatthew Barth 6622ab93b4SMatthew Barth /** 6722ab93b4SMatthew Barth * @brief Get the configured sensor definitions that make up a fan 6822ab93b4SMatthew Barth * 6922ab93b4SMatthew Barth * @param[in] sensor - JSON object containing a list of sensors 7022ab93b4SMatthew Barth * 7122ab93b4SMatthew Barth * @return List of sensor definition data that make up a fan being monitored 7222ab93b4SMatthew Barth */ 7322ab93b4SMatthew Barth const std::vector<SensorDefinition> getSensorDefs(const json& sensors); 7422ab93b4SMatthew Barth 7522ab93b4SMatthew Barth /** 7622ab93b4SMatthew Barth * @brief Get the configured fan definitions to be monitored 7722ab93b4SMatthew Barth * 7822ab93b4SMatthew Barth * @param[in] obj - JSON object to parse from 7922ab93b4SMatthew Barth * 8022ab93b4SMatthew Barth * @return List of fan definition data on the fans to be monitored 8122ab93b4SMatthew Barth */ 8222ab93b4SMatthew Barth const std::vector<FanDefinition> getFanDefs(const json& obj); 8322ab93b4SMatthew Barth 84f06ab07cSMatt Spinler /** 85f06ab07cSMatt Spinler * @brief Get the configured power off rules 86f06ab07cSMatt Spinler * 87f06ab07cSMatt Spinler * @param[in] obj - JSON object to parse from 88f06ab07cSMatt Spinler * 89f06ab07cSMatt Spinler * @param[in] powerInterface - The power interface object to use 90f06ab07cSMatt Spinler * 91*ac1efc11SMatt Spinler * @param[in] func - Optional user defined function that gets called 92*ac1efc11SMatt Spinler * right before a power off occurs. 93*ac1efc11SMatt Spinler * 94f06ab07cSMatt Spinler * @return std::vector<std::unique_ptr<PowerOffRule>> - 95f06ab07cSMatt Spinler * The PowerOffRule objects 96f06ab07cSMatt Spinler */ 97f06ab07cSMatt Spinler std::vector<std::unique_ptr<PowerOffRule>> 98f06ab07cSMatt Spinler getPowerOffRules(const json& obj, 99*ac1efc11SMatt Spinler std::shared_ptr<PowerInterfaceBase>& powerInterface, 100*ac1efc11SMatt Spinler PowerOffAction::PrePowerOffFunc& func); 101f06ab07cSMatt Spinler 102f13b42e2SMatt Spinler /** 103f13b42e2SMatt Spinler * @brief Returns the 'num_nonfunc_rotors_before_error field 104f13b42e2SMatt Spinler * 105f13b42e2SMatt Spinler * @param[in] obj - JSON object to parse from 106f13b42e2SMatt Spinler * 107f13b42e2SMatt Spinler * @return optional<size_t> - The value, or std::nullopt if not present 108f13b42e2SMatt Spinler */ 109f13b42e2SMatt Spinler std::optional<size_t> getNumNonfuncRotorsBeforeError(const json& obj); 110f13b42e2SMatt Spinler 111ccaf2db9SMatthew Barth } // namespace phosphor::fan::monitor 112