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; |
| 25 | using namespace pldm::utils; |
| 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, DBusHandler* const dbusHandler); |
| 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 |
| 60 | */ |
| 61 | virtual void constructEntry(const BIOSStringTable& stringTable, |
| 62 | Table& attrTable, Table& attrValueTable) = 0; |
| 63 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 64 | /** @brief Method to update the value for an attribute |
| 65 | * @param[in,out] newValue - An attribute value table row with the new |
| 66 | * value for the attribute |
| 67 | * @param[in] attrHdl - attribute handle |
| 68 | * @param[in] attrType - attribute type |
| 69 | * @param[in] newPropVal - The new value |
| 70 | * @return PLDM Success or failure status |
| 71 | */ |
| 72 | virtual int updateAttrVal(Table& newValue, uint16_t attrHdl, |
| 73 | uint8_t attrType, |
| 74 | const PropertyValue& newPropVal) = 0; |
| 75 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 76 | /** @brief Generate attribute entry by the spec DSP0247_1.0.0 Table 14 |
| 77 | * @param[in] attributevalue - attribute value(Enumeration, String and |
| 78 | * Integer) |
| 79 | * @param[in,out] attrValueEntry - attribute entry |
| 80 | */ |
| 81 | virtual void generateAttributeEntry( |
| 82 | const std::variant<int64_t, std::string>& attributevalue, |
| 83 | Table& attrValueEntry) = 0; |
| 84 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 85 | /** @brief Method to return the D-Bus map */ |
| 86 | std::optional<DBusMapping> getDBusMap(); |
| 87 | |
John Wang | e2efdcc | 2020-02-12 17:02:06 +0800 | [diff] [blame] | 88 | /** @brief Name of this attribute */ |
| 89 | const std::string name; |
| 90 | |
| 91 | /** Weather this attribute is read-only */ |
| 92 | const bool readOnly; |
| 93 | |
| 94 | protected: |
| 95 | /** @brief dbus backend, nullopt if this attribute is read-only*/ |
| 96 | std::optional<DBusMapping> dBusMap; |
| 97 | |
| 98 | /** @brief dbus handler */ |
| 99 | DBusHandler* const dbusHandler; |
| 100 | }; |
| 101 | |
| 102 | } // namespace bios |
| 103 | } // namespace responder |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 104 | } // namespace pldm |