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 | * |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 16 | * 2) bios_parser::setupConfig has to be invoked to setup the lookup data |
| 17 | * structure all the attributes of that type. This API needs to be invoked |
| 18 | * before invoking bios_enum::getValues and bios_enum::getAttrValue. |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 19 | * |
| 20 | * 3) bios_enum::getValues is invoked to populate the BIOS attribute table for |
| 21 | * BIOSEnumeration and BIOSEnumerationReadonly types.(similar API for other |
| 22 | * BIOS attribute types) |
| 23 | * |
| 24 | * 4) bios_enum::getAttrValue will return the current values for the BIOS |
| 25 | * enumeration attribute. If there is no D-Bus mapping for the attribute then |
| 26 | * default value is returned.(similar API for other BIOS attribute types). |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | namespace bios_parser |
| 31 | { |
| 32 | |
| 33 | using Strings = std::vector<std::string>; |
Carol Wang | dc220c8 | 2019-08-26 13:31:31 +0800 | [diff] [blame] | 34 | inline constexpr auto bIOSEnumJson = "enum_attrs.json"; |
| 35 | inline constexpr auto bIOSStrJson = "string_attrs.json"; |
John Wang | ecb7d57 | 2019-10-17 13:38:53 +0800 | [diff] [blame] | 36 | inline constexpr auto bIOSIntegerJson = "integer_attrs.json"; |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 37 | |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 38 | /** @brief Get all the preconfigured strings |
| 39 | * @return all the preconfigurated strings |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 40 | */ |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame] | 41 | const Strings& getStrings(); |
| 42 | /** @brief Parse every BIOS Configuration JSON file in the directory path |
| 43 | * @param[in] dirPath - directory path where all the bios configuration JSON |
| 44 | * files exist |
| 45 | */ |
| 46 | int setupConfig(const char* dirPath); |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 47 | |
| 48 | namespace bios_enum |
| 49 | { |
| 50 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 51 | using AttrName = std::string; |
| 52 | using IsReadOnly = bool; |
| 53 | using PossibleValues = std::vector<std::string>; |
| 54 | using DefaultValues = std::vector<std::string>; |
| 55 | using AttrValuesMap = |
| 56 | std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>; |
| 57 | |
| 58 | /** @brief Get the possible values and the default values for the |
| 59 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 60 | * |
| 61 | * @return information needed to build the BIOS attribute table specific to |
| 62 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 63 | */ |
| 64 | const AttrValuesMap& getValues(); |
| 65 | |
| 66 | using CurrentValues = std::vector<std::string>; |
| 67 | |
| 68 | /** @brief Get the current values for the BIOS Attribute |
| 69 | * |
| 70 | * @param[in] attrName - BIOS attribute name |
| 71 | * |
| 72 | * @return BIOS attribute value |
| 73 | */ |
| 74 | CurrentValues getAttrValue(const AttrName& attrName); |
| 75 | |
| 76 | } // namespace bios_enum |
| 77 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 78 | namespace bios_string |
| 79 | { |
| 80 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 81 | using AttrName = std::string; |
| 82 | using IsReadOnly = bool; |
| 83 | using StrType = uint8_t; |
| 84 | using MinStrLen = uint16_t; |
| 85 | using MaxStrLen = uint16_t; |
| 86 | using DefaultStrLen = uint16_t; |
| 87 | using DefaultStr = std::string; |
| 88 | using AttrValuesMap = |
| 89 | std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen, |
| 90 | DefaultStrLen, DefaultStr>>; |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 91 | |
| 92 | /** @brief Get the string related values and the default values for the |
| 93 | * BIOSString and BIOSStringReadOnly types |
| 94 | * |
| 95 | * @return information needed to build the BIOS attribute table specific to |
| 96 | * BIOSString and BIOSStringReadOnly types |
| 97 | */ |
| 98 | const AttrValuesMap& getValues(); |
| 99 | |
Carol Wang | b503f9e | 2019-09-02 16:34:10 +0800 | [diff] [blame] | 100 | /** @brief Get the current values for the BIOS Attribute |
| 101 | * |
| 102 | * @param[in] attrName - BIOS attribute name |
| 103 | * |
| 104 | * @return BIOS attribute value |
| 105 | */ |
| 106 | std::string getAttrValue(const AttrName& attrName); |
| 107 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 108 | } // namespace bios_string |
| 109 | |
John Wang | ecb7d57 | 2019-10-17 13:38:53 +0800 | [diff] [blame] | 110 | namespace bios_integer |
| 111 | { |
| 112 | |
| 113 | using AttrName = std::string; |
| 114 | using IsReadOnly = bool; |
| 115 | using LowerBound = uint64_t; |
| 116 | using UpperBound = uint64_t; |
| 117 | using ScalarIncrement = uint32_t; |
| 118 | using DefaultValue = uint64_t; |
| 119 | using AttrValues = std::tuple<IsReadOnly, LowerBound, UpperBound, |
| 120 | ScalarIncrement, DefaultValue>; |
| 121 | |
| 122 | constexpr auto AttrIsReadOnly = 0; |
| 123 | constexpr auto AttrLowerBound = 1; |
| 124 | constexpr auto AttrUpperBound = 2; |
| 125 | constexpr auto AttrScalarIncrement = 3; |
| 126 | constexpr auto AttrDefaultValue = 4; |
| 127 | |
| 128 | using AttrValuesMap = std::map<AttrName, AttrValues>; |
| 129 | |
| 130 | /** @brief Get the values of all fields for the |
| 131 | * BIOSInteger and BIOSIntegerReadOnly types |
| 132 | * |
| 133 | * @return information needed to build the BIOS attribute table specific to |
| 134 | * BIOSInteger and BIOSIntegerReadOnly types |
| 135 | */ |
| 136 | const AttrValuesMap& getValues(); |
| 137 | |
| 138 | /** @brief Get the current values for the BIOS Attribute |
| 139 | * |
| 140 | * @param[in] attrName - BIOS attribute name |
| 141 | * |
| 142 | * @return BIOS attribute value |
| 143 | */ |
| 144 | uint64_t getAttrValue(const AttrName& attrName); |
| 145 | |
| 146 | } // namespace bios_integer |
| 147 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 148 | } // namespace bios_parser |