1 #pragma once
2 
3 #include "bios_table.hpp"
4 #include "common/utils.hpp"
5 
6 #include <libpldm/bios_table.h>
7 
8 #include <nlohmann/json.hpp>
9 
10 #include <cstdint>
11 #include <filesystem>
12 #include <memory>
13 #include <optional>
14 #include <string>
15 #include <vector>
16 
17 namespace pldm
18 {
19 namespace responder
20 {
21 namespace bios
22 {
23 
24 using Json = nlohmann::json;
25 using ValueDisplayNamesMap = std::map<uint16_t, std::vector<std::string>>;
26 
27 /** @class BIOSAttribute
28  *  @brief Provide interfaces to implement specific types of attributes
29  */
30 class BIOSAttribute
31 {
32   public:
33     /** @brief Construct a bios attribute
34      *  @param[in] entry - Json Object
35      *  @param[in] dbusHandler - Dbus Handler
36      */
37     BIOSAttribute(const Json& entry,
38                   pldm::utils::DBusHandler* const dbusHandler);
39 
40     /** Virtual destructor
41      */
42     virtual ~BIOSAttribute() = default;
43 
44     /** @brief Set Attribute value On Dbus according to the attribute value
45      * entry
46      *  @param[in] attrValueEntry - The attribute value entry
47      *  @param[in] attrEntry - The attribute entry corresponding to the
48      *                         attribute value entry
49      *  @param[in] stringTable - The string table
50      */
51     virtual void
52         setAttrValueOnDbus(const pldm_bios_attr_val_table_entry* attrValueEntry,
53                            const pldm_bios_attr_table_entry* attrEntry,
54                            const BIOSStringTable& stringTable) = 0;
55 
56     /** @brief Construct corresponding entries at the end of the attribute table
57      *         and attribute value tables
58      *  @param[in] stringTable - The string Table
59      *  @param[in,out] attrTable - The attribute table
60      *  @param[in,out] attrValueTable - The attribute value table
61      *  @param[in,out] optAttributeValue - init value of the attribute
62      */
63     virtual void constructEntry(
64         const BIOSStringTable& stringTable, Table& attrTable,
65         Table& attrValueTable,
66         std::optional<std::variant<int64_t, std::string>> optAttributeValue =
67             std::nullopt) = 0;
68 
69     /** @brief Method to update the value for an attribute
70      *  @param[in,out] newValue - An attribute value table row with the new
71      * value for the attribute
72      *  @param[in] attrHdl - attribute handle
73      *  @param[in] attrType - attribute type
74      *  @param[in] newPropVal - The new value
75      *  @return PLDM Success or failure status
76      */
77     virtual int updateAttrVal(Table& newValue, uint16_t attrHdl,
78                               uint8_t attrType,
79                               const pldm::utils::PropertyValue& newPropVal) = 0;
80 
81     /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14
82      *  @param[in] attributevalue - attribute value(Enumeration, String and
83      *             Integer)
84      *  @param[in,out] attrValueEntry - attribute entry
85      */
86     virtual void generateAttributeEntry(
87         const std::variant<int64_t, std::string>& attributevalue,
88         Table& attrValueEntry) = 0;
89 
90     /** @brief Method to return the D-Bus map */
91     std::optional<pldm::utils::DBusMapping> getDBusMap();
92 
93     /** @brief Name of this attribute */
94     const std::string name;
95 
96     /** Weather this attribute is read-only */
97     bool readOnly;
98 
99     const std::string displayName;
100 
101     const std::string helpText;
102 
103     ValueDisplayNamesMap valueDisplayNamesMap;
104 
105   protected:
106     /** @brief dbus backend, nullopt if this attribute is read-only*/
107     std::optional<pldm::utils::DBusMapping> dBusMap;
108 
109     /** @brief dbus handler */
110     pldm::utils::DBusHandler* const dbusHandler;
111 };
112 
113 } // namespace bios
114 } // namespace responder
115 } // namespace pldm
116