blob: 1f13f9457b781f6af62151e0899a657a4f79cd36 [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
92} // namespace bios_parser