1 /**
2  * Copyright © 2021 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 "../manager.hpp"
19 #include "action.hpp"
20 #include "trigger_aliases.hpp"
21 
22 #include <nlohmann/json.hpp>
23 
24 #include <chrono>
25 
26 namespace phosphor::fan::control::json::trigger::timer
27 {
28 
29 using json = nlohmann::json;
30 
31 /**
32  * @brief Parse and return the timer trigger's type
33  *
34  * @param[in] jsonObj - JSON object for the timer trigger
35  *
36  * Gets the type of this timer
37  */
38 TimerType getType(const json& jsonObj);
39 
40 /**
41  * @brief Parse and return the timer's interval
42  *
43  * @param[in] jsonObj - JSON object for the timer trigger
44  *
45  * Gets the interval of this timer
46  */
47 std::chrono::microseconds getInterval(const json& jsonObj);
48 
49 /**
50  * @brief Trigger to run an event based on a timer
51  *
52  * @param[in] jsonObj - JSON object for the trigger
53  * @param[in] eventName - Name of event creating the trigger
54  * @param[in] actions - Actions associated with the trigger
55  *
56  * When fan control starts (or restarts), all events with 'timer' triggers
57  * have their timers started. Once the timer expires, per its configuration,
58  * the corresponding event's actions are run.
59  */
60 enableTrigger triggerTimer(const json& jsonObj, const std::string& eventName,
61                            std::vector<std::unique_ptr<ActionBase>>& actions);
62 
63 } // namespace phosphor::fan::control::json::trigger::timer
64