regulators: Create Configuration class

Create C++ class that implements the 'configuration' element from the
JSON config file.  See configuration.md for more information.

The execute() method of this class will be implemented in a future
commit.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I9a8e2774e110ef56b2e23c46be6830a6e1275cc6
diff --git a/phosphor-regulators/src/configuration.hpp b/phosphor-regulators/src/configuration.hpp
new file mode 100644
index 0000000..4e2e4ed
--- /dev/null
+++ b/phosphor-regulators/src/configuration.hpp
@@ -0,0 +1,113 @@
+/**
+ * Copyright © 2020 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "action.hpp"
+
+#include <memory>
+#include <optional>
+#include <utility>
+#include <vector>
+
+namespace phosphor::power::regulators
+{
+
+/**
+ * @class Configuration
+ *
+ * Configuration changes that should be applied to a device or regulator rail.
+ * These changes usually override hardware default settings.
+ *
+ * The most common configuration change is setting the output voltage for a
+ * regulator rail.  Other examples include modifying pgood thresholds and
+ * overcurrent settings.
+ *
+ * The configuration changes are applied during the boot before regulators are
+ * enabled.
+ *
+ * The configuration changes are applied by executing one or more actions.
+ *
+ * An output voltage value can be specified if necessary.  The value will be
+ * stored in the ActionEnvironment when the actions are executed.  Actions that
+ * require a volts value, such as PMBusWriteVoutCommandAction, can obtain it
+ * from the ActionEnvironment.
+ */
+class Configuration
+{
+  public:
+    // Specify which compiler-generated methods we want
+    Configuration() = delete;
+    Configuration(const Configuration&) = delete;
+    Configuration(Configuration&&) = delete;
+    Configuration& operator=(const Configuration&) = delete;
+    Configuration& operator=(Configuration&&) = delete;
+    ~Configuration() = default;
+
+    /**
+     * Constructor.
+     *
+     * @param volts optional output voltage value
+     * @param actions actions that configure the device/rail
+     */
+    explicit Configuration(std::optional<double> volts,
+                           std::vector<std::unique_ptr<Action>> actions) :
+        volts{volts},
+        actions{std::move(actions)}
+    {
+    }
+
+    /**
+     * Executes the actions to configure the device/rail.
+     */
+    void execute()
+    {
+        // TODO: Create ActionEnvironment, set volts value if specified, execute
+        // actions, catch and handle any exceptions
+    }
+
+    /**
+     * Returns the actions that configure the device/rail.
+     *
+     * @return actions
+     */
+    const std::vector<std::unique_ptr<Action>>& getActions() const
+    {
+        return actions;
+    }
+
+    /**
+     * Returns the optional output voltage value.
+     *
+     * @return optional volts value
+     */
+    std::optional<double> getVolts() const
+    {
+        return volts;
+    }
+
+  private:
+    /**
+     * Optional output voltage value.
+     */
+    const std::optional<double> volts{};
+
+    /**
+     * Actions that configure the device/rail.
+     */
+    std::vector<std::unique_ptr<Action>> actions{};
+};
+
+} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/test/configuration_tests.cpp b/phosphor-regulators/test/configuration_tests.cpp
new file mode 100644
index 0000000..a4086e1
--- /dev/null
+++ b/phosphor-regulators/test/configuration_tests.cpp
@@ -0,0 +1,105 @@
+/**
+ * Copyright © 2020 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "action.hpp"
+#include "configuration.hpp"
+#include "mock_action.hpp"
+
+#include <memory>
+#include <optional>
+#include <utility>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+
+TEST(ConfigurationTests, Constructor)
+{
+    // Test where volts value specified
+    {
+        std::optional<double> volts{1.3};
+
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+        actions.push_back(std::make_unique<MockAction>());
+
+        Configuration configuration(volts, std::move(actions));
+        EXPECT_EQ(configuration.getVolts().has_value(), true);
+        EXPECT_EQ(configuration.getVolts().value(), 1.3);
+        EXPECT_EQ(configuration.getActions().size(), 2);
+    }
+
+    // Test where volts value not specified
+    {
+        std::optional<double> volts{};
+
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+
+        Configuration configuration(volts, std::move(actions));
+        EXPECT_EQ(configuration.getVolts().has_value(), false);
+        EXPECT_EQ(configuration.getActions().size(), 1);
+    }
+}
+
+TEST(ConfigurationTests, Execute)
+{
+    // TODO: Implement test when execute() function is done
+}
+
+TEST(ConfigurationTests, GetActions)
+{
+    std::optional<double> volts{1.3};
+
+    std::vector<std::unique_ptr<Action>> actions{};
+
+    MockAction* action1 = new MockAction{};
+    actions.push_back(std::unique_ptr<MockAction>{action1});
+
+    MockAction* action2 = new MockAction{};
+    actions.push_back(std::unique_ptr<MockAction>{action2});
+
+    Configuration configuration(volts, std::move(actions));
+    EXPECT_EQ(configuration.getActions().size(), 2);
+    EXPECT_EQ(configuration.getActions()[0].get(), action1);
+    EXPECT_EQ(configuration.getActions()[1].get(), action2);
+}
+
+TEST(ConfigurationTests, GetVolts)
+{
+    // Test where volts value specified
+    {
+        std::optional<double> volts{3.2};
+
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+
+        Configuration configuration(volts, std::move(actions));
+        EXPECT_EQ(configuration.getVolts().has_value(), true);
+        EXPECT_EQ(configuration.getVolts().value(), 3.2);
+    }
+
+    // Test where volts value not specified
+    {
+        std::optional<double> volts{};
+
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+
+        Configuration configuration(volts, std::move(actions));
+        EXPECT_EQ(configuration.getVolts().has_value(), false);
+    }
+}
diff --git a/phosphor-regulators/test/meson.build b/phosphor-regulators/test/meson.build
index 8cee4e7..0220532 100644
--- a/phosphor-regulators/test/meson.build
+++ b/phosphor-regulators/test/meson.build
@@ -4,6 +4,7 @@
 )
 
 phosphor_regulators_tests_source_files = [
+    'configuration_tests.cpp',
     'device_tests.cpp',
     'id_map_tests.cpp',
     'pmbus_error_tests.cpp',