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 "fan.hpp" 19 #include "tach_sensor.hpp" 20 #include "trust_manager.hpp" 21 #include "types.hpp" 22 23 #include <nlohmann/json.hpp> 24 #include <sdbusplus/bus.hpp> 25 #include <sdeventplus/event.hpp> 26 #include <sdeventplus/source/signal.hpp> 27 28 #include <memory> 29 #include <optional> 30 #include <vector> 31 32 namespace phosphor::fan::monitor 33 { 34 35 using json = nlohmann::json; 36 37 class System 38 { 39 public: 40 System() = delete; 41 System(const System&) = delete; 42 System(System&&) = delete; 43 System& operator=(const System&) = delete; 44 System& operator=(System&&) = delete; 45 ~System() = default; 46 47 /** 48 * Constructor 49 * Parses and populates the fan monitor trust groups and list of fans 50 * 51 * @param[in] mode - mode of fan monitor 52 * @param[in] bus - sdbusplus bus object 53 * @param[in] event - event loop reference 54 */ 55 System(Mode mode, sdbusplus::bus::bus& bus, 56 const sdeventplus::Event& event); 57 58 /** 59 * @brief Callback function to handle receiving a HUP signal to reload the 60 * JSON configuration. 61 */ 62 void sighupHandler(sdeventplus::source::Signal&, 63 const struct signalfd_siginfo*); 64 65 private: 66 /* The mode of fan monitor */ 67 Mode _mode; 68 69 /* The sdbusplus bus object */ 70 sdbusplus::bus::bus& _bus; 71 72 /* The event loop reference */ 73 const sdeventplus::Event& _event; 74 75 /* Trust manager of trust groups */ 76 std::unique_ptr<phosphor::fan::trust::Manager> _trust; 77 78 /* List of fan objects to monitor */ 79 std::vector<std::unique_ptr<Fan>> _fans; 80 81 /** 82 * @brief Retrieve the configured trust groups 83 * 84 * @param[in] jsonObj - JSON object to parse from 85 * 86 * @return List of functions applied on trust groups 87 */ 88 const std::vector<CreateGroupFunction> getTrustGroups(const json& jsonObj); 89 90 /** 91 * @brief Set the trust manager's list of trust group functions 92 * 93 * @param[in] groupFuncs - list of trust group functions 94 */ 95 void setTrustMgr(const std::vector<CreateGroupFunction>& groupFuncs); 96 97 /** 98 * @brief Retrieve the configured fan definitions 99 * 100 * @param[in] jsonObj - JSON object to parse from 101 * 102 * @return List of fan definition data on the fans configured 103 */ 104 const std::vector<FanDefinition> getFanDefinitions(const json& jsonObj); 105 106 /** 107 * @brief Set the list of fans to be monitored 108 * 109 * @param[in] fanDefs - list of fan definitions to create fans monitored 110 */ 111 void setFans(const std::vector<FanDefinition>& fanDefs); 112 }; 113 114 } // namespace phosphor::fan::monitor 115