blob: 0bd43cb48b23a2e6858362b5b155affca33ad9a9 [file] [log] [blame]
Matthew Barthe8441c62021-05-13 16:50:56 -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#include "group.hpp"
Matthew Barth54b5a242021-05-21 11:02:52 -050021#include "trigger_aliases.hpp"
Matthew Barthe8441c62021-05-13 16:50:56 -050022
23#include <nlohmann/json.hpp>
24
25#include <functional>
26#include <map>
27#include <memory>
28#include <vector>
29
30namespace phosphor::fan::control::json::trigger::init
31{
32
33using json = nlohmann::json;
34
35/**
36 * @brief An init method to get properties used in an event
37 *
38 * @param[in] mgr - Pointer to manager of the event
39 * @param[in] group - Group associated with the event
40 */
41void getProperties(Manager* mgr, const Group& group);
42
43/**
44 * @brief An init method to get the owner name of a service used in an event
45 *
46 * @param[in] mgr - Pointer to manager of the event
47 * @param[in] group - Group associated with the event
48 */
49void nameHasOwner(Manager* mgr, const Group& group);
50
51// Handler function for method calls
52using methodHandler = std::function<void(Manager*, const Group&)>;
53
54/* Supported methods to their corresponding handler functions */
55static const std::map<std::string, methodHandler> methods = {
56 {"get_properties", getProperties}, {"name_has_owner", nameHasOwner}};
57
58/**
59 * @brief Trigger to process an event immediately upon fan control starting
60 *
61 * @param[in] jsonObj - JSON object for the trigger
62 * @param[in] eventName - Name of event creating the trigger
Matthew Barthe8441c62021-05-13 16:50:56 -050063 * @param[in] actions - Actions associated with the trigger
64 *
65 * When fan control starts (or restarts), all events with 'init' triggers are
66 * processed immediately, per its configuration, and its corresponding actions
67 * are run.
68 *
69 * Generally, this type of trigger is paired with a 'signal' class of trigger on
70 * an event so the initial data for an event is collected, processed, and run
71 * before any signal may be received.
72 */
Matthew Barth54b5a242021-05-21 11:02:52 -050073enableTrigger triggerInit(const json& jsonObj, const std::string& eventName,
Matthew Barth54b5a242021-05-21 11:02:52 -050074 std::vector<std::unique_ptr<ActionBase>>& actions);
Matthew Barthe8441c62021-05-13 16:50:56 -050075
76} // namespace phosphor::fan::control::json::trigger::init