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);