1d0ba86a3SMatt Spinler /** 2d0ba86a3SMatt Spinler * Copyright © 2021 IBM Corporation 3d0ba86a3SMatt Spinler * 4d0ba86a3SMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License"); 5d0ba86a3SMatt Spinler * you may not use this file except in compliance with the License. 6d0ba86a3SMatt Spinler * You may obtain a copy of the License at 7d0ba86a3SMatt Spinler * 8d0ba86a3SMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0 9d0ba86a3SMatt Spinler * 10d0ba86a3SMatt Spinler * Unless required by applicable law or agreed to in writing, software 11d0ba86a3SMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS, 12d0ba86a3SMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d0ba86a3SMatt Spinler * See the License for the specific language governing permissions and 14d0ba86a3SMatt Spinler * limitations under the License. 15d0ba86a3SMatt Spinler */ 16d0ba86a3SMatt Spinler #include "parameter.hpp" 17d0ba86a3SMatt Spinler 18d0ba86a3SMatt Spinler #include "../manager.hpp" 19d0ba86a3SMatt Spinler 20*fbf4703fSPatrick Williams #include <format> 21d0ba86a3SMatt Spinler 22d0ba86a3SMatt Spinler namespace phosphor::fan::control::json::trigger::parameter 23d0ba86a3SMatt Spinler { 24d0ba86a3SMatt Spinler 25d0ba86a3SMatt Spinler using json = nlohmann::json; 26d0ba86a3SMatt Spinler 27d0ba86a3SMatt Spinler enableTrigger triggerParameter(const json & jsonObj,const std::string & eventName,std::vector<std::unique_ptr<ActionBase>> &)28d0ba86a3SMatt Spinler triggerParameter(const json& jsonObj, const std::string& eventName, 29b2e9a4fcSMike Capps std::vector<std::unique_ptr<ActionBase>>& /*actions*/) 30d0ba86a3SMatt Spinler { 31d0ba86a3SMatt Spinler if (!jsonObj.contains("parameter")) 32d0ba86a3SMatt Spinler { 33*fbf4703fSPatrick Williams auto msg = std::format( 34d0ba86a3SMatt Spinler "Event '{}' parameter trigger is missing 'parameter'", eventName); 35d0ba86a3SMatt Spinler log<level::ERR>(msg.c_str()); 36d0ba86a3SMatt Spinler throw std::runtime_error(msg); 37d0ba86a3SMatt Spinler } 38d0ba86a3SMatt Spinler 39d0ba86a3SMatt Spinler auto name = jsonObj["parameter"].get<std::string>(); 40d0ba86a3SMatt Spinler 41b2e9a4fcSMike Capps return [name](const std::string& /*eventName*/, Manager* /*mgr*/, 42b2e9a4fcSMike Capps const std::vector<Group>& /*groups*/, 43d0ba86a3SMatt Spinler std::vector<std::unique_ptr<ActionBase>>& actions) { 44d0ba86a3SMatt Spinler Manager::addParameterTrigger(name, actions); 45d0ba86a3SMatt Spinler }; 46d0ba86a3SMatt Spinler } 47d0ba86a3SMatt Spinler 48d0ba86a3SMatt Spinler } // namespace phosphor::fan::control::json::trigger::parameter 49