xref: /openbmc/phosphor-fan-presence/control/json/triggers/parameter.cpp (revision 64b5ac203518568ec8b7569d0e785352278f2472)
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 <phosphor-logging/lg2.hpp>
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         lg2::error(
34             "Event '{EVENT_NAME}' parameter trigger is missing 'parameter'",
35             "EVENT_NAME", eventName);
36         throw std::runtime_error(
37             "Event parameter trigger is missing 'parameter'");
38     }
39 
40     auto name = jsonObj["parameter"].get<std::string>();
41 
42     return [name](const std::string& /*eventName*/, Manager* /*mgr*/,
43                   const std::vector<Group>& /*groups*/,
44                   std::vector<std::unique_ptr<ActionBase>>& actions) {
45         Manager::addParameterTrigger(name, actions);
46     };
47 }
48 
49 } // namespace phosphor::fan::control::json::trigger::parameter
50