regulators: Implements support for and action
Enhance the configuration file parser to support the and action element.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I9099bf06606fb52ea7eaa374e2a2b1f924904d4f
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 64b6121..e458ba7 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -67,9 +67,8 @@
std::unique_ptr<Action> action{};
if (element.contains("and"))
{
- // TODO: Not implemented yet
- // action = parseAnd(element["and"]);
- // ++propertyCount;
+ action = parseAnd(element["and"]);
+ ++propertyCount;
}
else if (element.contains("compare_presence"))
{
@@ -176,6 +175,21 @@
return actions;
}
+std::unique_ptr<AndAction> parseAnd(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<AndAction>(std::move(actions));
+}
+
std::unique_ptr<Chassis> parseChassis(const json& element)
{
verifyIsObject(element);
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index b653c00..d81e403 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -16,6 +16,7 @@
#pragma once
#include "action.hpp"
+#include "and_action.hpp"
#include "chassis.hpp"
#include "configuration.hpp"
#include "device.hpp"
@@ -111,6 +112,18 @@
parseActionArray(const nlohmann::json& element);
/**
+ * Parses a JSON element containing an and action.
+ *
+ * Returns the corresponding C++ AndAction object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return AndAction object
+ */
+std::unique_ptr<AndAction> parseAnd(const nlohmann::json& element);
+
+/**
* Parses a JSON element containing a bit position (from 0-7).
*
* Returns the corresponding C++ uint8_t value.