regulators: Implements support for compare_vpd action
Enhance the configuration file parser to support the compare_vpd
action element.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: Ia8766a0d2f893898c5ff2655a757d60f7cdcc7df
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 7a3d497..11527b8 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -77,9 +77,8 @@
}
else if (element.contains("compare_vpd"))
{
- // TODO: Not implemented yet
- // action = parseCompareVPD(element["compare_vpd"]);
- // ++propertyCount;
+ action = parseCompareVPD(element["compare_vpd"]);
+ ++propertyCount;
}
else if (element.contains("i2c_compare_bit"))
{
@@ -252,6 +251,32 @@
return std::make_unique<ComparePresenceAction>(fru, value);
}
+std::unique_ptr<CompareVPDAction> parseCompareVPD(const json& element)
+{
+ verifyIsObject(element);
+ unsigned int propertyCount{0};
+
+ // Required fru property
+ const json& fruElement = getRequiredProperty(element, "fru");
+ std::string fru = parseString(fruElement);
+ ++propertyCount;
+
+ // Required keyword property
+ const json& keywordElement = getRequiredProperty(element, "keyword");
+ std::string keyword = parseString(keywordElement);
+ ++propertyCount;
+
+ // Required value property
+ const json& valueElement = getRequiredProperty(element, "value");
+ std::string value = parseString(valueElement);
+ ++propertyCount;
+
+ // Verify no invalid properties exist
+ verifyPropertyCount(element, propertyCount);
+
+ return std::make_unique<CompareVPDAction>(fru, keyword, value);
+}
+
std::unique_ptr<Configuration> parseConfiguration(const json& element)
{
verifyIsObject(element);
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index 706c609..205f43a 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -19,6 +19,7 @@
#include "and_action.hpp"
#include "chassis.hpp"
#include "compare_presence_action.hpp"
+#include "compare_vpd_action.hpp"
#include "configuration.hpp"
#include "device.hpp"
#include "i2c_compare_bit_action.hpp"
@@ -237,6 +238,19 @@
parseComparePresence(const nlohmann::json& element);
/**
+ * Parses a JSON element containing a compare_vpd action.
+ *
+ * Returns the corresponding C++ CompareVPDAction object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return CompareVPDAction object
+ */
+std::unique_ptr<CompareVPDAction>
+ parseCompareVPD(const nlohmann::json& element);
+
+/**
* Parses a JSON element containing a configuration.
*
* Returns the corresponding C++ Configuration object.