blob: 2d8667a31b370345a7a30a80fe83f896a86ef3b4 [file] [log] [blame]
John Wang3be70852020-02-13 15:59:04 +08001#pragma once
2
3#include "bios_attribute.hpp"
4
5#include <map>
6#include <set>
7#include <string>
8#include <variant>
9
10class TestBIOSEnumAttribute;
11
12namespace pldm
13{
14namespace responder
15{
16namespace bios
17{
18
19/** @class BIOSEnumAttribute
20 * @brief Associate enum entry(attr table and attribute value table) and
21 * dbus attribute
22 */
23class BIOSEnumAttribute : public BIOSAttribute
24{
25 public:
26 friend class ::TestBIOSEnumAttribute;
27 /** @brief Construct a bios enum attribute
28 * @param[in] entry - Json Object
29 * @param[in] dbusHandler - Dbus Handler
30 */
31 BIOSEnumAttribute(const Json& entry, DBusHandler* const dbusHandler);
32
33 /** @brief Set Attribute value On Dbus according to the attribute value
34 * entry
35 * @param[in] attrValueEntry - The attribute value entry
36 * @param[in] attrEntry - The attribute entry corresponding to the
37 * attribute value entry
38 * @param[in] stringTable - The string table
39 */
40 void
41 setAttrValueOnDbus(const pldm_bios_attr_val_table_entry* attrValueEntry,
42 const pldm_bios_attr_table_entry* attrEntry,
43 const BIOSStringTable& stringTable) override;
44
45 /** @brief Construct corresponding entries at the end of the attribute table
46 * and attribute value tables
47 * @param[in] stringTable - The string Table
48 * @param[in,out] attrTable - The attribute table
49 * @param[in,out] attrValueTable - The attribute value table
50 */
51 void constructEntry(const BIOSStringTable& stringTable, Table& attrTable,
52 Table& attrValueTable) override;
53
54 private:
55 std::vector<std::string> possibleValues;
56 std::string defaultValue;
57
58 /** @brief Get index of the given value in possible values
59 * @param[in] value - The given value
60 * @param[in] pVs - The possible values
61 * @return Index of the given value in possible values
62 */
63 uint8_t getValueIndex(const std::string& value,
64 const std::vector<std::string>& pVs);
65
66 /** @brief Get handles of possible values
67 * @param[in] stringTable - The bios string table
68 * @param[in] pVs - The possible values
69 * @return The handles
70 */
71 std::vector<uint16_t>
72 getPossibleValuesHandle(const BIOSStringTable& stringTable,
73 const std::vector<std::string>& pVs);
74
75 using ValMap = std::map<PropertyValue, std::string>;
76
77 /** @brief Map of value on dbus and pldm */
78 ValMap valMap;
79
80 /** @brief Build the map of dbus value to pldm enum value
81 * @param[in] dbusVals - The dbus values in the json's dbus section
82 */
83 void buildValMap(const Json& dbusVals);
84
85 /** @brief Get index of the current value in possible values
86 * @return The index of the current value in possible values
87 */
88 uint8_t getAttrValueIndex();
89};
90
91} // namespace bios
92} // namespace responder
93} // namespace pldm