blob: b1b80a517efca2ac439dee4caa2fe69a1e997742 [file] [log] [blame]
Matthew Barthc95c5272020-06-15 19:51:13 -05001/**
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"
Matt Spinlere892e392020-10-14 13:21:31 -050019#include "power_off_rule.hpp"
20#include "power_state.hpp"
Matthew Barthc95c5272020-06-15 19:51:13 -050021#include "tach_sensor.hpp"
22#include "trust_manager.hpp"
23#include "types.hpp"
24
25#include <nlohmann/json.hpp>
26#include <sdbusplus/bus.hpp>
27#include <sdeventplus/event.hpp>
Matthew Barthd06905c2020-06-12 08:13:06 -050028#include <sdeventplus/source/signal.hpp>
Matthew Barthc95c5272020-06-15 19:51:13 -050029
30#include <memory>
31#include <optional>
32#include <vector>
33
34namespace phosphor::fan::monitor
35{
36
37using json = nlohmann::json;
38
39class System
40{
41 public:
42 System() = delete;
43 System(const System&) = delete;
44 System(System&&) = delete;
45 System& operator=(const System&) = delete;
46 System& operator=(System&&) = delete;
47 ~System() = default;
48
49 /**
50 * Constructor
51 * Parses and populates the fan monitor trust groups and list of fans
52 *
53 * @param[in] mode - mode of fan monitor
54 * @param[in] bus - sdbusplus bus object
55 * @param[in] event - event loop reference
56 */
57 System(Mode mode, sdbusplus::bus::bus& bus,
58 const sdeventplus::Event& event);
59
Matthew Barthd06905c2020-06-12 08:13:06 -050060 /**
61 * @brief Callback function to handle receiving a HUP signal to reload the
62 * JSON configuration.
63 */
64 void sighupHandler(sdeventplus::source::Signal&,
65 const struct signalfd_siginfo*);
66
Matt Spinlerb63aa092020-10-14 09:45:11 -050067 /**
68 * @brief Called from the fan when it changes either
69 * present or functional status to update the
70 * fan health map.
71 *
72 * @param[in] fan - The fan that changed
73 */
74 void fanStatusChange(const Fan& fan);
75
Matthew Barthc95c5272020-06-15 19:51:13 -050076 private:
77 /* The mode of fan monitor */
78 Mode _mode;
79
80 /* The sdbusplus bus object */
81 sdbusplus::bus::bus& _bus;
82
83 /* The event loop reference */
84 const sdeventplus::Event& _event;
85
86 /* Trust manager of trust groups */
87 std::unique_ptr<phosphor::fan::trust::Manager> _trust;
88
89 /* List of fan objects to monitor */
90 std::vector<std::unique_ptr<Fan>> _fans;
91
92 /**
Matt Spinlerb63aa092020-10-14 09:45:11 -050093 * @brief The latest health of all the fans
94 */
95 FanHealth _fanHealth;
96
97 /**
Matt Spinlere892e392020-10-14 13:21:31 -050098 * @brief The object to watch the power state
99 */
100 std::unique_ptr<PowerState> _powerState;
101
102 /**
103 * @brief The power off rules, for shutting down the system
104 * due to fan failures.
105 */
106 std::vector<std::unique_ptr<PowerOffRule>> _powerOffRules;
107
108 /**
Matthew Barthc95c5272020-06-15 19:51:13 -0500109 * @brief Retrieve the configured trust groups
110 *
111 * @param[in] jsonObj - JSON object to parse from
112 *
113 * @return List of functions applied on trust groups
114 */
115 const std::vector<CreateGroupFunction> getTrustGroups(const json& jsonObj);
116
117 /**
Matthew Barthd06905c2020-06-12 08:13:06 -0500118 * @brief Set the trust manager's list of trust group functions
119 *
120 * @param[in] groupFuncs - list of trust group functions
121 */
122 void setTrustMgr(const std::vector<CreateGroupFunction>& groupFuncs);
123
124 /**
Matthew Barthc95c5272020-06-15 19:51:13 -0500125 * @brief Retrieve the configured fan definitions
126 *
127 * @param[in] jsonObj - JSON object to parse from
128 *
129 * @return List of fan definition data on the fans configured
130 */
131 const std::vector<FanDefinition> getFanDefinitions(const json& jsonObj);
Matthew Barthd06905c2020-06-12 08:13:06 -0500132
133 /**
134 * @brief Set the list of fans to be monitored
135 *
136 * @param[in] fanDefs - list of fan definitions to create fans monitored
137 */
138 void setFans(const std::vector<FanDefinition>& fanDefs);
Matt Spinlerb63aa092020-10-14 09:45:11 -0500139
140 /**
141 * @brief Updates the fan health map entry for the fan passed in
142 *
143 * @param[in] fan - The fan to update the health map with
144 */
145 void updateFanHealth(const Fan& fan);
Matt Spinlere892e392020-10-14 13:21:31 -0500146
147 /**
148 * @brief The function that runs when the power state changes
149 *
150 * @param[in] powerStateOn - If power is now on or not
151 */
152 void powerStateChanged(bool powerStateOn);
153
154 /**
155 * @brief Reads the fault configuration from the JSON config
156 * file, such as the power off rule configuration.
157 *
158 * @param[in] jsonObj - JSON object to parse from
159 */
160 void setFaultConfig(const json& jsonObj);
Matthew Barthc95c5272020-06-15 19:51:13 -0500161};
162
163} // namespace phosphor::fan::monitor