regulators: Implements support for or action

Enhance the configuration file parser to support the or action element.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I6e6dee26c23a2ea414e96a0cda3525b91b806509
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 5f0181e..8c6dc12 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -125,9 +125,8 @@
     }
     else if (element.contains("or"))
     {
-        // TODO: Not implemented yet
-        // action = parseOr(element["or"]);
-        // ++propertyCount;
+        action = parseOr(element["or"]);
+        ++propertyCount;
     }
     else if (element.contains("pmbus_read_sensor"))
     {
@@ -583,6 +582,21 @@
     return std::make_unique<NotAction>(std::move(action));
 }
 
+std::unique_ptr<OrAction> parseOr(const json& element)
+{
+    verifyIsArray(element);
+
+    // Verify if array size less than 2
+    if (element.size() < 2)
+    {
+        throw std::invalid_argument{"Array must contain two or more actions"};
+    }
+    // Array of two or more actions
+    std::vector<std::unique_ptr<Action>> actions = parseActionArray(element);
+
+    return std::make_unique<OrAction>(std::move(actions));
+}
+
 std::unique_ptr<PMBusWriteVoutCommandAction>
     parsePMBusWriteVoutCommand(const json& element)
 {
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index e2476a2..7104356 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -28,6 +28,7 @@
 #include "i2c_write_byte_action.hpp"
 #include "i2c_write_bytes_action.hpp"
 #include "not_action.hpp"
+#include "or_action.hpp"
 #include "pmbus_write_vout_command_action.hpp"
 #include "presence_detection.hpp"
 #include "rail.hpp"
@@ -453,6 +454,18 @@
 std::unique_ptr<NotAction> parseNot(const nlohmann::json& element);
 
 /**
+ * Parses a JSON element containing an or action.
+ *
+ * Returns the corresponding C++ OrAction object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return OrAction object
+ */
+std::unique_ptr<OrAction> parseOr(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing a pmbus_write_vout_command action.
  *
  * Returns the corresponding C++ PMBusWriteVoutCommandAction object.