blob: e26a32aa67e5b588afb56bb38e28395693ab2833 [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,
Pavithra Barithaya165749d2023-07-10 01:05:26 -050068 const pldm::utils::PropertyValue& newPropVal) override;
Sampa Misra46ece062020-03-18 07:17:44 -050069
John Wang3be70852020-02-13 15:59:04 +080070 private:
71 std::vector<std::string> possibleValues;
Sagar Srinivas7927f902023-10-09 07:53:00 -050072 std::vector<std::string> valueDisplayNames;
John Wang3be70852020-02-13 15:59:04 +080073 std::string defaultValue;
74
75 /** @brief Get index of the given value in possible values
76 * @param[in] value - The given value
77 * @param[in] pVs - The possible values
78 * @return Index of the given value in possible values
79 */
80 uint8_t getValueIndex(const std::string& value,
81 const std::vector<std::string>& pVs);
82
83 /** @brief Get handles of possible values
84 * @param[in] stringTable - The bios string table
85 * @param[in] pVs - The possible values
86 * @return The handles
87 */
88 std::vector<uint16_t>
89 getPossibleValuesHandle(const BIOSStringTable& stringTable,
90 const std::vector<std::string>& pVs);
91
Sagar Srinivas7927f902023-10-09 07:53:00 -050092 /** @brief Method to populate the valueDisplayNamesMap
93 * @param[in] attrHandle - attribute handle
94 */
95 void populateValueDisplayNamesMap(uint16_t attrHandle);
96
Brad Bishop5079ac42021-08-19 18:35:06 -040097 using ValMap = std::map<pldm::utils::PropertyValue, std::string>;
John Wang3be70852020-02-13 15:59:04 +080098
99 /** @brief Map of value on dbus and pldm */
100 ValMap valMap;
101
102 /** @brief Build the map of dbus value to pldm enum value
103 * @param[in] dbusVals - The dbus values in the json's dbus section
104 */
105 void buildValMap(const Json& dbusVals);
106
107 /** @brief Get index of the current value in possible values
108 * @return The index of the current value in possible values
109 */
110 uint8_t getAttrValueIndex();
George Liu1244acf2020-08-14 09:11:11 +0800111
112 /** @brief Get index of the property value in possible values
113 * @param[in] propValue - property values
114 *
115 * @return The index of the property value in possible values
116 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400117 uint8_t getAttrValueIndex(const pldm::utils::PropertyValue& propValue);
John Wang3be70852020-02-13 15:59:04 +0800118};
119
120} // namespace bios
121} // namespace responder
Sampa Misra46ece062020-03-18 07:17:44 -0500122} // namespace pldm