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>; |
Carol Wang | dc220c8 | 2019-08-26 13:31:31 +0800 | [diff] [blame] | 35 | inline constexpr auto bIOSEnumJson = "enum_attrs.json"; |
| 36 | inline constexpr auto bIOSStrJson = "string_attrs.json"; |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 37 | |
| 38 | /** @brief Parse every BIOS configuration JSON files in the directory path |
| 39 | * and populate all the attribute names and all the preconfigured |
| 40 | * strings used in representing the values of attributes. |
| 41 | * |
| 42 | * @param[in] dirPath - directory path where all the BIOS configuration JSON |
| 43 | * files exist. |
| 44 | * |
| 45 | * @return all the strings that should be populated in the BIOS string table |
| 46 | */ |
| 47 | Strings getStrings(const char* dirPath); |
| 48 | |
| 49 | namespace bios_enum |
| 50 | { |
| 51 | |
| 52 | /** @brief Parse the JSON file specific to BIOSEnumeration and |
| 53 | * BIOSEnumerationReadOnly types and populate the data structure for |
| 54 | * the corresponding possible values and the default value. Setup the |
| 55 | * data structure to lookup the current value of the BIOS enumeration |
| 56 | * attribute. JSON is parsed once and the information is cached. |
| 57 | * |
| 58 | * @param[in] dirPath - directory path where all the BIOS configuration JSON |
| 59 | * exist |
| 60 | * |
| 61 | * @return 0 for success and negative return code for failure |
| 62 | */ |
| 63 | int setupValueLookup(const char* dirPath); |
| 64 | |
| 65 | using AttrName = std::string; |
| 66 | using IsReadOnly = bool; |
| 67 | using PossibleValues = std::vector<std::string>; |
| 68 | using DefaultValues = std::vector<std::string>; |
| 69 | using AttrValuesMap = |
| 70 | std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>; |
| 71 | |
| 72 | /** @brief Get the possible values and the default values for the |
| 73 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 74 | * |
| 75 | * @return information needed to build the BIOS attribute table specific to |
| 76 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 77 | */ |
| 78 | const AttrValuesMap& getValues(); |
| 79 | |
| 80 | using CurrentValues = std::vector<std::string>; |
| 81 | |
| 82 | /** @brief Get the current values for the BIOS Attribute |
| 83 | * |
| 84 | * @param[in] attrName - BIOS attribute name |
| 85 | * |
| 86 | * @return BIOS attribute value |
| 87 | */ |
| 88 | CurrentValues getAttrValue(const AttrName& attrName); |
| 89 | |
| 90 | } // namespace bios_enum |
| 91 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame^] | 92 | namespace bios_string |
| 93 | { |
| 94 | |
| 95 | /** @brief Parse the JSON file specific to BIOSString and |
| 96 | * BIOSStringReadOnly types and populate the data structure for |
| 97 | * the corresponding possible values and the default value. Setup the |
| 98 | * data structure to lookup the current value of the BIOS string |
| 99 | * attribute. JSON is parsed once and the information is cached. |
| 100 | * |
| 101 | * @param[in] dirPath - directory path where all the BIOS configuration JSON |
| 102 | * exist |
| 103 | * |
| 104 | * @return 0 for success and negative return code for failure |
| 105 | */ |
| 106 | int setupValueLookup(const char* dirPath); |
| 107 | |
| 108 | using AttrName = std::string; |
| 109 | using IsReadOnly = bool; |
| 110 | using StrType = uint8_t; |
| 111 | using MinStrLen = uint16_t; |
| 112 | using MaxStrLen = uint16_t; |
| 113 | using DefaultStrLen = uint16_t; |
| 114 | using DefaultStr = std::string; |
| 115 | using AttrValuesMap = |
| 116 | std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen, |
| 117 | DefaultStrLen, DefaultStr>>; |
| 118 | /* attrTableSize is the sum of fixed length of members which construct a string |
| 119 | * attribute table, including attr_handle(uint16_t), attr_type(uint8_t), |
| 120 | * string_handle(uint16_t), strType(uint8_t), minStrLen(uint16_t), |
| 121 | * MaxStrLen(uint16_t), DefaultStrLen(uint16_t) */ |
| 122 | constexpr auto attrTableSize = 12; |
| 123 | static_assert(attrTableSize == sizeof(uint16_t) + sizeof(uint8_t) + |
| 124 | sizeof(uint16_t) + sizeof(uint8_t) + |
| 125 | sizeof(uint16_t) + sizeof(uint16_t) + |
| 126 | sizeof(uint16_t)); |
| 127 | |
| 128 | /** @brief Get the string related values and the default values for the |
| 129 | * BIOSString and BIOSStringReadOnly types |
| 130 | * |
| 131 | * @return information needed to build the BIOS attribute table specific to |
| 132 | * BIOSString and BIOSStringReadOnly types |
| 133 | */ |
| 134 | const AttrValuesMap& getValues(); |
| 135 | |
| 136 | } // namespace bios_string |
| 137 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 138 | } // namespace bios_parser |