blob: 7c424a2c00cb99453073892c1fa4639004be71f1 [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"
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>
Matthew Barthd06905c2020-06-12 08:13:06 -050026#include <sdeventplus/source/signal.hpp>
Matthew Barthc95c5272020-06-15 19:51:13 -050027
28#include <memory>
29#include <optional>
30#include <vector>
31
32namespace phosphor::fan::monitor
33{
34
35using json = nlohmann::json;
36
37class 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
Matthew Barthd06905c2020-06-12 08:13:06 -050058 /**
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
Matt Spinlerb63aa092020-10-14 09:45:11 -050065 /**
66 * @brief Called from the fan when it changes either
67 * present or functional status to update the
68 * fan health map.
69 *
70 * @param[in] fan - The fan that changed
71 */
72 void fanStatusChange(const Fan& fan);
73
Matthew Barthc95c5272020-06-15 19:51:13 -050074 private:
75 /* The mode of fan monitor */
76 Mode _mode;
77
78 /* The sdbusplus bus object */
79 sdbusplus::bus::bus& _bus;
80
81 /* The event loop reference */
82 const sdeventplus::Event& _event;
83
84 /* Trust manager of trust groups */
85 std::unique_ptr<phosphor::fan::trust::Manager> _trust;
86
87 /* List of fan objects to monitor */
88 std::vector<std::unique_ptr<Fan>> _fans;
89
90 /**
Matt Spinlerb63aa092020-10-14 09:45:11 -050091 * @brief The latest health of all the fans
92 */
93 FanHealth _fanHealth;
94
95 /**
Matthew Barthc95c5272020-06-15 19:51:13 -050096 * @brief Retrieve the configured trust groups
97 *
98 * @param[in] jsonObj - JSON object to parse from
99 *
100 * @return List of functions applied on trust groups
101 */
102 const std::vector<CreateGroupFunction> getTrustGroups(const json& jsonObj);
103
104 /**
Matthew Barthd06905c2020-06-12 08:13:06 -0500105 * @brief Set the trust manager's list of trust group functions
106 *
107 * @param[in] groupFuncs - list of trust group functions
108 */
109 void setTrustMgr(const std::vector<CreateGroupFunction>& groupFuncs);
110
111 /**
Matthew Barthc95c5272020-06-15 19:51:13 -0500112 * @brief Retrieve the configured fan definitions
113 *
114 * @param[in] jsonObj - JSON object to parse from
115 *
116 * @return List of fan definition data on the fans configured
117 */
118 const std::vector<FanDefinition> getFanDefinitions(const json& jsonObj);
Matthew Barthd06905c2020-06-12 08:13:06 -0500119
120 /**
121 * @brief Set the list of fans to be monitored
122 *
123 * @param[in] fanDefs - list of fan definitions to create fans monitored
124 */
125 void setFans(const std::vector<FanDefinition>& fanDefs);
Matt Spinlerb63aa092020-10-14 09:45:11 -0500126
127 /**
128 * @brief Updates the fan health map entry for the fan passed in
129 *
130 * @param[in] fan - The fan to update the health map with
131 */
132 void updateFanHealth(const Fan& fan);
Matthew Barthc95c5272020-06-15 19:51:13 -0500133};
134
135} // namespace phosphor::fan::monitor