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 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 31 | BIOSEnumAttribute(const Json& entry, |
| 32 | pldm::utils::DBusHandler* const dbusHandler); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 33 | |
| 34 | /** @brief Set Attribute value On Dbus according to the attribute value |
| 35 | * entry |
| 36 | * @param[in] attrValueEntry - The attribute value entry |
| 37 | * @param[in] attrEntry - The attribute entry corresponding to the |
| 38 | * attribute value entry |
| 39 | * @param[in] stringTable - The string table |
| 40 | */ |
| 41 | void |
| 42 | setAttrValueOnDbus(const pldm_bios_attr_val_table_entry* attrValueEntry, |
| 43 | const pldm_bios_attr_table_entry* attrEntry, |
| 44 | const BIOSStringTable& stringTable) override; |
| 45 | |
| 46 | /** @brief Construct corresponding entries at the end of the attribute table |
| 47 | * and attribute value tables |
| 48 | * @param[in] stringTable - The string Table |
| 49 | * @param[in,out] attrTable - The attribute table |
| 50 | * @param[in,out] attrValueTable - The attribute value table |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 51 | * @param[in,out] optAttributeValue - init value of the attribute |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 52 | */ |
| 53 | void constructEntry(const BIOSStringTable& stringTable, Table& attrTable, |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 54 | Table& attrValueTable, |
| 55 | std::optional<std::variant<int64_t, std::string>> |
| 56 | optAttributeValue = std::nullopt) override; |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 57 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 58 | /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14 |
| 59 | * @param[in] attributevalue - attribute value(Enumeration, String and |
| 60 | * Integer) |
| 61 | * @param[in,out] attrValueEntry - attribute entry |
| 62 | */ |
| 63 | void generateAttributeEntry( |
| 64 | const std::variant<int64_t, std::string>& attributevalue, |
| 65 | Table& attrValueEntry) override; |
| 66 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 67 | int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType, |
Pavithra Barithaya | 165749d | 2023-07-10 01:05:26 -0500 | [diff] [blame^] | 68 | const pldm::utils::PropertyValue& newPropVal) override; |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 69 | |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 70 | private: |
| 71 | std::vector<std::string> possibleValues; |
| 72 | std::string defaultValue; |
| 73 | |
| 74 | /** @brief Get index of the given value in possible values |
| 75 | * @param[in] value - The given value |
| 76 | * @param[in] pVs - The possible values |
| 77 | * @return Index of the given value in possible values |
| 78 | */ |
| 79 | uint8_t getValueIndex(const std::string& value, |
| 80 | const std::vector<std::string>& pVs); |
| 81 | |
| 82 | /** @brief Get handles of possible values |
| 83 | * @param[in] stringTable - The bios string table |
| 84 | * @param[in] pVs - The possible values |
| 85 | * @return The handles |
| 86 | */ |
| 87 | std::vector<uint16_t> |
| 88 | getPossibleValuesHandle(const BIOSStringTable& stringTable, |
| 89 | const std::vector<std::string>& pVs); |
| 90 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 91 | using ValMap = std::map<pldm::utils::PropertyValue, std::string>; |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 92 | |
| 93 | /** @brief Map of value on dbus and pldm */ |
| 94 | ValMap valMap; |
| 95 | |
| 96 | /** @brief Build the map of dbus value to pldm enum value |
| 97 | * @param[in] dbusVals - The dbus values in the json's dbus section |
| 98 | */ |
| 99 | void buildValMap(const Json& dbusVals); |
| 100 | |
| 101 | /** @brief Get index of the current value in possible values |
| 102 | * @return The index of the current value in possible values |
| 103 | */ |
| 104 | uint8_t getAttrValueIndex(); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 105 | |
| 106 | /** @brief Get index of the property value in possible values |
| 107 | * @param[in] propValue - property values |
| 108 | * |
| 109 | * @return The index of the property value in possible values |
| 110 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 111 | uint8_t getAttrValueIndex(const pldm::utils::PropertyValue& propValue); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace bios |
| 115 | } // namespace responder |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 116 | } // namespace pldm |