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