Add APIs for parsing BIOS configuration JSON
1) Add API to get the BIOS strings from the JSON configuration files.
2) Add API to parse the config file and setup the lookup data structures
for the BIOS attribute table and BIOS attribute value table.
3) Add API to get the possible values and the default values for the BIOS
enumeration type.
4) Add API to get the current value of the BIOS enumeration attribute.
5) BIOS attributes can be configured by JSON configuration files which have
information to build the BIOS string table, attribute table and attribute
value table.
Change-Id: I747dd3cfc0801f8262ffafe2d516ae7f4ddeb7a2
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/libpldmresponder/bios_parser.hpp b/libpldmresponder/bios_parser.hpp
new file mode 100644
index 0000000..0e21991
--- /dev/null
+++ b/libpldmresponder/bios_parser.hpp
@@ -0,0 +1,90 @@
+#pragma once
+
+#include <map>
+#include <string>
+#include <tuple>
+#include <variant>
+#include <vector>
+
+/*
+ * BIOS Parser API usage:
+ *
+ * 1) bios_parser::getStrings gets all the attribute names and the preconfigured
+ * strings used in representing the values of the attributes. This will be
+ * used to populate the BIOS String table.
+ *
+ * 2) bios_enum::setupValueLookup (similar API for other supported BIOS
+ * attribute types) has to be invoked to setup the lookup data structure for
+ * all the attributes of that type. This API needs to be invoked before
+ * invoking bios_enum::getValues and bios_enum::getAttrValue.
+ *
+ * 3) bios_enum::getValues is invoked to populate the BIOS attribute table for
+ * BIOSEnumeration and BIOSEnumerationReadonly types.(similar API for other
+ * BIOS attribute types)
+ *
+ * 4) bios_enum::getAttrValue will return the current values for the BIOS
+ * enumeration attribute. If there is no D-Bus mapping for the attribute then
+ * default value is returned.(similar API for other BIOS attribute types).
+ *
+ */
+
+namespace bios_parser
+{
+
+using Strings = std::vector<std::string>;
+
+/** @brief Parse every BIOS configuration JSON files in the directory path
+ * and populate all the attribute names and all the preconfigured
+ * strings used in representing the values of attributes.
+ *
+ * @param[in] dirPath - directory path where all the BIOS configuration JSON
+ * files exist.
+ *
+ * @return all the strings that should be populated in the BIOS string table
+ */
+Strings getStrings(const char* dirPath);
+
+namespace bios_enum
+{
+
+/** @brief Parse the JSON file specific to BIOSEnumeration and
+ * BIOSEnumerationReadOnly types and populate the data structure for
+ * the corresponding possible values and the default value. Setup the
+ * data structure to lookup the current value of the BIOS enumeration
+ * attribute. JSON is parsed once and the information is cached.
+ *
+ * @param[in] dirPath - directory path where all the BIOS configuration JSON
+ * exist
+ *
+ * @return 0 for success and negative return code for failure
+ */
+int setupValueLookup(const char* dirPath);
+
+using AttrName = std::string;
+using IsReadOnly = bool;
+using PossibleValues = std::vector<std::string>;
+using DefaultValues = std::vector<std::string>;
+using AttrValuesMap =
+ std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>;
+
+/** @brief Get the possible values and the default values for the
+ * BIOSEnumeration and BIOSEnumerationReadOnly types
+ *
+ * @return information needed to build the BIOS attribute table specific to
+ * BIOSEnumeration and BIOSEnumerationReadOnly types
+ */
+const AttrValuesMap& getValues();
+
+using CurrentValues = std::vector<std::string>;
+
+/** @brief Get the current values for the BIOS Attribute
+ *
+ * @param[in] attrName - BIOS attribute name
+ *
+ * @return BIOS attribute value
+ */
+CurrentValues getAttrValue(const AttrName& attrName);
+
+} // namespace bios_enum
+
+} // namespace bios_parser