blob: fb593e43ad8c88c4aa22e1d4bd7293d5ff937606 [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
Archana Kakaniac713ee2024-05-20 01:27:53 -050093 /** @brief Type of the attribute */
94 const std::string type;
95
John Wange2efdcc2020-02-12 17:02:06 +080096 /** @brief Name of this attribute */
97 const std::string name;
98
99 /** Weather this attribute is read-only */
George Liudaa69232020-09-02 17:22:09 +0800100 bool readOnly;
John Wange2efdcc2020-02-12 17:02:06 +0800101
George Liu92bb4022020-09-03 14:58:24 +0800102 const std::string displayName;
103
104 const std::string helpText;
105
Sagar Srinivas7927f902023-10-09 07:53:00 -0500106 ValueDisplayNamesMap valueDisplayNamesMap;
107
John Wange2efdcc2020-02-12 17:02:06 +0800108 protected:
109 /** @brief dbus backend, nullopt if this attribute is read-only*/
Brad Bishop5079ac42021-08-19 18:35:06 -0400110 std::optional<pldm::utils::DBusMapping> dBusMap;
John Wange2efdcc2020-02-12 17:02:06 +0800111
112 /** @brief dbus handler */
Brad Bishop5079ac42021-08-19 18:35:06 -0400113 pldm::utils::DBusHandler* const dbusHandler;
John Wange2efdcc2020-02-12 17:02:06 +0800114};
115
116} // namespace bios
117} // namespace responder
Sampa Misra46ece062020-03-18 07:17:44 -0500118} // namespace pldm