blob: 6986608cf40ee60ef43216ba0663c1027e6740b8 [file] [log] [blame]
Matt Spinlerd0ba86a2021-11-09 10:09:13 -06001/**
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
Patrick Williamsfbf47032023-07-17 12:27:34 -050020#include <format>
Matt Spinlerd0ba86a2021-11-09 10:09:13 -060021
22namespace phosphor::fan::control::json::trigger::parameter
23{
24
25using json = nlohmann::json;
26
27enableTrigger
28 triggerParameter(const json& jsonObj, const std::string& eventName,
Mike Cappsb2e9a4f2022-06-13 10:15:42 -040029 std::vector<std::unique_ptr<ActionBase>>& /*actions*/)
Matt Spinlerd0ba86a2021-11-09 10:09:13 -060030{
31 if (!jsonObj.contains("parameter"))
32 {
Patrick Williamsfbf47032023-07-17 12:27:34 -050033 auto msg = std::format(
Matt Spinlerd0ba86a2021-11-09 10:09:13 -060034 "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
Mike Cappsb2e9a4f2022-06-13 10:15:42 -040041 return [name](const std::string& /*eventName*/, Manager* /*mgr*/,
42 const std::vector<Group>& /*groups*/,
Matt Spinlerd0ba86a2021-11-09 10:09:13 -060043 std::vector<std::unique_ptr<ActionBase>>& actions) {
44 Manager::addParameterTrigger(name, actions);
45 };
46}
47
48} // namespace phosphor::fan::control::json::trigger::parameter