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 #include "error_reporter.hpp"
17 
18 #include <phosphor-logging/log.hpp>
19 
20 namespace phosphor::fan::presence
21 {
22 
23 using json = nlohmann::json;
24 using namespace phosphor::logging;
25 
26 ErrorReporter::ErrorReporter(
27     sdbusplus::bus::bus& bus, const json& jsonConf,
28     const std::vector<
29         std::tuple<Fan, std::vector<std::unique_ptr<PresenceSensor>>>>& fans) :
30     _bus(bus)
31 {
32     loadConfig(jsonConf);
33 }
34 
35 void ErrorReporter::loadConfig(const json& jsonConf)
36 {
37     if (!jsonConf.contains("fan_missing_error_time"))
38     {
39         log<level::ERR>("Missing 'fan_missing_error_time' entry in JSON "
40                         "'reporting' section");
41 
42         throw std::runtime_error("Missing fan missing time entry in JSON");
43     }
44 
45     _fanMissingErrorTime = std::chrono::seconds{
46         jsonConf.at("fan_missing_error_time").get<std::size_t>()};
47 }
48 
49 } // namespace phosphor::fan::presence
50