John Wang | 29683b5 | 2020-02-27 16:41:44 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "bios_attribute.hpp" |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | class TestBIOSStringAttribute; |
| 7 | |
| 8 | namespace pldm |
| 9 | { |
| 10 | namespace responder |
| 11 | { |
| 12 | namespace bios |
| 13 | { |
| 14 | |
| 15 | /** @class BIOSStringAttribute |
| 16 | * @brief Associate string entry(attr table and attribute value table) and dbus |
| 17 | * attribute |
| 18 | */ |
| 19 | class BIOSStringAttribute : public BIOSAttribute |
| 20 | { |
| 21 | public: |
| 22 | friend class ::TestBIOSStringAttribute; |
| 23 | |
| 24 | /** @brief BIOS string types */ |
| 25 | enum class Encoding : uint8_t |
| 26 | { |
| 27 | UNKNOWN = 0x00, |
| 28 | ASCII = 0x01, |
| 29 | HEX = 0x02, |
| 30 | UTF_8 = 0x03, |
| 31 | UTF_16LE = 0x04, |
| 32 | UTF_16BE = 0x05, |
| 33 | VENDOR_SPECIFIC = 0xFF |
| 34 | }; |
| 35 | |
| 36 | /** brief Mapping of string to enum for string type */ |
| 37 | inline static const std::map<std::string, Encoding> strTypeMap{ |
| 38 | {"Unknown", Encoding::UNKNOWN}, |
| 39 | {"ASCII", Encoding::ASCII}, |
| 40 | {"Hex", Encoding::HEX}, |
| 41 | {"UTF-8", Encoding::UTF_8}, |
| 42 | {"UTF-16LE", Encoding::UTF_16LE}, |
| 43 | {"UTF-16LE", Encoding::UTF_16LE}, |
| 44 | {"Vendor Specific", Encoding::VENDOR_SPECIFIC}}; |
| 45 | |
| 46 | /** @brief Construct a bios string attribute |
| 47 | * @param[in] entry - Json Object |
| 48 | * @param[in] dbusHandler - Dbus Handler |
| 49 | */ |
| 50 | BIOSStringAttribute(const Json& entry, DBusHandler* const dbusHandler); |
| 51 | |
| 52 | /** @brief Set Attribute value On Dbus according to the attribute value |
| 53 | * entry |
| 54 | * @param[in] attrValueEntry - The attribute value entry |
| 55 | * @param[in] attrEntry - The attribute entry corresponding to the |
| 56 | * attribute value entry |
| 57 | * @param[in] stringTable - The string table |
| 58 | */ |
| 59 | void |
| 60 | setAttrValueOnDbus(const pldm_bios_attr_val_table_entry* attrValueEntry, |
| 61 | const pldm_bios_attr_table_entry* attrEntry, |
| 62 | const BIOSStringTable& stringTable) override; |
| 63 | |
| 64 | /** @brief Construct corresponding entries at the end of the attribute table |
| 65 | * and attribute value tables |
| 66 | * @param[in] stringTable - The string Table |
| 67 | * @param[in,out] attrTable - The attribute table |
| 68 | * @param[in,out] attrValueTable - The attribute value table |
| 69 | */ |
| 70 | void constructEntry(const BIOSStringTable& stringTable, Table& attrTable, |
| 71 | Table& attrValueTable) override; |
| 72 | |
| 73 | private: |
| 74 | /** @brief string field from json */ |
| 75 | table::attribute::StringField stringInfo; |
| 76 | |
| 77 | /** @brief Get attribute value on dbus */ |
| 78 | std::string getAttrValue(); |
| 79 | }; |
| 80 | |
| 81 | } // namespace bios |
| 82 | } // namespace responder |
| 83 | } // namespace pldm |