1 #pragma once
2 
3 #include "bios_attribute.hpp"
4 
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <variant>
9 
10 class TestBIOSEnumAttribute;
11 
12 namespace pldm
13 {
14 namespace responder
15 {
16 namespace bios
17 {
18 
19 /** @class BIOSEnumAttribute
20  *  @brief Associate enum entry(attr table and attribute value table) and
21  *         dbus attribute
22  */
23 class 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     /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14
55      *  @param[in] attributevalue - attribute value(Enumeration, String and
56      *             Integer)
57      *  @param[in,out] attrValueEntry - attribute entry
58      */
59     void generateAttributeEntry(
60         const std::variant<int64_t, std::string>& attributevalue,
61         Table& attrValueEntry) override;
62 
63     int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType,
64                       const PropertyValue& newPropVal);
65 
66   private:
67     std::vector<std::string> possibleValues;
68     std::string defaultValue;
69 
70     /** @brief Get index of the given value in possible values
71      *  @param[in] value - The given value
72      *  @param[in] pVs - The possible values
73      *  @return Index of the given value in possible values
74      */
75     uint8_t getValueIndex(const std::string& value,
76                           const std::vector<std::string>& pVs);
77 
78     /** @brief Get handles of possible values
79      *  @param[in] stringTable - The bios string table
80      *  @param[in] pVs - The possible values
81      *  @return The handles
82      */
83     std::vector<uint16_t>
84         getPossibleValuesHandle(const BIOSStringTable& stringTable,
85                                 const std::vector<std::string>& pVs);
86 
87     using ValMap = std::map<PropertyValue, std::string>;
88 
89     /** @brief Map of value on dbus and pldm */
90     ValMap valMap;
91 
92     /** @brief Build the map of dbus value to pldm enum value
93      *  @param[in] dbusVals - The dbus values in the json's dbus section
94      */
95     void buildValMap(const Json& dbusVals);
96 
97     /** @brief Get index of the current value in possible values
98      *  @return The index of the current value in possible values
99      */
100     uint8_t getAttrValueIndex();
101 
102     /** @brief Get index of the property value in possible values
103      *  @param[in] propValue - property values
104      *
105      *  @return The index of the property value in possible values
106      */
107     uint8_t getAttrValueIndex(const PropertyValue& propValue);
108 };
109 
110 } // namespace bios
111 } // namespace responder
112 } // namespace pldm
113