blob: 1be7fdd77ff0a13cb9101a9af96ca067841983e0 [file] [log] [blame]
Matthew Barth93341e02021-04-14 13:56:28 -05001/**
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
21#include <nlohmann/json.hpp>
22
23#include <chrono>
24
25namespace phosphor::fan::control::json::trigger::timer
26{
27
28using json = nlohmann::json;
29
30/**
31 * @brief Parse and return the timer trigger's type
32 *
33 * @param[in] jsonObj - JSON object for the timer trigger
34 *
35 * Gets the type of this timer
36 */
37TimerType getType(const json& jsonObj);
38
39/**
40 * @brief Parse and return the timer's interval
41 *
42 * @param[in] jsonObj - JSON object for the timer trigger
43 *
44 * Gets the interval of this timer
45 */
46std::chrono::microseconds getInterval(const json& jsonObj);
47
48/**
49 * @brief Trigger to run an event based on a timer
50 *
51 * @param[in] jsonObj - JSON object for the trigger
52 * @param[in] eventName - Name of event creating the trigger
53 * @param[in] mgr - Manager to setup the trigger on
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 */
60void triggerTimer(const json& jsonObj, const std::string& eventName,
61 Manager* mgr,
62 std::vector<std::unique_ptr<ActionBase>>& actions);
63
64} // namespace phosphor::fan::control::json::trigger::timer