| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 1 | /** | 
|  | 2 | * Copyright © 2020 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 "event.hpp" | 
|  | 17 |  | 
| Matthew Barth | 776ca56 | 2021-03-31 09:50:58 -0500 | [diff] [blame] | 18 | #include "action.hpp" | 
| Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 19 | #include "config_base.hpp" | 
| Matthew Barth | 391ade0 | 2021-01-15 14:33:21 -0600 | [diff] [blame] | 20 | #include "group.hpp" | 
| Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 21 | #include "manager.hpp" | 
| Matthew Barth | 9403a21 | 2021-05-17 09:31:50 -0500 | [diff] [blame] | 22 | #include "sdbusplus.hpp" | 
| Matthew Barth | 54b5a24 | 2021-05-21 11:02:52 -0500 | [diff] [blame] | 23 | #include "trigger.hpp" | 
| Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 24 |  | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 26 | #include <phosphor-logging/lg2.hpp> | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 27 | #include <sdbusplus/bus.hpp> | 
|  | 28 |  | 
| Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 29 | #include <algorithm> | 
| Matthew Barth | 12bae96 | 2021-01-15 16:18:11 -0600 | [diff] [blame] | 30 | #include <optional> | 
| Matthew Barth | 12bae96 | 2021-01-15 16:18:11 -0600 | [diff] [blame] | 31 |  | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 32 | namespace phosphor::fan::control::json | 
|  | 33 | { | 
|  | 34 |  | 
|  | 35 | using json = nlohmann::json; | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 36 |  | 
| Matthew Barth | 3695ac3 | 2021-10-06 14:55:30 -0500 | [diff] [blame] | 37 | std::map<configKey, std::unique_ptr<Group>> Event::allGroups; | 
|  | 38 |  | 
| Matthew Barth | 9403a21 | 2021-05-17 09:31:50 -0500 | [diff] [blame] | 39 | Event::Event(const json& jsonObj, Manager* mgr, | 
| Matthew Barth | 9f1632e | 2021-03-31 15:51:50 -0500 | [diff] [blame] | 40 | std::map<configKey, std::unique_ptr<Zone>>& zones) : | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 41 | ConfigBase(jsonObj), _bus(util::SDBusPlus::getBus()), _manager(mgr), | 
|  | 42 | _zones(zones) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 43 | { | 
| Matthew Barth | 619dc0f | 2021-05-20 09:27:02 -0500 | [diff] [blame] | 44 | // Event groups are optional | 
|  | 45 | if (jsonObj.contains("groups")) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 46 | { | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 47 | setGroups(jsonObj, _profiles, _groups); | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 48 | } | 
| Matthew Barth | 619dc0f | 2021-05-20 09:27:02 -0500 | [diff] [blame] | 49 | // Event actions are optional | 
|  | 50 | if (jsonObj.contains("actions")) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 51 | { | 
| Matthew Barth | 619dc0f | 2021-05-20 09:27:02 -0500 | [diff] [blame] | 52 | setActions(jsonObj); | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 53 | } | 
| Matthew Barth | 619dc0f | 2021-05-20 09:27:02 -0500 | [diff] [blame] | 54 | setTriggers(jsonObj); | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
| Matthew Barth | 54b5a24 | 2021-05-21 11:02:52 -0500 | [diff] [blame] | 57 | void Event::enable() | 
|  | 58 | { | 
| Matt Spinler | d1f97f4 | 2021-10-29 16:19:24 -0500 | [diff] [blame] | 59 | for (const auto& [type, trigger] : _triggers) | 
| Matthew Barth | 54b5a24 | 2021-05-21 11:02:52 -0500 | [diff] [blame] | 60 | { | 
| Matt Spinler | d1f97f4 | 2021-10-29 16:19:24 -0500 | [diff] [blame] | 61 | // Don't call the powerOn or powerOff triggers | 
|  | 62 | if (type.find("power") == std::string::npos) | 
|  | 63 | { | 
|  | 64 | trigger(getName(), _manager, _groups, _actions); | 
|  | 65 | } | 
|  | 66 | } | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | void Event::powerOn() | 
|  | 70 | { | 
|  | 71 | for (const auto& [type, trigger] : _triggers) | 
|  | 72 | { | 
|  | 73 | if (type == "poweron") | 
|  | 74 | { | 
|  | 75 | trigger(getName(), _manager, _groups, _actions); | 
|  | 76 | } | 
|  | 77 | } | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | void Event::powerOff() | 
|  | 81 | { | 
|  | 82 | for (const auto& [type, trigger] : _triggers) | 
|  | 83 | { | 
|  | 84 | if (type == "poweroff") | 
|  | 85 | { | 
|  | 86 | trigger(getName(), _manager, _groups, _actions); | 
|  | 87 | } | 
| Matthew Barth | 54b5a24 | 2021-05-21 11:02:52 -0500 | [diff] [blame] | 88 | } | 
|  | 89 | } | 
|  | 90 |  | 
| Patrick Williams | 4fa67aa | 2025-02-03 14:28:47 -0500 | [diff] [blame] | 91 | std::map<configKey, std::unique_ptr<Group>>& Event::getAllGroups( | 
|  | 92 | bool loadGroups) | 
| Matthew Barth | c8bde4a | 2021-05-19 15:34:49 -0500 | [diff] [blame] | 93 | { | 
| Matthew Barth | 3695ac3 | 2021-10-06 14:55:30 -0500 | [diff] [blame] | 94 | if (allGroups.empty() && loadGroups) | 
|  | 95 | { | 
|  | 96 | allGroups = Manager::getConfig<Group>(true); | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | return allGroups; | 
| Matthew Barth | c8bde4a | 2021-05-19 15:34:49 -0500 | [diff] [blame] | 100 | } | 
|  | 101 |  | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 102 | void Event::configGroup(Group& group, const json& jsonObj) | 
|  | 103 | { | 
|  | 104 | if (!jsonObj.contains("interface") || !jsonObj.contains("property") || | 
|  | 105 | !jsonObj["property"].contains("name")) | 
|  | 106 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 107 | lg2::error("Missing required group attribute", "JSON", jsonObj.dump()); | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 108 | throw std::runtime_error("Missing required group attribute"); | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | // Get the group members' interface | 
|  | 112 | auto intf = jsonObj["interface"].get<std::string>(); | 
|  | 113 | group.setInterface(intf); | 
|  | 114 |  | 
|  | 115 | // Get the group members' property name | 
|  | 116 | auto prop = jsonObj["property"]["name"].get<std::string>(); | 
|  | 117 | group.setProperty(prop); | 
|  | 118 |  | 
|  | 119 | // Get the group members' data type | 
|  | 120 | if (jsonObj["property"].contains("type")) | 
|  | 121 | { | 
|  | 122 | std::optional<std::string> type = | 
|  | 123 | jsonObj["property"]["type"].get<std::string>(); | 
|  | 124 | group.setType(type); | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | // Get the group members' expected value | 
|  | 128 | if (jsonObj["property"].contains("value")) | 
|  | 129 | { | 
|  | 130 | std::optional<PropertyVariantType> value = | 
|  | 131 | getJsonValue(jsonObj["property"]["value"]); | 
|  | 132 | group.setValue(value); | 
|  | 133 | } | 
|  | 134 | } | 
|  | 135 |  | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 136 | void Event::setGroups(const json& jsonObj, | 
|  | 137 | const std::vector<std::string>& profiles, | 
|  | 138 | std::vector<Group>& groups) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 139 | { | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 140 | if (jsonObj.contains("groups")) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 141 | { | 
| Matthew Barth | 3695ac3 | 2021-10-06 14:55:30 -0500 | [diff] [blame] | 142 | auto& availGroups = getAllGroups(); | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 143 | for (const auto& jsonGrp : jsonObj["groups"]) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 144 | { | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 145 | if (!jsonGrp.contains("name")) | 
|  | 146 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 147 | lg2::error("Missing required group name attribute", "JSON", | 
|  | 148 | jsonGrp.dump()); | 
|  | 149 | throw std::runtime_error( | 
|  | 150 | "Missing required group name attribute"); | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 151 | } | 
| Matthew Barth | 12bae96 | 2021-01-15 16:18:11 -0600 | [diff] [blame] | 152 |  | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 153 | configKey eventProfile = | 
|  | 154 | std::make_pair(jsonGrp["name"].get<std::string>(), profiles); | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 155 | auto grpEntry = std::find_if( | 
|  | 156 | availGroups.begin(), availGroups.end(), | 
|  | 157 | [&eventProfile](const auto& grp) { | 
|  | 158 | return Manager::inConfig(grp.first, eventProfile); | 
|  | 159 | }); | 
| Matthew Barth | e386fbb | 2021-06-30 14:33:55 -0500 | [diff] [blame] | 160 | if (grpEntry != availGroups.end()) | 
|  | 161 | { | 
|  | 162 | auto group = Group(*grpEntry->second); | 
|  | 163 | configGroup(group, jsonGrp); | 
|  | 164 | groups.emplace_back(group); | 
|  | 165 | } | 
| Matthew Barth | 12bae96 | 2021-01-15 16:18:11 -0600 | [diff] [blame] | 166 | } | 
| Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 167 | } | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 168 | } | 
|  | 169 |  | 
| Matthew Barth | c8bde4a | 2021-05-19 15:34:49 -0500 | [diff] [blame] | 170 | void Event::setActions(const json& jsonObj) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 171 | { | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 172 | for (const auto& jsonAct : jsonObj["actions"]) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 173 | { | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 174 | if (!jsonAct.contains("name")) | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 175 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 176 | lg2::error("Missing required event action name", "JSON", | 
|  | 177 | jsonAct.dump()); | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 178 | throw std::runtime_error("Missing required event action name"); | 
|  | 179 | } | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 180 |  | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 181 | // Determine list of zones action should be run against | 
|  | 182 | std::vector<std::reference_wrapper<Zone>> actionZones; | 
| Matthew Barth | a8ea091 | 2021-05-03 14:33:52 -0500 | [diff] [blame] | 183 | if (!jsonAct.contains("zones")) | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 184 | { | 
|  | 185 | // No zones configured on the action results in the action running | 
|  | 186 | // against all zones matching the event's active profiles | 
|  | 187 | for (const auto& zone : _zones) | 
|  | 188 | { | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 189 | configKey eventProfile = | 
|  | 190 | std::make_pair(zone.second->getName(), _profiles); | 
|  | 191 | auto zoneEntry = std::find_if( | 
|  | 192 | _zones.begin(), _zones.end(), | 
|  | 193 | [&eventProfile](const auto& z) { | 
|  | 194 | return Manager::inConfig(z.first, eventProfile); | 
|  | 195 | }); | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 196 | if (zoneEntry != _zones.end()) | 
|  | 197 | { | 
|  | 198 | actionZones.emplace_back(*zoneEntry->second); | 
|  | 199 | } | 
|  | 200 | } | 
|  | 201 | } | 
|  | 202 | else | 
|  | 203 | { | 
|  | 204 | // Zones configured on the action result in the action only running | 
|  | 205 | // against those zones if they match the event's active profiles | 
| Matthew Barth | a8ea091 | 2021-05-03 14:33:52 -0500 | [diff] [blame] | 206 | for (const auto& jsonZone : jsonAct["zones"]) | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 207 | { | 
|  | 208 | configKey eventProfile = | 
|  | 209 | std::make_pair(jsonZone.get<std::string>(), _profiles); | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 210 | auto zoneEntry = std::find_if( | 
|  | 211 | _zones.begin(), _zones.end(), | 
|  | 212 | [&eventProfile](const auto& z) { | 
|  | 213 | return Manager::inConfig(z.first, eventProfile); | 
|  | 214 | }); | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 215 | if (zoneEntry != _zones.end()) | 
|  | 216 | { | 
|  | 217 | actionZones.emplace_back(*zoneEntry->second); | 
|  | 218 | } | 
|  | 219 | } | 
|  | 220 | } | 
|  | 221 | if (actionZones.empty()) | 
|  | 222 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 223 | lg2::debug( | 
|  | 224 | "No zones configured for event {EVENT_NAME}'s action {ACTION} " | 
|  | 225 | "based on the active profile(s)", | 
|  | 226 | "EVENT_NAME", getName(), "ACTION", | 
|  | 227 | jsonAct["name"].get<std::string>()); | 
| Matthew Barth | 46b3448 | 2021-04-06 11:27:23 -0500 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
| Matthew Barth | 5fb5268 | 2021-09-29 13:57:02 -0500 | [diff] [blame] | 230 | // Action specific groups, if any given, will override the use of event | 
|  | 231 | // groups in the action(s) | 
|  | 232 | std::vector<Group> actionGroups; | 
|  | 233 | setGroups(jsonAct, _profiles, actionGroups); | 
|  | 234 | if (!actionGroups.empty()) | 
| Matthew Barth | 776ca56 | 2021-03-31 09:50:58 -0500 | [diff] [blame] | 235 | { | 
| Matthew Barth | 5fb5268 | 2021-09-29 13:57:02 -0500 | [diff] [blame] | 236 | // Create the action for the event using the action's groups | 
|  | 237 | auto actObj = ActionFactory::getAction( | 
|  | 238 | jsonAct["name"].get<std::string>(), jsonAct, | 
|  | 239 | std::move(actionGroups), std::move(actionZones)); | 
|  | 240 | if (actObj) | 
|  | 241 | { | 
| Matt Spinler | e6fc210 | 2022-04-07 14:31:29 -0500 | [diff] [blame] | 242 | actObj->setEventName(_name); | 
| Matthew Barth | 5fb5268 | 2021-09-29 13:57:02 -0500 | [diff] [blame] | 243 | _actions.emplace_back(std::move(actObj)); | 
|  | 244 | } | 
|  | 245 | } | 
|  | 246 | else | 
|  | 247 | { | 
|  | 248 | // Create the action for the event using the event's groups | 
|  | 249 | auto actObj = ActionFactory::getAction( | 
|  | 250 | jsonAct["name"].get<std::string>(), jsonAct, _groups, | 
|  | 251 | std::move(actionZones)); | 
|  | 252 | if (actObj) | 
|  | 253 | { | 
| Matt Spinler | e6fc210 | 2022-04-07 14:31:29 -0500 | [diff] [blame] | 254 | actObj->setEventName(_name); | 
| Matthew Barth | 5fb5268 | 2021-09-29 13:57:02 -0500 | [diff] [blame] | 255 | _actions.emplace_back(std::move(actObj)); | 
|  | 256 | } | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | if (actionGroups.empty() && _groups.empty()) | 
|  | 260 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 261 | lg2::debug( | 
|  | 262 | "No groups configured for event {EVENT_NAME}'s action {ACTION} " | 
|  | 263 | "based on the active profile(s)", | 
|  | 264 | "EVENT_NAME", getName(), "ACTION", | 
|  | 265 | jsonAct["name"].get<std::string>()); | 
| Matthew Barth | 776ca56 | 2021-03-31 09:50:58 -0500 | [diff] [blame] | 266 | } | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 267 | } | 
|  | 268 | } | 
|  | 269 |  | 
| Matthew Barth | 9f1632e | 2021-03-31 15:51:50 -0500 | [diff] [blame] | 270 | void Event::setTriggers(const json& jsonObj) | 
|  | 271 | { | 
|  | 272 | if (!jsonObj.contains("triggers")) | 
|  | 273 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 274 | lg2::error("Missing required event triggers list", "JSON", | 
|  | 275 | jsonObj.dump()); | 
| Matthew Barth | 9f1632e | 2021-03-31 15:51:50 -0500 | [diff] [blame] | 276 | throw std::runtime_error("Missing required event triggers list"); | 
|  | 277 | } | 
| Matthew Barth | 0620be7 | 2021-04-14 13:31:12 -0500 | [diff] [blame] | 278 | for (const auto& jsonTrig : jsonObj["triggers"]) | 
|  | 279 | { | 
|  | 280 | if (!jsonTrig.contains("class")) | 
|  | 281 | { | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 282 | lg2::error("Missing required event trigger class", "JSON", | 
|  | 283 | jsonTrig.dump()); | 
| Matthew Barth | 0620be7 | 2021-04-14 13:31:12 -0500 | [diff] [blame] | 284 | throw std::runtime_error("Missing required event trigger class"); | 
|  | 285 | } | 
|  | 286 | // The class of trigger used to run the event actions | 
|  | 287 | auto tClass = jsonTrig["class"].get<std::string>(); | 
|  | 288 | std::transform(tClass.begin(), tClass.end(), tClass.begin(), tolower); | 
|  | 289 | auto trigFunc = trigger::triggers.find(tClass); | 
|  | 290 | if (trigFunc != trigger::triggers.end()) | 
|  | 291 | { | 
| Matthew Barth | 54b5a24 | 2021-05-21 11:02:52 -0500 | [diff] [blame] | 292 | _triggers.emplace_back( | 
| Matt Spinler | d1f97f4 | 2021-10-29 16:19:24 -0500 | [diff] [blame] | 293 | trigFunc->first, | 
| Matthew Barth | b6ebac8 | 2021-05-21 11:15:33 -0500 | [diff] [blame] | 294 | trigFunc->second(jsonTrig, getName(), _actions)); | 
| Matthew Barth | 0620be7 | 2021-04-14 13:31:12 -0500 | [diff] [blame] | 295 | } | 
|  | 296 | else | 
|  | 297 | { | 
|  | 298 | // Construct list of available triggers | 
|  | 299 | auto availTrigs = std::accumulate( | 
|  | 300 | std::next(trigger::triggers.begin()), trigger::triggers.end(), | 
|  | 301 | trigger::triggers.begin()->first, [](auto list, auto trig) { | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 302 | return std::move(list) + ", " + trig.first; | 
|  | 303 | }); | 
| Anwaar Hadi | 64b5ac2 | 2025-04-04 23:54:53 +0000 | [diff] [blame] | 304 | lg2::error( | 
|  | 305 | "Trigger '{TRIGGER}' is not recognized. Available triggers are {AVAILABLE_TRIGGERS}", | 
|  | 306 | "TRIGGER", tClass, "AVAILABLE_TRIGGERS", availTrigs); | 
| Matthew Barth | 0620be7 | 2021-04-14 13:31:12 -0500 | [diff] [blame] | 307 | throw std::runtime_error("Unsupported trigger class name given"); | 
|  | 308 | } | 
|  | 309 | } | 
| Matthew Barth | 9f1632e | 2021-03-31 15:51:50 -0500 | [diff] [blame] | 310 | } | 
|  | 311 |  | 
| Matt Spinler | c3eb7b3 | 2022-04-25 15:44:16 -0500 | [diff] [blame] | 312 | json Event::dump() const | 
|  | 313 | { | 
|  | 314 | json actionData; | 
|  | 315 | std::for_each(_actions.begin(), _actions.end(), | 
|  | 316 | [&actionData](const auto& action) { | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 317 | actionData[action->getUniqueName()] = action->dump(); | 
|  | 318 | }); | 
| Matt Spinler | c3eb7b3 | 2022-04-25 15:44:16 -0500 | [diff] [blame] | 319 |  | 
|  | 320 | std::vector<std::string> groupData; | 
|  | 321 | std::for_each(_groups.begin(), _groups.end(), | 
|  | 322 | [&groupData](const auto& group) { | 
| Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame] | 323 | groupData.push_back(group.getName()); | 
|  | 324 | }); | 
| Matt Spinler | c3eb7b3 | 2022-04-25 15:44:16 -0500 | [diff] [blame] | 325 |  | 
|  | 326 | json eventData; | 
|  | 327 | eventData["groups"] = groupData; | 
|  | 328 | eventData["actions"] = actionData; | 
|  | 329 |  | 
|  | 330 | return eventData; | 
|  | 331 | } | 
|  | 332 |  | 
| Matthew Barth | 3174e72 | 2020-09-15 15:13:40 -0500 | [diff] [blame] | 333 | } // namespace phosphor::fan::control::json |