blob: 30e9d0201566845db77ba6ad6e1843a6718a5299 [file] [log] [blame]
/**
* Copyright © 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "json_config.hpp"
#include "power_off_action.hpp"
#include "trust_group.hpp"
#include "types.hpp"
#include <nlohmann/json.hpp>
#include <sdbusplus/bus.hpp>
namespace phosphor::fan::monitor
{
using json = nlohmann::json;
class PowerOffRule;
class PowerInterfaceBase;
class System;
constexpr auto confAppName = "monitor";
constexpr auto confFileName = "config.json";
// Trust group class handler function
using trustHandler = std::function<CreateGroupFunction(
const std::vector<trust::GroupDefinition>&)>;
// Fan monitoring condition handler function
using condHandler = std::function<Condition(const json&)>;
/**
* @brief Get the JSON object
*
* @return JSON object
* A JSON object created after loading the JSON configuration file
*/
inline const json getJsonObj()
{
return fan::JsonConfig::load(
fan::JsonConfig::getConfFile(confAppName, confFileName));
}
/**
* @brief Get any configured trust groups
*
* @param[in] obj - JSON object to parse from
*
* @return List of functions applied on trust groups
*/
const std::vector<CreateGroupFunction> getTrustGrps(const json& obj);
/**
* @brief Get the configured sensor definitions that make up a fan
*
* @param[in] sensor - JSON object containing a list of sensors
*
* @return List of sensor definition data that make up a fan being monitored
*/
const std::vector<SensorDefinition> getSensorDefs(const json& sensors);
/**
* @brief Get the configured fan definitions to be monitored
*
* @param[in] obj - JSON object to parse from
*
* @return List of fan definition data on the fans to be monitored
*/
const std::vector<FanDefinition> getFanDefs(const json& obj);
/**
* @brief Get the configured power off rules
*
* @param[in] obj - JSON object to parse from
*
* @param[in] powerInterface - The power interface object to use
*
* @param[in] func - Optional user defined function that gets called
* right before a power off occurs.
*
* @return std::vector<std::unique_ptr<PowerOffRule>> -
* The PowerOffRule objects
*/
std::vector<std::unique_ptr<PowerOffRule>> getPowerOffRules(
const json& obj, std::shared_ptr<PowerInterfaceBase>& powerInterface,
PowerOffAction::PrePowerOffFunc& func);
/**
* @brief Returns the 'num_nonfunc_rotors_before_error field
*
* @param[in] obj - JSON object to parse from
*
* @return optional<size_t> - The value, or std::nullopt if not present
*/
std::optional<size_t> getNumNonfuncRotorsBeforeError(const json& obj);
} // namespace phosphor::fan::monitor