blob: 2edbc955a15fb66a1206377902b147a3a69a59e8 [file] [log] [blame]
Tom Joseph52552ef2019-06-20 09:50:15 +05301#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
31namespace bios_parser
32{
33
34using Strings = std::vector<std::string>;
Carol Wangdc220c82019-08-26 13:31:31 +080035inline constexpr auto bIOSEnumJson = "enum_attrs.json";
36inline constexpr auto bIOSStrJson = "string_attrs.json";
Tom Joseph52552ef2019-06-20 09:50:15 +053037
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 */
47Strings getStrings(const char* dirPath);
48
49namespace 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 */
63int setupValueLookup(const char* dirPath);
64
65using AttrName = std::string;
66using IsReadOnly = bool;
67using PossibleValues = std::vector<std::string>;
68using DefaultValues = std::vector<std::string>;
69using 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 */
78const AttrValuesMap& getValues();
79
80using 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 */
88CurrentValues getAttrValue(const AttrName& attrName);
89
90} // namespace bios_enum
91
Carol Wang612f35b2019-08-26 17:14:26 +080092namespace 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 */
106int setupValueLookup(const char* dirPath);
107
108using AttrName = std::string;
109using IsReadOnly = bool;
110using StrType = uint8_t;
111using MinStrLen = uint16_t;
112using MaxStrLen = uint16_t;
113using DefaultStrLen = uint16_t;
114using DefaultStr = std::string;
115using 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) */
122constexpr auto attrTableSize = 12;
123static_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 */
134const AttrValuesMap& getValues();
135
136} // namespace bios_string
137
Tom Joseph52552ef2019-06-20 09:50:15 +0530138} // namespace bios_parser