blob: 1757fc7f28fda1887d24215755c3aa655ab479a4 [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 *
John Wange96e7e52019-10-05 17:47:30 +080016 * 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 Joseph52552ef2019-06-20 09:50:15 +053019 *
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
30namespace bios_parser
31{
32
33using Strings = std::vector<std::string>;
Carol Wangdc220c82019-08-26 13:31:31 +080034inline constexpr auto bIOSEnumJson = "enum_attrs.json";
35inline constexpr auto bIOSStrJson = "string_attrs.json";
John Wangecb7d572019-10-17 13:38:53 +080036inline constexpr auto bIOSIntegerJson = "integer_attrs.json";
Tom Joseph52552ef2019-06-20 09:50:15 +053037
John Wange96e7e52019-10-05 17:47:30 +080038/** @brief Get all the preconfigured strings
39 * @return all the preconfigurated strings
Tom Joseph52552ef2019-06-20 09:50:15 +053040 */
John Wange96e7e52019-10-05 17:47:30 +080041const 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 */
46int setupConfig(const char* dirPath);
Tom Joseph52552ef2019-06-20 09:50:15 +053047
48namespace bios_enum
49{
50
Tom Joseph52552ef2019-06-20 09:50:15 +053051using AttrName = std::string;
52using IsReadOnly = bool;
53using PossibleValues = std::vector<std::string>;
54using DefaultValues = std::vector<std::string>;
55using 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 */
64const AttrValuesMap& getValues();
65
66using 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 */
74CurrentValues getAttrValue(const AttrName& attrName);
75
76} // namespace bios_enum
77
Carol Wang612f35b2019-08-26 17:14:26 +080078namespace bios_string
79{
80
Carol Wang612f35b2019-08-26 17:14:26 +080081using AttrName = std::string;
82using IsReadOnly = bool;
83using StrType = uint8_t;
84using MinStrLen = uint16_t;
85using MaxStrLen = uint16_t;
86using DefaultStrLen = uint16_t;
87using DefaultStr = std::string;
88using AttrValuesMap =
89 std::map<AttrName, std::tuple<IsReadOnly, StrType, MinStrLen, MaxStrLen,
90 DefaultStrLen, DefaultStr>>;
Carol Wang612f35b2019-08-26 17:14:26 +080091
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 */
98const AttrValuesMap& getValues();
99
Carol Wangb503f9e2019-09-02 16:34:10 +0800100/** @brief Get the current values for the BIOS Attribute
101 *
102 * @param[in] attrName - BIOS attribute name
103 *
104 * @return BIOS attribute value
105 */
106std::string getAttrValue(const AttrName& attrName);
107
Carol Wang612f35b2019-08-26 17:14:26 +0800108} // namespace bios_string
109
John Wangecb7d572019-10-17 13:38:53 +0800110namespace bios_integer
111{
112
113using AttrName = std::string;
114using IsReadOnly = bool;
115using LowerBound = uint64_t;
116using UpperBound = uint64_t;
117using ScalarIncrement = uint32_t;
118using DefaultValue = uint64_t;
119using AttrValues = std::tuple<IsReadOnly, LowerBound, UpperBound,
120 ScalarIncrement, DefaultValue>;
121
122constexpr auto AttrIsReadOnly = 0;
123constexpr auto AttrLowerBound = 1;
124constexpr auto AttrUpperBound = 2;
125constexpr auto AttrScalarIncrement = 3;
126constexpr auto AttrDefaultValue = 4;
127
128using 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 */
136const 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 */
144uint64_t getAttrValue(const AttrName& attrName);
145
146} // namespace bios_integer
147
Tom Joseph52552ef2019-06-20 09:50:15 +0530148} // namespace bios_parser