blob: a798804d553af7214728fb9b8e68fb40320e137c [file] [log] [blame]
John Wang3be70852020-02-13 15:59:04 +08001#pragma once
2
3#include "bios_attribute.hpp"
4
5#include <map>
6#include <set>
7#include <string>
8#include <variant>
9
10class TestBIOSEnumAttribute;
11
12namespace pldm
13{
14namespace responder
15{
16namespace bios
17{
18
19/** @class BIOSEnumAttribute
20 * @brief Associate enum entry(attr table and attribute value table) and
21 * dbus attribute
22 */
23class 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 Bishop5079ac42021-08-19 18:35:06 -040031 BIOSEnumAttribute(const Json& entry,
32 pldm::utils::DBusHandler* const dbusHandler);
John Wang3be70852020-02-13 15:59:04 +080033
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 Josephca7b2522020-11-18 12:27:11 +053051 * @param[in,out] optAttributeValue - init value of the attribute
John Wang3be70852020-02-13 15:59:04 +080052 */
53 void constructEntry(const BIOSStringTable& stringTable, Table& attrTable,
Tom Josephca7b2522020-11-18 12:27:11 +053054 Table& attrValueTable,
55 std::optional<std::variant<int64_t, std::string>>
56 optAttributeValue = std::nullopt) override;
John Wang3be70852020-02-13 15:59:04 +080057
George Liu1244acf2020-08-14 09:11:11 +080058 /** @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 Misra46ece062020-03-18 07:17:44 -050067 int updateAttrVal(Table& newValue, uint16_t attrHdl, uint8_t attrType,
Brad Bishop5079ac42021-08-19 18:35:06 -040068 const pldm::utils::PropertyValue& newPropVal);
Sampa Misra46ece062020-03-18 07:17:44 -050069
John Wang3be70852020-02-13 15:59:04 +080070 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 Bishop5079ac42021-08-19 18:35:06 -040091 using ValMap = std::map<pldm::utils::PropertyValue, std::string>;
John Wang3be70852020-02-13 15:59:04 +080092
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 Liu1244acf2020-08-14 09:11:11 +0800105
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 Bishop5079ac42021-08-19 18:35:06 -0400111 uint8_t getAttrValueIndex(const pldm::utils::PropertyValue& propValue);
John Wang3be70852020-02-13 15:59:04 +0800112};
113
114} // namespace bios
115} // namespace responder
Sampa Misra46ece062020-03-18 07:17:44 -0500116} // namespace pldm