John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "bios_table.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 4 | #include "common/utils.hpp" |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 5 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/bios_table.h> |
| 7 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 8 | #include <nlohmann/json.hpp> |
| 9 | |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 10 | #include <cstdint> |
| 11 | #include <filesystem> |
| 12 | #include <memory> |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 13 | #include <optional> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 17 | namespace pldm |
| 18 | { |
| 19 | namespace responder |
| 20 | { |
| 21 | namespace bios |
| 22 | { |
| 23 | |
| 24 | using Json = nlohmann::json; |
Sagar Srinivas | 7927f90 | 2023-10-09 07:53:00 -0500 | [diff] [blame] | 25 | using ValueDisplayNamesMap = std::map<uint16_t, std::vector<std::string>>; |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 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 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 37 | BIOSAttribute(const Json& entry, |
| 38 | pldm::utils::DBusHandler* const dbusHandler); |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 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 |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 61 | * @param[in,out] optAttributeValue - init value of the attribute |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 62 | */ |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 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; |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 68 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 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, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 79 | const pldm::utils::PropertyValue& newPropVal) = 0; |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 80 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 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 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 90 | /** @brief Method to return the D-Bus map */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 91 | std::optional<pldm::utils::DBusMapping> getDBusMap(); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 92 | |
Archana Kakani | ac713ee | 2024-05-20 01:27:53 -0500 | [diff] [blame] | 93 | /** @brief Type of the attribute */ |
| 94 | const std::string type; |
| 95 | |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 96 | /** @brief Name of this attribute */ |
| 97 | const std::string name; |
| 98 | |
| 99 | /** Weather this attribute is read-only */ |
George Liu | daa6923 | 2020-09-02 17:22:09 +0800 | [diff] [blame] | 100 | bool readOnly; |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 101 | |
George Liu | 92bb402 | 2020-09-03 14:58:24 +0800 | [diff] [blame] | 102 | const std::string displayName; |
| 103 | |
| 104 | const std::string helpText; |
| 105 | |
Sagar Srinivas | 7927f90 | 2023-10-09 07:53:00 -0500 | [diff] [blame] | 106 | ValueDisplayNamesMap valueDisplayNamesMap; |
| 107 | |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 108 | protected: |
| 109 | /** @brief dbus backend, nullopt if this attribute is read-only*/ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 110 | std::optional<pldm::utils::DBusMapping> dBusMap; |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 111 | |
| 112 | /** @brief dbus handler */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 113 | pldm::utils::DBusHandler* const dbusHandler; |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace bios |
| 117 | } // namespace responder |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 118 | } // namespace pldm |