1 #pragma once 2 3 #include <stdint.h> 4 5 #include <filesystem> 6 #include <vector> 7 8 #include "libpldm/bios.h" 9 10 namespace pldm 11 { 12 13 namespace responder 14 { 15 16 namespace bios 17 { 18 19 using Table = std::vector<uint8_t>; 20 using Response = std::vector<uint8_t>; 21 namespace fs = std::filesystem; 22 23 /** @class BIOSTable 24 * 25 * @brief Provides APIs for storing and loading BIOS tables 26 * 27 * Typical usage is as follows: 28 * BIOSTable table(BIOS_STRING_TABLE_FILE_PATH); 29 * if (table.isEmpty()) { // no persisted table 30 * // construct BIOSTable 't' 31 * // prepare Response 'r' 32 * // send response to GetBIOSTable 33 * table.store(t); // persisted 34 * } 35 * else { // persisted table exists 36 * // create Response 'r' which has response fields (except 37 * // the table itself) to a GetBIOSTable command 38 * table.load(r); // actual table will be pushed back to the vector 39 * } 40 */ 41 class BIOSTable 42 { 43 public: 44 /** @brief Ctor - set file path to persist BIOS table 45 * 46 * @param[in] filePath - file where BIOS table should be persisted 47 */ 48 BIOSTable(const char* filePath); 49 50 /** @brief Checks if there's a persisted BIOS table 51 * 52 * @return bool - true if table exists, false otherwise 53 */ 54 bool isEmpty() const noexcept; 55 56 /** @brief Persist a BIOS table(string/attribute/attribute value) 57 * 58 * @param[in] table - BIOS table 59 */ 60 void store(const Table& table); 61 62 /** @brief Load BIOS table from persistent store to memory 63 * 64 * @param[in,out] response - PLDM response message to GetBIOSTable 65 * (excluding table), table will be pushed back to this. 66 */ 67 void load(Response& response) const; 68 69 private: 70 // file storing PLDM BIOS table 71 fs::path filePath; 72 }; 73 74 } // namespace bios 75 } // namespace responder 76 } // namespace pldm 77