blob: 67503df128a0b0a66de3717e8dcd244830dda0fc [file] [log] [blame]
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +05301#pragma once
2
3#include <stdint.h>
4
5#include <filesystem>
6#include <vector>
7
8#include "libpldm/bios.h"
9
10namespace pldm
11{
12
13namespace responder
14{
15
16namespace bios
17{
18
19using Table = std::vector<uint8_t>;
20using Response = std::vector<uint8_t>;
21namespace 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 */
41class 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 Wange297b9f2020-02-03 10:18:13 +080074class BIOSStringTable
John Wangf719f3b2020-01-17 08:46:22 +080075{
76 public:
John Wange297b9f2020-02-03 10:18:13 +080077 /** @brief Constructs BIOSStringTable
John Wangf719f3b2020-01-17 08:46:22 +080078 *
John Wange297b9f2020-02-03 10:18:13 +080079 * @param[in] stringTable - The stringTable in RAM
John Wangf719f3b2020-01-17 08:46:22 +080080 */
John Wange297b9f2020-02-03 10:18:13 +080081 BIOSStringTable(const Table& stringTable);
82
83 /** @brief Constructs BIOSStringTable
84 *
85 * @param[in] biosTable - The BIOSTable
86 */
87 BIOSStringTable(const BIOSTable& biosTable);
John Wangf719f3b2020-01-17 08:46:22 +080088
89 /** @brief Find the string name from the BIOS string table for a string
90 * handle
91 * @param[in] handle - string handle
John Wange297b9f2020-02-03 10:18:13 +080092 * @return name of the corresponding BIOS string
93 * @throw std::invalid_argument if the string can not be found.
John Wangf719f3b2020-01-17 08:46:22 +080094 */
95 std::string findString(uint16_t handle) const;
96
John Wange297b9f2020-02-03 10:18:13 +080097 /** @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 Wangf719f3b2020-01-17 08:46:22 +0800105 private:
106 Table stringTable;
107};
108
Deepak Kodihallicb7f2d42019-06-19 13:25:31 +0530109} // namespace bios
110} // namespace responder
111} // namespace pldm