178488f61SShawn McCarney /** 278488f61SShawn McCarney * Copyright © 2019 IBM Corporation 378488f61SShawn McCarney * 478488f61SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 578488f61SShawn McCarney * you may not use this file except in compliance with the License. 678488f61SShawn McCarney * You may obtain a copy of the License at 778488f61SShawn McCarney * 878488f61SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 978488f61SShawn McCarney * 1078488f61SShawn McCarney * Unless required by applicable law or agreed to in writing, software 1178488f61SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 1278488f61SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1378488f61SShawn McCarney * See the License for the specific language governing permissions and 1478488f61SShawn McCarney * limitations under the License. 1578488f61SShawn McCarney */ 1678488f61SShawn McCarney #pragma once 1778488f61SShawn McCarney 1878488f61SShawn McCarney #include "action.hpp" 1978488f61SShawn McCarney #include "action_environment.hpp" 2078488f61SShawn McCarney 2178488f61SShawn McCarney #include <memory> 2278488f61SShawn McCarney #include <vector> 2378488f61SShawn McCarney 24*ea7385b8SShawn McCarney namespace phosphor::power::regulators::action_utils 2578488f61SShawn McCarney { 2678488f61SShawn McCarney 2778488f61SShawn McCarney /** 2878488f61SShawn McCarney * This file contains utility functions related to the regulators action 2978488f61SShawn McCarney * framework. 3078488f61SShawn McCarney */ 3178488f61SShawn McCarney 3278488f61SShawn McCarney /** 3378488f61SShawn McCarney * Executes one or more actions in sequential order. 3478488f61SShawn McCarney * 3578488f61SShawn McCarney * Returns the return value from the last action in the vector. 3678488f61SShawn McCarney * 3778488f61SShawn McCarney * Throws an exception if an error occurs and an action cannot be 3878488f61SShawn McCarney * successfully executed. 3978488f61SShawn McCarney * 4078488f61SShawn McCarney * @param actions actions to execute 4178488f61SShawn McCarney * @param environment action execution environment 4278488f61SShawn McCarney * @return return value from last action in vector 4378488f61SShawn McCarney */ execute(std::vector<std::unique_ptr<Action>> & actions,ActionEnvironment & environment)4478488f61SShawn McCarneyinline bool execute(std::vector<std::unique_ptr<Action>>& actions, 4578488f61SShawn McCarney ActionEnvironment& environment) 4678488f61SShawn McCarney { 4778488f61SShawn McCarney bool returnValue{true}; 4878488f61SShawn McCarney for (std::unique_ptr<Action>& action : actions) 4978488f61SShawn McCarney { 5078488f61SShawn McCarney returnValue = action->execute(environment); 5178488f61SShawn McCarney } 5278488f61SShawn McCarney return returnValue; 5378488f61SShawn McCarney } 5478488f61SShawn McCarney 55*ea7385b8SShawn McCarney } // namespace phosphor::power::regulators::action_utils 56