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 * @param[in,out] optAttributeValue - init value of the attribute 51 */ 52 void constructEntry(const BIOSStringTable& stringTable, Table& attrTable, 53 Table& attrValueTable, 54 std::optional<std::variant<int64_t, std::string>> 55 optAttributeValue = std::nullopt) override; 56 57 /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14 58 * @param[in] attributevalue - attribute value(Enumeration, String and 59 * Integer) 60 * @param[in,out] attrValueEntry - attribute entry 61 */ 62 void generateAttributeEntry( 63 const std::variant<int64_t, std::string>& attributevalue, 64 Table& attrValueEntry) override; 65 66 int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType, 67 const PropertyValue& newPropVal); 68 69 private: 70 std::vector<std::string> possibleValues; 71 std::string defaultValue; 72 73 /** @brief Get index of the given value in possible values 74 * @param[in] value - The given value 75 * @param[in] pVs - The possible values 76 * @return Index of the given value in possible values 77 */ 78 uint8_t getValueIndex(const std::string& value, 79 const std::vector<std::string>& pVs); 80 81 /** @brief Get handles of possible values 82 * @param[in] stringTable - The bios string table 83 * @param[in] pVs - The possible values 84 * @return The handles 85 */ 86 std::vector<uint16_t> 87 getPossibleValuesHandle(const BIOSStringTable& stringTable, 88 const std::vector<std::string>& pVs); 89 90 using ValMap = std::map<PropertyValue, std::string>; 91 92 /** @brief Map of value on dbus and pldm */ 93 ValMap valMap; 94 95 /** @brief Build the map of dbus value to pldm enum value 96 * @param[in] dbusVals - The dbus values in the json's dbus section 97 */ 98 void buildValMap(const Json& dbusVals); 99 100 /** @brief Get index of the current value in possible values 101 * @return The index of the current value in possible values 102 */ 103 uint8_t getAttrValueIndex(); 104 105 /** @brief Get index of the property value in possible values 106 * @param[in] propValue - property values 107 * 108 * @return The index of the property value in possible values 109 */ 110 uint8_t getAttrValueIndex(const PropertyValue& propValue); 111 }; 112 113 } // namespace bios 114 } // namespace responder 115 } // namespace pldm 116