blob: 9ddff4f83a18986e45c1cb6374b1fb5e51d8a921 [file] [log] [blame]
Shawn McCarney78488f62019-11-05 15:29:54 -06001/**
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
24namespace phosphor
25{
26namespace power
27{
28namespace regulators
29{
30namespace action_utils
31{
32
33/**
34 * This file contains utility functions related to the regulators action
35 * framework.
36 */
37
38/**
39 * Executes one or more actions in sequential order.
40 *
41 * Returns the return value from the last action in the vector.
42 *
43 * Throws an exception if an error occurs and an action cannot be
44 * successfully executed.
45 *
46 * @param actions actions to execute
47 * @param environment action execution environment
48 * @return return value from last action in vector
49 */
50inline bool execute(std::vector<std::unique_ptr<Action>>& actions,
51 ActionEnvironment& environment)
52{
53 bool returnValue{true};
54 for (std::unique_ptr<Action>& action : actions)
55 {
56 returnValue = action->execute(environment);
57 }
58 return returnValue;
59}
60
61} // namespace action_utils
62} // namespace regulators
63} // namespace power
64} // namespace phosphor