blob: 5132841d35bd2f5dd7b63512778a1b422551a9ad [file] [log] [blame]
John Wang29683b52020-02-27 16:41:44 +08001#pragma once
2#include "bios_attribute.hpp"
3
4#include <string>
5
6class TestBIOSStringAttribute;
7
8namespace pldm
9{
10namespace responder
11{
12namespace bios
13{
14
15/** @class BIOSStringAttribute
16 * @brief Associate string entry(attr table and attribute value table) and dbus
17 * attribute
18 */
19class 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 */
Brad Bishop5079ac42021-08-19 18:35:06 -040050 BIOSStringAttribute(const Json& entry,
51 pldm::utils::DBusHandler* const dbusHandler);
John Wang29683b52020-02-27 16:41:44 +080052
53 /** @brief Set Attribute value On Dbus according to the attribute value
54 * entry
55 * @param[in] attrValueEntry - The attribute value entry
56 * @param[in] attrEntry - The attribute entry corresponding to the
57 * attribute value entry
58 * @param[in] stringTable - The string table
59 */
60 void
61 setAttrValueOnDbus(const pldm_bios_attr_val_table_entry* attrValueEntry,
62 const pldm_bios_attr_table_entry* attrEntry,
63 const BIOSStringTable& stringTable) override;
64
65 /** @brief Construct corresponding entries at the end of the attribute table
66 * and attribute value tables
67 * @param[in] stringTable - The string Table
68 * @param[in,out] attrTable - The attribute table
69 * @param[in,out] attrValueTable - The attribute value table
Tom Josephca7b2522020-11-18 12:27:11 +053070 * @param[in,out] optAttributeValue - init value of the attribute
John Wang29683b52020-02-27 16:41:44 +080071 */
72 void constructEntry(const BIOSStringTable& stringTable, Table& attrTable,
Tom Josephca7b2522020-11-18 12:27:11 +053073 Table& attrValueTable,
74 std::optional<std::variant<int64_t, std::string>>
75 optAttributeValue = std::nullopt) override;
John Wang29683b52020-02-27 16:41:44 +080076
George Liu1244acf2020-08-14 09:11:11 +080077 /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14
78 * @param[in] attributevalue - attribute value(Enumeration, String and
79 * Integer)
80 * @param[in,out] attrValueEntry - attribute entry
81 */
82 void generateAttributeEntry(
83 const std::variant<int64_t, std::string>& attributevalue,
84 Table& attrValueEntry) override;
85
Sampa Misra46ece062020-03-18 07:17:44 -050086 int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType,
Brad Bishop5079ac42021-08-19 18:35:06 -040087 const pldm::utils::PropertyValue& newPropVal);
Sampa Misra46ece062020-03-18 07:17:44 -050088
John Wang29683b52020-02-27 16:41:44 +080089 private:
90 /** @brief string field from json */
91 table::attribute::StringField stringInfo;
92
93 /** @brief Get attribute value on dbus */
94 std::string getAttrValue();
95};
96
97} // namespace bios
98} // namespace responder
99} // namespace pldm