blob: bc92e3c31cf0775fa0eea25cd1eecfb8a368f196 [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";
Tom Joseph52552ef2019-06-20 09:50:15 +053036
John Wange96e7e52019-10-05 17:47:30 +080037/** @brief Get all the preconfigured strings
38 * @return all the preconfigurated strings
Tom Joseph52552ef2019-06-20 09:50:15 +053039 */
John Wange96e7e52019-10-05 17:47:30 +080040const 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 */
45int setupConfig(const char* dirPath);
Tom Joseph52552ef2019-06-20 09:50:15 +053046
47namespace bios_enum
48{
49
Tom Joseph52552ef2019-06-20 09:50:15 +053050using AttrName = std::string;
51using IsReadOnly = bool;
52using PossibleValues = std::vector<std::string>;
53using DefaultValues = std::vector<std::string>;
54using 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 */
63const AttrValuesMap& getValues();
64
65using 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 */
73CurrentValues getAttrValue(const AttrName& attrName);
74
75} // namespace bios_enum
76
Carol Wang612f35b2019-08-26 17:14:26 +080077namespace bios_string
78{
79
Carol Wang612f35b2019-08-26 17:14:26 +080080using AttrName = std::string;
81using IsReadOnly = bool;
82using StrType = uint8_t;
83using MinStrLen = uint16_t;
84using MaxStrLen = uint16_t;
85using DefaultStrLen = uint16_t;
86using DefaultStr = std::string;
87using 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) */
94constexpr auto attrTableSize = 12;
95static_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 */
106const AttrValuesMap& getValues();
107
Carol Wangb503f9e2019-09-02 16:34:10 +0800108/** @brief Get the current values for the BIOS Attribute
109 *
110 * @param[in] attrName - BIOS attribute name
111 *
112 * @return BIOS attribute value
113 */
114std::string getAttrValue(const AttrName& attrName);
115
Carol Wang612f35b2019-08-26 17:14:26 +0800116} // namespace bios_string
117
Tom Joseph52552ef2019-06-20 09:50:15 +0530118} // namespace bios_parser