1 /** 2 * Copyright © 2019 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 #pragma once 17 18 #include "action.hpp" 19 #include "action_environment.hpp" 20 21 #include <memory> 22 #include <vector> 23 24 namespace phosphor::power::regulators::action_utils 25 { 26 27 /** 28 * This file contains utility functions related to the regulators action 29 * framework. 30 */ 31 32 /** 33 * Executes one or more actions in sequential order. 34 * 35 * Returns the return value from the last action in the vector. 36 * 37 * Throws an exception if an error occurs and an action cannot be 38 * successfully executed. 39 * 40 * @param actions actions to execute 41 * @param environment action execution environment 42 * @return return value from last action in vector 43 */ 44 inline bool execute(std::vector<std::unique_ptr<Action>>& actions, 45 ActionEnvironment& environment) 46 { 47 bool returnValue{true}; 48 for (std::unique_ptr<Action>& action : actions) 49 { 50 returnValue = action->execute(environment); 51 } 52 return returnValue; 53 } 54 55 } // namespace phosphor::power::regulators::action_utils 56