blob: c07d86f0c037e94da5abc9adfdc43d314dcd9473 [file] [log] [blame]
John Wange2efdcc2020-02-12 17:02:06 +08001#pragma once
2
3#include "bios_table.hpp"
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05004#include "common/utils.hpp"
John Wange2efdcc2020-02-12 17:02:06 +08005
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/bios_table.h>
7
George Liu6492f522020-06-16 10:34:05 +08008#include <nlohmann/json.hpp>
9
John Wange2efdcc2020-02-12 17:02:06 +080010#include <cstdint>
11#include <filesystem>
12#include <memory>
John Wange2efdcc2020-02-12 17:02:06 +080013#include <optional>
14#include <string>
15#include <vector>
16
John Wange2efdcc2020-02-12 17:02:06 +080017namespace pldm
18{
19namespace responder
20{
21namespace bios
22{
23
24using Json = nlohmann::json;
Sagar Srinivas7927f902023-10-09 07:53:00 -050025using ValueDisplayNamesMap = std::map<uint16_t, std::vector<std::string>>;
John Wange2efdcc2020-02-12 17:02:06 +080026
27/** @class BIOSAttribute
28 * @brief Provide interfaces to implement specific types of attributes
29 */
30class BIOSAttribute
31{
32 public:
33 /** @brief Construct a bios attribute
34 * @param[in] entry - Json Object
35 * @param[in] dbusHandler - Dbus Handler
36 */
Brad Bishop5079ac42021-08-19 18:35:06 -040037 BIOSAttribute(const Json& entry,
38 pldm::utils::DBusHandler* const dbusHandler);
John Wange2efdcc2020-02-12 17:02:06 +080039
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
Tom Josephca7b2522020-11-18 12:27:11 +053061 * @param[in,out] optAttributeValue - init value of the attribute
John Wange2efdcc2020-02-12 17:02:06 +080062 */
Tom Josephca7b2522020-11-18 12:27:11 +053063 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;
John Wange2efdcc2020-02-12 17:02:06 +080068
Sampa Misra46ece062020-03-18 07:17:44 -050069 /** @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,
Brad Bishop5079ac42021-08-19 18:35:06 -040079 const pldm::utils::PropertyValue& newPropVal) = 0;
Sampa Misra46ece062020-03-18 07:17:44 -050080
George Liu1244acf2020-08-14 09:11:11 +080081 /** @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
Sampa Misra46ece062020-03-18 07:17:44 -050090 /** @brief Method to return the D-Bus map */
Brad Bishop5079ac42021-08-19 18:35:06 -040091 std::optional<pldm::utils::DBusMapping> getDBusMap();
Sampa Misra46ece062020-03-18 07:17:44 -050092
John Wange2efdcc2020-02-12 17:02:06 +080093 /** @brief Name of this attribute */
94 const std::string name;
95
96 /** Weather this attribute is read-only */
George Liudaa69232020-09-02 17:22:09 +080097 bool readOnly;
John Wange2efdcc2020-02-12 17:02:06 +080098
George Liu92bb4022020-09-03 14:58:24 +080099 const std::string displayName;
100
101 const std::string helpText;
102
Sagar Srinivas7927f902023-10-09 07:53:00 -0500103 ValueDisplayNamesMap valueDisplayNamesMap;
104
John Wange2efdcc2020-02-12 17:02:06 +0800105 protected:
106 /** @brief dbus backend, nullopt if this attribute is read-only*/
Brad Bishop5079ac42021-08-19 18:35:06 -0400107 std::optional<pldm::utils::DBusMapping> dBusMap;
John Wange2efdcc2020-02-12 17:02:06 +0800108
109 /** @brief dbus handler */
Brad Bishop5079ac42021-08-19 18:35:06 -0400110 pldm::utils::DBusHandler* const dbusHandler;
John Wange2efdcc2020-02-12 17:02:06 +0800111};
112
113} // namespace bios
114} // namespace responder
Sampa Misra46ece062020-03-18 07:17:44 -0500115} // namespace pldm