Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <string> |
| 5 | #include <tuple> |
| 6 | #include <variant> |
| 7 | #include <vector> |
| 8 | |
| 9 | /* |
| 10 | * BIOS Parser API usage: |
| 11 | * |
| 12 | * 1) bios_parser::getStrings gets all the attribute names and the preconfigured |
| 13 | * strings used in representing the values of the attributes. This will be |
| 14 | * used to populate the BIOS String table. |
| 15 | * |
| 16 | * 2) bios_enum::setupValueLookup (similar API for other supported BIOS |
| 17 | * attribute types) has to be invoked to setup the lookup data structure for |
| 18 | * all the attributes of that type. This API needs to be invoked before |
| 19 | * invoking bios_enum::getValues and bios_enum::getAttrValue. |
| 20 | * |
| 21 | * 3) bios_enum::getValues is invoked to populate the BIOS attribute table for |
| 22 | * BIOSEnumeration and BIOSEnumerationReadonly types.(similar API for other |
| 23 | * BIOS attribute types) |
| 24 | * |
| 25 | * 4) bios_enum::getAttrValue will return the current values for the BIOS |
| 26 | * enumeration attribute. If there is no D-Bus mapping for the attribute then |
| 27 | * default value is returned.(similar API for other BIOS attribute types). |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | namespace bios_parser |
| 32 | { |
| 33 | |
| 34 | using Strings = std::vector<std::string>; |
| 35 | |
| 36 | /** @brief Parse every BIOS configuration JSON files in the directory path |
| 37 | * and populate all the attribute names and all the preconfigured |
| 38 | * strings used in representing the values of attributes. |
| 39 | * |
| 40 | * @param[in] dirPath - directory path where all the BIOS configuration JSON |
| 41 | * files exist. |
| 42 | * |
| 43 | * @return all the strings that should be populated in the BIOS string table |
| 44 | */ |
| 45 | Strings getStrings(const char* dirPath); |
| 46 | |
| 47 | namespace bios_enum |
| 48 | { |
| 49 | |
| 50 | /** @brief Parse the JSON file specific to BIOSEnumeration and |
| 51 | * BIOSEnumerationReadOnly types and populate the data structure for |
| 52 | * the corresponding possible values and the default value. Setup the |
| 53 | * data structure to lookup the current value of the BIOS enumeration |
| 54 | * attribute. JSON is parsed once and the information is cached. |
| 55 | * |
| 56 | * @param[in] dirPath - directory path where all the BIOS configuration JSON |
| 57 | * exist |
| 58 | * |
| 59 | * @return 0 for success and negative return code for failure |
| 60 | */ |
| 61 | int setupValueLookup(const char* dirPath); |
| 62 | |
| 63 | using AttrName = std::string; |
| 64 | using IsReadOnly = bool; |
| 65 | using PossibleValues = std::vector<std::string>; |
| 66 | using DefaultValues = std::vector<std::string>; |
| 67 | using AttrValuesMap = |
| 68 | std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>; |
| 69 | |
| 70 | /** @brief Get the possible values and the default values for the |
| 71 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 72 | * |
| 73 | * @return information needed to build the BIOS attribute table specific to |
| 74 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 75 | */ |
| 76 | const AttrValuesMap& getValues(); |
| 77 | |
| 78 | using CurrentValues = std::vector<std::string>; |
| 79 | |
| 80 | /** @brief Get the current values for the BIOS Attribute |
| 81 | * |
| 82 | * @param[in] attrName - BIOS attribute name |
| 83 | * |
| 84 | * @return BIOS attribute value |
| 85 | */ |
| 86 | CurrentValues getAttrValue(const AttrName& attrName); |
| 87 | |
| 88 | } // namespace bios_enum |
| 89 | |
| 90 | } // namespace bios_parser |