blob: 64474350cdf0977fbea3a9a99a89be780d3cccd0 [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"
21
22#include <nlohmann/json.hpp>
23
24#include <functional>
25#include <map>
26#include <memory>
27#include <vector>
28
29namespace phosphor::fan::control::json::trigger::init
30{
31
32using json = nlohmann::json;
33
34/**
35 * @brief An init method to get properties used in an event
36 *
37 * @param[in] mgr - Pointer to manager of the event
38 * @param[in] group - Group associated with the event
39 */
40void getProperties(Manager* mgr, const Group& group);
41
42/**
43 * @brief An init method to get the owner name of a service used in an event
44 *
45 * @param[in] mgr - Pointer to manager of the event
46 * @param[in] group - Group associated with the event
47 */
48void nameHasOwner(Manager* mgr, const Group& group);
49
50// Handler function for method calls
51using methodHandler = std::function<void(Manager*, const Group&)>;
52
53/* Supported methods to their corresponding handler functions */
54static const std::map<std::string, methodHandler> methods = {
55 {"get_properties", getProperties}, {"name_has_owner", nameHasOwner}};
56
57/**
58 * @brief Trigger to process an event immediately upon fan control starting
59 *
60 * @param[in] jsonObj - JSON object for the trigger
61 * @param[in] eventName - Name of event creating the trigger
62 * @param[in] mgr - Manager to setup the trigger on
63 * @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 */
73void triggerInit(const json& jsonObj, const std::string& eventName,
74 Manager* mgr,
75 std::vector<std::unique_ptr<ActionBase>>& actions);
76
77} // namespace phosphor::fan::control::json::trigger::init