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"; |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 36 | |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame^] | 37 | /** @brief Get all the preconfigured strings |
| 38 | * @return all the preconfigurated strings |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 39 | */ |
John Wang | e96e7e5 | 2019-10-05 17:47:30 +0800 | [diff] [blame^] | 40 | const Strings& getStrings(); |
| 41 | /** @brief Parse every BIOS Configuration JSON file in the directory path |
| 42 | * @param[in] dirPath - directory path where all the bios configuration JSON |
| 43 | * files exist |
| 44 | */ |
| 45 | int setupConfig(const char* dirPath); |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 46 | |
| 47 | namespace bios_enum |
| 48 | { |
| 49 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 50 | using AttrName = std::string; |
| 51 | using IsReadOnly = bool; |
| 52 | using PossibleValues = std::vector<std::string>; |
| 53 | using DefaultValues = std::vector<std::string>; |
| 54 | using AttrValuesMap = |
| 55 | std::map<AttrName, std::tuple<IsReadOnly, PossibleValues, DefaultValues>>; |
| 56 | |
| 57 | /** @brief Get the possible values and the default values for the |
| 58 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 59 | * |
| 60 | * @return information needed to build the BIOS attribute table specific to |
| 61 | * BIOSEnumeration and BIOSEnumerationReadOnly types |
| 62 | */ |
| 63 | const AttrValuesMap& getValues(); |
| 64 | |
| 65 | using CurrentValues = std::vector<std::string>; |
| 66 | |
| 67 | /** @brief Get the current values for the BIOS Attribute |
| 68 | * |
| 69 | * @param[in] attrName - BIOS attribute name |
| 70 | * |
| 71 | * @return BIOS attribute value |
| 72 | */ |
| 73 | CurrentValues getAttrValue(const AttrName& attrName); |
| 74 | |
| 75 | } // namespace bios_enum |
| 76 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 77 | namespace bios_string |
| 78 | { |
| 79 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 80 | using AttrName = std::string; |
| 81 | using IsReadOnly = bool; |
| 82 | using StrType = uint8_t; |
| 83 | using MinStrLen = uint16_t; |
| 84 | using MaxStrLen = uint16_t; |
| 85 | using DefaultStrLen = uint16_t; |
| 86 | using DefaultStr = std::string; |
| 87 | using AttrValuesMap = |
| 88 | std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen, |
| 89 | DefaultStrLen, DefaultStr>>; |
| 90 | /* attrTableSize is the sum of fixed length of members which construct a string |
| 91 | * attribute table, including attr_handle(uint16_t), attr_type(uint8_t), |
| 92 | * string_handle(uint16_t), strType(uint8_t), minStrLen(uint16_t), |
| 93 | * MaxStrLen(uint16_t), DefaultStrLen(uint16_t) */ |
| 94 | constexpr auto attrTableSize = 12; |
| 95 | static_assert(attrTableSize == sizeof(uint16_t) + sizeof(uint8_t) + |
| 96 | sizeof(uint16_t) + sizeof(uint8_t) + |
| 97 | sizeof(uint16_t) + sizeof(uint16_t) + |
| 98 | sizeof(uint16_t)); |
| 99 | |
| 100 | /** @brief Get the string related values and the default values for the |
| 101 | * BIOSString and BIOSStringReadOnly types |
| 102 | * |
| 103 | * @return information needed to build the BIOS attribute table specific to |
| 104 | * BIOSString and BIOSStringReadOnly types |
| 105 | */ |
| 106 | const AttrValuesMap& getValues(); |
| 107 | |
Carol Wang | b503f9e | 2019-09-02 16:34:10 +0800 | [diff] [blame] | 108 | /** @brief Get the current values for the BIOS Attribute |
| 109 | * |
| 110 | * @param[in] attrName - BIOS attribute name |
| 111 | * |
| 112 | * @return BIOS attribute value |
| 113 | */ |
| 114 | std::string getAttrValue(const AttrName& attrName); |
| 115 | |
Carol Wang | 612f35b | 2019-08-26 17:14:26 +0800 | [diff] [blame] | 116 | } // namespace bios_string |
| 117 | |
Tom Joseph | 52552ef | 2019-06-20 09:50:15 +0530 | [diff] [blame] | 118 | } // namespace bios_parser |