1 /**
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 #include "parameter.hpp"
17
18 #include "../manager.hpp"
19
20 #include <format>
21
22 namespace phosphor::fan::control::json::trigger::parameter
23 {
24
25 using json = nlohmann::json;
26
triggerParameter(const json & jsonObj,const std::string & eventName,std::vector<std::unique_ptr<ActionBase>> &)27 enableTrigger triggerParameter(
28 const json& jsonObj, const std::string& eventName,
29 std::vector<std::unique_ptr<ActionBase>>& /*actions*/)
30 {
31 if (!jsonObj.contains("parameter"))
32 {
33 auto msg = std::format(
34 "Event '{}' parameter trigger is missing 'parameter'", eventName);
35 log<level::ERR>(msg.c_str());
36 throw std::runtime_error(msg);
37 }
38
39 auto name = jsonObj["parameter"].get<std::string>();
40
41 return [name](const std::string& /*eventName*/, Manager* /*mgr*/,
42 const std::vector<Group>& /*groups*/,
43 std::vector<std::unique_ptr<ActionBase>>& actions) {
44 Manager::addParameterTrigger(name, actions);
45 };
46 }
47
48 } // namespace phosphor::fan::control::json::trigger::parameter
49