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