John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 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 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 54 | int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType, |
| 55 | const PropertyValue& newPropVal); |
| 56 | |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 57 | private: |
| 58 | std::vector<std::string> possibleValues; |
| 59 | std::string defaultValue; |
| 60 | |
| 61 | /** @brief Get index of the given value in possible values |
| 62 | * @param[in] value - The given value |
| 63 | * @param[in] pVs - The possible values |
| 64 | * @return Index of the given value in possible values |
| 65 | */ |
| 66 | uint8_t getValueIndex(const std::string& value, |
| 67 | const std::vector<std::string>& pVs); |
| 68 | |
| 69 | /** @brief Get handles of possible values |
| 70 | * @param[in] stringTable - The bios string table |
| 71 | * @param[in] pVs - The possible values |
| 72 | * @return The handles |
| 73 | */ |
| 74 | std::vector<uint16_t> |
| 75 | getPossibleValuesHandle(const BIOSStringTable& stringTable, |
| 76 | const std::vector<std::string>& pVs); |
| 77 | |
| 78 | using ValMap = std::map<PropertyValue, std::string>; |
| 79 | |
| 80 | /** @brief Map of value on dbus and pldm */ |
| 81 | ValMap valMap; |
| 82 | |
| 83 | /** @brief Build the map of dbus value to pldm enum value |
| 84 | * @param[in] dbusVals - The dbus values in the json's dbus section |
| 85 | */ |
| 86 | void buildValMap(const Json& dbusVals); |
| 87 | |
| 88 | /** @brief Get index of the current value in possible values |
| 89 | * @return The index of the current value in possible values |
| 90 | */ |
| 91 | uint8_t getAttrValueIndex(); |
| 92 | }; |
| 93 | |
| 94 | } // namespace bios |
| 95 | } // namespace responder |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 96 | } // namespace pldm |