xref: /openbmc/phosphor-fan-presence/control/json/manager.cpp (revision 5e15c3ba7e863d57a38fa44b343d625fb26da9ca)
1 /**
2  * Copyright © 2022 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 "config.h"
17 
18 #include "manager.hpp"
19 
20 #include "action.hpp"
21 #include "dbus_paths.hpp"
22 #include "event.hpp"
23 #include "fan.hpp"
24 #include "group.hpp"
25 #include "json_config.hpp"
26 #include "power_state.hpp"
27 #include "profile.hpp"
28 #include "sdbusplus.hpp"
29 #include "utils/flight_recorder.hpp"
30 #include "zone.hpp"
31 
32 #include <systemd/sd-bus.h>
33 
34 #include <nlohmann/json.hpp>
35 #include <sdbusplus/bus.hpp>
36 #include <sdbusplus/server/manager.hpp>
37 #include <sdeventplus/event.hpp>
38 #include <sdeventplus/utility/timer.hpp>
39 
40 #include <algorithm>
41 #include <chrono>
42 #include <filesystem>
43 #include <functional>
44 #include <map>
45 #include <memory>
46 #include <tuple>
47 #include <utility>
48 #include <vector>
49 
50 namespace phosphor::fan::control::json
51 {
52 
53 using json = nlohmann::json;
54 
55 std::vector<std::string> Manager::_activeProfiles;
56 std::map<std::string,
57          std::map<std::string, std::pair<bool, std::vector<std::string>>>>
58     Manager::_servTree;
59 std::map<std::string,
60          std::map<std::string, std::map<std::string, PropertyVariantType>>>
61     Manager::_objects;
62 std::unordered_map<std::string, PropertyVariantType> Manager::_parameters;
63 std::unordered_map<std::string, TriggerActions> Manager::_parameterTriggers;
64 
65 const std::string Manager::dumpFile = "/tmp/fan_control_dump.json";
66 
67 Manager::Manager(const sdeventplus::Event& event) :
68     _bus(util::SDBusPlus::getBus()), _event(event),
69     _mgr(util::SDBusPlus::getBus(), CONTROL_OBJPATH), _loadAllowed(true),
70     _powerState(std::make_unique<PGoodState>(
71         util::SDBusPlus::getBus(),
72         std::bind(std::mem_fn(&Manager::powerStateChanged), this,
73                   std::placeholders::_1)))
74 {}
75 
76 void Manager::sighupHandler(sdeventplus::source::Signal&,
77                             const struct signalfd_siginfo*)
78 {
79     FlightRecorder::instance().log("main", "SIGHUP received");
80     // Save current set of available and active profiles
81     std::map<configKey, std::unique_ptr<Profile>> profiles;
82     profiles.swap(_profiles);
83     std::vector<std::string> activeProfiles;
84     activeProfiles.swap(_activeProfiles);
85 
86     try
87     {
88         _loadAllowed = true;
89         load();
90     }
91     catch (const std::runtime_error& re)
92     {
93         // Restore saved available and active profiles
94         _loadAllowed = false;
95         _profiles.swap(profiles);
96         _activeProfiles.swap(activeProfiles);
97         log<level::ERR>("Error reloading configs, no changes made",
98                         entry("LOAD_ERROR=%s", re.what()));
99         FlightRecorder::instance().log(
100             "main", std::format("Error reloading configs, no changes made: {}",
101                                 re.what()));
102     }
103 }
104 
105 void Manager::dumpDebugData(sdeventplus::source::Signal&,
106                             const struct signalfd_siginfo*)
107 {
108     json data;
109     FlightRecorder::instance().dump(data);
110     dumpCache(data);
111 
112     std::for_each(_zones.begin(), _zones.end(), [&data](const auto& zone) {
113         data["zones"][zone.second->getName()] = zone.second->dump();
114     });
115 
116     std::ofstream file{Manager::dumpFile};
117     if (!file)
118     {
119         log<level::ERR>("Could not open file for fan dump");
120         return;
121     }
122 
123     file << std::setw(4) << data;
124 }
125 
126 void Manager::dumpCache(json& data)
127 {
128     auto& objects = data["objects"];
129     for (const auto& [path, interfaces] : _objects)
130     {
131         auto& interfaceJSON = objects[path];
132 
133         for (const auto& [interface, properties] : interfaces)
134         {
135             auto& propertyJSON = interfaceJSON[interface];
136             for (const auto& [propName, propValue] : properties)
137             {
138                 std::visit(
139                     [&obj = propertyJSON[propName]](auto&& val) { obj = val; },
140                     propValue);
141             }
142         }
143     }
144 
145     auto& parameters = data["parameters"];
146     for (const auto& [name, value] : _parameters)
147     {
148         std::visit([&obj = parameters[name]](auto&& val) { obj = val; }, value);
149     }
150 
151     std::for_each(_events.begin(), _events.end(), [&data](const auto& event) {
152         data["events"][event.second->getName()] = event.second->dump();
153     });
154 
155     data["services"] = _servTree;
156 }
157 
158 void Manager::load()
159 {
160     if (_loadAllowed)
161     {
162         // Load the available profiles and which are active
163         setProfiles();
164 
165         // Load the zone configurations
166         auto zones = getConfig<Zone>(false, _event, this);
167         // Load the fan configurations and move each fan into its zone
168         auto fans = getConfig<Fan>(false);
169         for (auto& fan : fans)
170         {
171             configKey fanProfile = std::make_pair(fan.second->getZone(),
172                                                   fan.first.second);
173             auto itZone = std::find_if(zones.begin(), zones.end(),
174                                        [&fanProfile](const auto& zone) {
175                 return Manager::inConfig(fanProfile, zone.first);
176             });
177             if (itZone != zones.end())
178             {
179                 if (itZone->second->getTarget() != fan.second->getTarget() &&
180                     fan.second->getTarget() != 0)
181                 {
182                     // Update zone target to current target of the fan in the
183                     // zone
184                     itZone->second->setTarget(fan.second->getTarget());
185                 }
186                 itZone->second->addFan(std::move(fan.second));
187             }
188         }
189 
190         // Save all currently available groups, if any, then clear for reloading
191         auto groups = std::move(Event::getAllGroups(false));
192         Event::clearAllGroups();
193 
194         std::map<configKey, std::unique_ptr<Event>> events;
195         try
196         {
197             // Load any events configured, including all the groups
198             events = getConfig<Event>(true, this, zones);
199         }
200         catch (const std::runtime_error& re)
201         {
202             // Restore saved set of all available groups for current events
203             Event::setAllGroups(std::move(groups));
204             throw re;
205         }
206 
207         // Enable zones
208         _zones = std::move(zones);
209         std::for_each(_zones.begin(), _zones.end(),
210                       [](const auto& entry) { entry.second->enable(); });
211 
212         // Clear current timers and signal subscriptions before enabling events
213         // To save reloading services and/or objects into cache, do not clear
214         // cache
215         _timers.clear();
216         _signals.clear();
217 
218         // Enable events
219         _events = std::move(events);
220         FlightRecorder::instance().log("main", "Enabling events");
221         std::for_each(_events.begin(), _events.end(),
222                       [](const auto& entry) { entry.second->enable(); });
223         FlightRecorder::instance().log("main", "Done enabling events");
224 
225         _loadAllowed = false;
226     }
227 }
228 
229 void Manager::powerStateChanged(bool powerStateOn)
230 {
231     if (powerStateOn)
232     {
233         if (_zones.empty())
234         {
235             throw std::runtime_error("No configured zones found at poweron");
236         }
237         std::for_each(_zones.begin(), _zones.end(), [](const auto& entry) {
238             entry.second->setTarget(entry.second->getPoweronTarget());
239         });
240 
241         // Tell events to run their power on triggers
242         std::for_each(_events.begin(), _events.end(),
243                       [](const auto& entry) { entry.second->powerOn(); });
244     }
245     else
246     {
247         // Tell events to run their power off triggers
248         std::for_each(_events.begin(), _events.end(),
249                       [](const auto& entry) { entry.second->powerOff(); });
250     }
251 }
252 
253 const std::vector<std::string>& Manager::getActiveProfiles()
254 {
255     return _activeProfiles;
256 }
257 
258 bool Manager::inConfig(const configKey& input, const configKey& comp)
259 {
260     // Config names dont match, do not include in config
261     if (input.first != comp.first)
262     {
263         return false;
264     }
265     // No profiles specified by input config, can be used in any config
266     if (input.second.empty())
267     {
268         return true;
269     }
270     else
271     {
272         // Profiles must have one match in the other's profiles(and they must be
273         // an active profile) to be used in the config
274         return std::any_of(input.second.begin(), input.second.end(),
275                            [&comp](const auto& lProfile) {
276             return std::any_of(comp.second.begin(), comp.second.end(),
277                                [&lProfile](const auto& rProfile) {
278                 if (lProfile != rProfile)
279                 {
280                     return false;
281                 }
282                 auto activeProfs = getActiveProfiles();
283                 return std::find(activeProfs.begin(), activeProfs.end(),
284                                  lProfile) != activeProfs.end();
285             });
286         });
287     }
288 }
289 
290 bool Manager::hasOwner(const std::string& path, const std::string& intf)
291 {
292     auto itServ = _servTree.find(path);
293     if (itServ == _servTree.end())
294     {
295         // Path not found in cache, therefore owner missing
296         return false;
297     }
298     for (const auto& service : itServ->second)
299     {
300         auto itIntf = std::find_if(
301             service.second.second.begin(), service.second.second.end(),
302             [&intf](const auto& interface) { return intf == interface; });
303         if (itIntf != std::end(service.second.second))
304         {
305             // Service found, return owner state
306             return service.second.first;
307         }
308     }
309     // Interface not found in cache, therefore owner missing
310     return false;
311 }
312 
313 void Manager::setOwner(const std::string& serv, bool hasOwner)
314 {
315     // Update owner state on all entries of `serv`
316     for (auto& itPath : _servTree)
317     {
318         auto itServ = itPath.second.find(serv);
319         if (itServ != itPath.second.end())
320         {
321             itServ->second.first = hasOwner;
322 
323             // Remove associated interfaces from object cache when service no
324             // longer has an owner
325             if (!hasOwner && _objects.find(itPath.first) != _objects.end())
326             {
327                 for (auto& intf : itServ->second.second)
328                 {
329                     _objects[itPath.first].erase(intf);
330                 }
331             }
332         }
333     }
334 }
335 
336 void Manager::setOwner(const std::string& path, const std::string& serv,
337                        const std::string& intf, bool isOwned)
338 {
339     // Set owner state for specific object given
340     auto& ownIntf = _servTree[path][serv];
341     ownIntf.first = isOwned;
342     auto itIntf = std::find_if(
343         ownIntf.second.begin(), ownIntf.second.end(),
344         [&intf](const auto& interface) { return intf == interface; });
345     if (itIntf == std::end(ownIntf.second))
346     {
347         ownIntf.second.emplace_back(intf);
348     }
349 
350     // Update owner state on all entries of the same `serv` & `intf`
351     for (auto& itPath : _servTree)
352     {
353         if (itPath.first == path)
354         {
355             // Already set/updated owner on this path for `serv` & `intf`
356             continue;
357         }
358         for (auto& itServ : itPath.second)
359         {
360             if (itServ.first != serv)
361             {
362                 continue;
363             }
364             auto itIntf = std::find_if(
365                 itServ.second.second.begin(), itServ.second.second.end(),
366                 [&intf](const auto& interface) { return intf == interface; });
367             if (itIntf != std::end(itServ.second.second))
368             {
369                 itServ.second.first = isOwned;
370             }
371         }
372     }
373 }
374 
375 const std::string& Manager::findService(const std::string& path,
376                                         const std::string& intf)
377 {
378     static const std::string empty = "";
379 
380     auto itServ = _servTree.find(path);
381     if (itServ != _servTree.end())
382     {
383         for (const auto& service : itServ->second)
384         {
385             auto itIntf = std::find_if(
386                 service.second.second.begin(), service.second.second.end(),
387                 [&intf](const auto& interface) { return intf == interface; });
388             if (itIntf != std::end(service.second.second))
389             {
390                 // Service found, return service name
391                 return service.first;
392             }
393         }
394     }
395 
396     return empty;
397 }
398 
399 void Manager::addServices(const std::string& intf, int32_t depth)
400 {
401     // Get all subtree objects for the given interface
402     auto objects = util::SDBusPlus::getSubTreeRaw(util::SDBusPlus::getBus(),
403                                                   "/", intf, depth);
404     // Add what's returned to the cache of path->services
405     for (auto& itPath : objects)
406     {
407         auto pathIter = _servTree.find(itPath.first);
408         if (pathIter != _servTree.end())
409         {
410             // Path found in cache
411             for (auto& itServ : itPath.second)
412             {
413                 auto servIter = pathIter->second.find(itServ.first);
414                 if (servIter != pathIter->second.end())
415                 {
416                     if (std::find(servIter->second.second.begin(),
417                                   servIter->second.second.end(),
418                                   intf) == servIter->second.second.end())
419                     {
420                         // Add interface to cache
421                         servIter->second.second.emplace_back(intf);
422                     }
423                 }
424                 else
425                 {
426                     // Service not found in cache
427                     auto intfs = {intf};
428                     pathIter->second[itServ.first] = std::make_pair(true,
429                                                                     intfs);
430                 }
431             }
432         }
433         else
434         {
435             // Path not found in cache
436             auto intfs = {intf};
437             for (const auto& [servName, servIntfs] : itPath.second)
438             {
439                 _servTree[itPath.first][servName] = std::make_pair(true, intfs);
440             }
441         }
442     }
443 }
444 
445 const std::string& Manager::getService(const std::string& path,
446                                        const std::string& intf)
447 {
448     // Retrieve service from cache
449     const auto& serviceName = findService(path, intf);
450     if (serviceName.empty())
451     {
452         addServices(intf, 0);
453         return findService(path, intf);
454     }
455 
456     return serviceName;
457 }
458 
459 std::vector<std::string> Manager::findPaths(const std::string& serv,
460                                             const std::string& intf)
461 {
462     std::vector<std::string> paths;
463 
464     for (const auto& path : _servTree)
465     {
466         auto itServ = path.second.find(serv);
467         if (itServ != path.second.end())
468         {
469             if (std::find(itServ->second.second.begin(),
470                           itServ->second.second.end(),
471                           intf) != itServ->second.second.end())
472             {
473                 if (std::find(paths.begin(), paths.end(), path.first) ==
474                     paths.end())
475                 {
476                     paths.push_back(path.first);
477                 }
478             }
479         }
480     }
481 
482     return paths;
483 }
484 
485 std::vector<std::string> Manager::getPaths(const std::string& serv,
486                                            const std::string& intf)
487 {
488     auto paths = findPaths(serv, intf);
489     if (paths.empty())
490     {
491         addServices(intf, 0);
492         return findPaths(serv, intf);
493     }
494 
495     return paths;
496 }
497 
498 void Manager::insertFilteredObjects(ManagedObjects& ref)
499 {
500     // Filter out objects that aren't part of a group
501     const auto& allGroupMembers = Group::getAllMembers();
502     auto it = ref.begin();
503 
504     while (it != ref.end())
505     {
506         if (allGroupMembers.find(it->first) == allGroupMembers.end())
507         {
508             it = ref.erase(it);
509         }
510         else
511         {
512             it++;
513         }
514     }
515 
516     for (auto& [path, pathMap] : ref)
517     {
518         for (auto& [intf, intfMap] : pathMap)
519         {
520             // for each property on this path+interface
521             for (auto& [prop, value] : intfMap)
522             {
523                 setProperty(path, intf, prop, value);
524             }
525         }
526     }
527 }
528 
529 void Manager::addObjects(const std::string& path, const std::string& intf,
530                          const std::string& prop,
531                          const std::string& serviceName)
532 {
533     auto service = serviceName;
534     if (service.empty())
535     {
536         service = getService(path, intf);
537         if (service.empty())
538         {
539             // Log service not found for object
540             log<level::DEBUG>(
541                 std::format(
542                     "Unable to get service name for path {}, interface {}",
543                     path, intf)
544                     .c_str());
545             return;
546         }
547     }
548     else
549     {
550         // The service is known, so the service cache can be
551         // populated even if the path itself isn't present.
552         const auto& s = findService(path, intf);
553         if (s.empty())
554         {
555             addServices(intf, 0);
556         }
557     }
558 
559     auto objMgrPaths = getPaths(service, "org.freedesktop.DBus.ObjectManager");
560     if (objMgrPaths.empty())
561     {
562         // No object manager interface provided by service?
563         // Attempt to retrieve property directly
564         try
565         {
566             auto value =
567                 util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
568                     _bus, service, path, intf, prop);
569 
570             setProperty(path, intf, prop, value);
571         }
572         catch (const std::exception& e)
573         {}
574         return;
575     }
576 
577     for (const auto& objMgrPath : objMgrPaths)
578     {
579         // Get all managed objects of service
580         auto objects = util::SDBusPlus::getManagedObjects<PropertyVariantType>(
581             _bus, service, objMgrPath);
582 
583         // insert all objects that are in groups but remove any NaN values
584         insertFilteredObjects(objects);
585     }
586 }
587 
588 const std::optional<PropertyVariantType>
589     Manager::getProperty(const std::string& path, const std::string& intf,
590                          const std::string& prop)
591 {
592     // TODO Objects hosted by fan control (i.e. ThermalMode) are required to
593     // update the cache upon being set/updated
594     auto itPath = _objects.find(path);
595     if (itPath != _objects.end())
596     {
597         auto itIntf = itPath->second.find(intf);
598         if (itIntf != itPath->second.end())
599         {
600             auto itProp = itIntf->second.find(prop);
601             if (itProp != itIntf->second.end())
602             {
603                 return itProp->second;
604             }
605         }
606     }
607 
608     return std::nullopt;
609 }
610 
611 void Manager::setProperty(const std::string& path, const std::string& intf,
612                           const std::string& prop, PropertyVariantType value)
613 {
614     // filter NaNs out of the cache
615     if (PropertyContainsNan(value))
616     {
617         // dont use operator [] if paths dont exist
618         if (_objects.find(path) != _objects.end() &&
619             _objects[path].find(intf) != _objects[path].end())
620         {
621             _objects[path][intf].erase(prop);
622         }
623     }
624     else
625     {
626         _objects[path][intf][prop] = std::move(value);
627     }
628 }
629 
630 void Manager::addTimer(const TimerType type,
631                        const std::chrono::microseconds interval,
632                        std::unique_ptr<TimerPkg> pkg)
633 {
634     auto dataPtr =
635         std::make_unique<TimerData>(std::make_pair(type, std::move(*pkg)));
636     Timer timer(_event,
637                 std::bind(&Manager::timerExpired, this, std::ref(*dataPtr)));
638     if (type == TimerType::repeating)
639     {
640         timer.restart(interval);
641     }
642     else if (type == TimerType::oneshot)
643     {
644         timer.restartOnce(interval);
645     }
646     else
647     {
648         throw std::invalid_argument("Invalid Timer Type");
649     }
650     _timers.emplace_back(std::move(dataPtr), std::move(timer));
651 }
652 
653 void Manager::addGroups(const std::vector<Group>& groups)
654 {
655     std::string lastServ;
656     std::vector<std::string> objMgrPaths;
657     std::set<std::string> services;
658     for (const auto& group : groups)
659     {
660         for (const auto& member : group.getMembers())
661         {
662             try
663             {
664                 auto service = group.getService();
665                 if (service.empty())
666                 {
667                     service = getService(member, group.getInterface());
668                 }
669 
670                 if (!service.empty())
671                 {
672                     if (lastServ != service)
673                     {
674                         objMgrPaths = getPaths(
675                             service, "org.freedesktop.DBus.ObjectManager");
676                         lastServ = service;
677                     }
678 
679                     // Look for the ObjectManager as an ancestor from the
680                     // member.
681                     auto hasObjMgr = std::any_of(objMgrPaths.begin(),
682                                                  objMgrPaths.end(),
683                                                  [&member](const auto& path) {
684                         return member.find(path) != std::string::npos;
685                     });
686 
687                     if (!hasObjMgr)
688                     {
689                         // No object manager interface provided for group member
690                         // Attempt to retrieve group member property directly
691                         try
692                         {
693                             auto value = util::SDBusPlus::getPropertyVariant<
694                                 PropertyVariantType>(_bus, service, member,
695                                                      group.getInterface(),
696                                                      group.getProperty());
697                             setProperty(member, group.getInterface(),
698                                         group.getProperty(), value);
699                         }
700                         catch (const std::exception& e)
701                         {}
702                         continue;
703                     }
704 
705                     if (services.find(service) == services.end())
706                     {
707                         services.insert(service);
708                         for (const auto& objMgrPath : objMgrPaths)
709                         {
710                             // Get all managed objects from the service
711                             auto objects = util::SDBusPlus::getManagedObjects<
712                                 PropertyVariantType>(_bus, service, objMgrPath);
713 
714                             // Insert objects into cache
715                             insertFilteredObjects(objects);
716                         }
717                     }
718                 }
719             }
720             catch (const util::DBusError&)
721             {
722                 // No service or property found for group member with the
723                 // group's configured interface
724                 continue;
725             }
726         }
727     }
728 }
729 
730 void Manager::timerExpired(TimerData& data)
731 {
732     if (std::get<bool>(data.second))
733     {
734         addGroups(std::get<const std::vector<Group>&>(data.second));
735     }
736 
737     auto& actions =
738         std::get<std::vector<std::unique_ptr<ActionBase>>&>(data.second);
739     // Perform the actions in the timer data
740     std::for_each(actions.begin(), actions.end(),
741                   [](auto& action) { action->run(); });
742 
743     // Remove oneshot timers after they expired
744     if (data.first == TimerType::oneshot)
745     {
746         auto itTimer = std::find_if(_timers.begin(), _timers.end(),
747                                     [&data](const auto& timer) {
748             return (data.first == timer.first->first &&
749                     (std::get<std::string>(data.second) ==
750                      std::get<std::string>(timer.first->second)));
751         });
752         if (itTimer != std::end(_timers))
753         {
754             _timers.erase(itTimer);
755         }
756     }
757 }
758 
759 void Manager::handleSignal(sdbusplus::message_t& msg,
760                            const std::vector<SignalPkg>* pkgs)
761 {
762     for (auto& pkg : *pkgs)
763     {
764         // Handle the signal callback and only run the actions if the handler
765         // updated the cache for the given SignalObject
766         if (std::get<SignalHandler>(pkg)(msg, std::get<SignalObject>(pkg),
767                                          *this))
768         {
769             // Perform the actions in the handler package
770             auto& actions = std::get<TriggerActions>(pkg);
771             std::for_each(actions.begin(), actions.end(), [](auto& action) {
772                 if (action.get())
773                 {
774                     action.get()->run();
775                 }
776             });
777         }
778         // Only rewind message when not last package
779         if (&pkg != &pkgs->back())
780         {
781             sd_bus_message_rewind(msg.get(), true);
782         }
783     }
784 }
785 
786 void Manager::setProfiles()
787 {
788     // Profiles JSON config file is optional
789     auto confFile = fan::JsonConfig::getConfFile(confAppName,
790                                                  Profile::confFileName, true);
791 
792     _profiles.clear();
793     if (!confFile.empty())
794     {
795         for (const auto& entry : fan::JsonConfig::load(confFile))
796         {
797             auto obj = std::make_unique<Profile>(entry);
798             _profiles.emplace(
799                 std::make_pair(obj->getName(), obj->getProfiles()),
800                 std::move(obj));
801         }
802     }
803 
804     // Ensure all configurations use the same set of active profiles
805     // (In case a profile's active state changes during configuration)
806     _activeProfiles.clear();
807     for (const auto& profile : _profiles)
808     {
809         if (profile.second->isActive())
810         {
811             _activeProfiles.emplace_back(profile.first.first);
812         }
813     }
814 }
815 
816 void Manager::addParameterTrigger(
817     const std::string& name, std::vector<std::unique_ptr<ActionBase>>& actions)
818 {
819     auto it = _parameterTriggers.find(name);
820     if (it != _parameterTriggers.end())
821     {
822         std::for_each(actions.begin(), actions.end(),
823                       [&actList = it->second](auto& action) {
824             actList.emplace_back(std::ref(action));
825         });
826     }
827     else
828     {
829         TriggerActions triggerActions;
830         std::for_each(actions.begin(), actions.end(),
831                       [&triggerActions](auto& action) {
832             triggerActions.emplace_back(std::ref(action));
833         });
834         _parameterTriggers[name] = std::move(triggerActions);
835     }
836 }
837 
838 void Manager::runParameterActions(const std::string& name)
839 {
840     auto it = _parameterTriggers.find(name);
841     if (it != _parameterTriggers.end())
842     {
843         std::for_each(it->second.begin(), it->second.end(),
844                       [](auto& action) { action.get()->run(); });
845     }
846 }
847 
848 } // namespace phosphor::fan::control::json
849