| Deepak Kodihalli | cb7f2d4 | 2019-06-19 13:25:31 +0530 | [diff] [blame] | 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 |  | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 74 | class BIOSStringTable | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 75 | { | 
|  | 76 | public: | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 77 | /** @brief Constructs BIOSStringTable | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 78 | * | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 79 | *  @param[in] stringTable - The stringTable in RAM | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 80 | */ | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 81 | BIOSStringTable(const Table& stringTable); | 
|  | 82 |  | 
|  | 83 | /** @brief Constructs BIOSStringTable | 
|  | 84 | * | 
|  | 85 | *  @param[in] biosTable - The BIOSTable | 
|  | 86 | */ | 
|  | 87 | BIOSStringTable(const BIOSTable& biosTable); | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 88 |  | 
|  | 89 | /** @brief Find the string name from the BIOS string table for a string | 
|  | 90 | * handle | 
|  | 91 | *  @param[in] handle - string handle | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 92 | *  @return name of the corresponding BIOS string | 
|  | 93 | *  @throw std::invalid_argument if the string can not be found. | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 94 | */ | 
|  | 95 | std::string findString(uint16_t handle) const; | 
|  | 96 |  | 
| John Wang | e297b9f | 2020-02-03 10:18:13 +0800 | [diff] [blame] | 97 | /** @brief Find the string handle from the BIOS string table by the given | 
|  | 98 | *         name | 
|  | 99 | *  @param[in] name - name of the BIOS string | 
|  | 100 | *  @return handle of the string | 
|  | 101 | *  @throw std::invalid_argument if the string can not be found | 
|  | 102 | */ | 
|  | 103 | uint16_t findHandle(const std::string& name) const; | 
|  | 104 |  | 
| John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 105 | private: | 
|  | 106 | Table stringTable; | 
|  | 107 | }; | 
|  | 108 |  | 
| Deepak Kodihalli | cb7f2d4 | 2019-06-19 13:25:31 +0530 | [diff] [blame] | 109 | } // namespace bios | 
|  | 110 | } // namespace responder | 
|  | 111 | } // namespace pldm |