1*e8441c69SMatthew Barth /** 2*e8441c69SMatthew Barth * Copyright © 2021 IBM Corporation 3*e8441c69SMatthew Barth * 4*e8441c69SMatthew Barth * Licensed under the Apache License, Version 2.0 (the "License"); 5*e8441c69SMatthew Barth * you may not use this file except in compliance with the License. 6*e8441c69SMatthew Barth * You may obtain a copy of the License at 7*e8441c69SMatthew Barth * 8*e8441c69SMatthew Barth * http://www.apache.org/licenses/LICENSE-2.0 9*e8441c69SMatthew Barth * 10*e8441c69SMatthew Barth * Unless required by applicable law or agreed to in writing, software 11*e8441c69SMatthew Barth * distributed under the License is distributed on an "AS IS" BASIS, 12*e8441c69SMatthew Barth * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e8441c69SMatthew Barth * See the License for the specific language governing permissions and 14*e8441c69SMatthew Barth * limitations under the License. 15*e8441c69SMatthew Barth */ 16*e8441c69SMatthew Barth #pragma once 17*e8441c69SMatthew Barth 18*e8441c69SMatthew Barth #include "../manager.hpp" 19*e8441c69SMatthew Barth #include "action.hpp" 20*e8441c69SMatthew Barth #include "group.hpp" 21*e8441c69SMatthew Barth 22*e8441c69SMatthew Barth #include <nlohmann/json.hpp> 23*e8441c69SMatthew Barth 24*e8441c69SMatthew Barth #include <functional> 25*e8441c69SMatthew Barth #include <map> 26*e8441c69SMatthew Barth #include <memory> 27*e8441c69SMatthew Barth #include <vector> 28*e8441c69SMatthew Barth 29*e8441c69SMatthew Barth namespace phosphor::fan::control::json::trigger::init 30*e8441c69SMatthew Barth { 31*e8441c69SMatthew Barth 32*e8441c69SMatthew Barth using json = nlohmann::json; 33*e8441c69SMatthew Barth 34*e8441c69SMatthew Barth /** 35*e8441c69SMatthew Barth * @brief An init method to get properties used in an event 36*e8441c69SMatthew Barth * 37*e8441c69SMatthew Barth * @param[in] mgr - Pointer to manager of the event 38*e8441c69SMatthew Barth * @param[in] group - Group associated with the event 39*e8441c69SMatthew Barth */ 40*e8441c69SMatthew Barth void getProperties(Manager* mgr, const Group& group); 41*e8441c69SMatthew Barth 42*e8441c69SMatthew Barth /** 43*e8441c69SMatthew Barth * @brief An init method to get the owner name of a service used in an event 44*e8441c69SMatthew Barth * 45*e8441c69SMatthew Barth * @param[in] mgr - Pointer to manager of the event 46*e8441c69SMatthew Barth * @param[in] group - Group associated with the event 47*e8441c69SMatthew Barth */ 48*e8441c69SMatthew Barth void nameHasOwner(Manager* mgr, const Group& group); 49*e8441c69SMatthew Barth 50*e8441c69SMatthew Barth // Handler function for method calls 51*e8441c69SMatthew Barth using methodHandler = std::function<void(Manager*, const Group&)>; 52*e8441c69SMatthew Barth 53*e8441c69SMatthew Barth /* Supported methods to their corresponding handler functions */ 54*e8441c69SMatthew Barth static const std::map<std::string, methodHandler> methods = { 55*e8441c69SMatthew Barth {"get_properties", getProperties}, {"name_has_owner", nameHasOwner}}; 56*e8441c69SMatthew Barth 57*e8441c69SMatthew Barth /** 58*e8441c69SMatthew Barth * @brief Trigger to process an event immediately upon fan control starting 59*e8441c69SMatthew Barth * 60*e8441c69SMatthew Barth * @param[in] jsonObj - JSON object for the trigger 61*e8441c69SMatthew Barth * @param[in] eventName - Name of event creating the trigger 62*e8441c69SMatthew Barth * @param[in] mgr - Manager to setup the trigger on 63*e8441c69SMatthew Barth * @param[in] actions - Actions associated with the trigger 64*e8441c69SMatthew Barth * 65*e8441c69SMatthew Barth * When fan control starts (or restarts), all events with 'init' triggers are 66*e8441c69SMatthew Barth * processed immediately, per its configuration, and its corresponding actions 67*e8441c69SMatthew Barth * are run. 68*e8441c69SMatthew Barth * 69*e8441c69SMatthew Barth * Generally, this type of trigger is paired with a 'signal' class of trigger on 70*e8441c69SMatthew Barth * an event so the initial data for an event is collected, processed, and run 71*e8441c69SMatthew Barth * before any signal may be received. 72*e8441c69SMatthew Barth */ 73*e8441c69SMatthew Barth void triggerInit(const json& jsonObj, const std::string& eventName, 74*e8441c69SMatthew Barth Manager* mgr, 75*e8441c69SMatthew Barth std::vector<std::unique_ptr<ActionBase>>& actions); 76*e8441c69SMatthew Barth 77*e8441c69SMatthew Barth } // namespace phosphor::fan::control::json::trigger::init 78