bios: Implement an iterator for bios attribute table
Traversing bios attribute table should be platform-independent, so
implement a c-version bios attribute table iterator in libpldm, also
implement a c++ auxiliary function to traverse a bios table.
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I2afcaac306603410e711aa4772ba35b5e0b131d5
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index a1288b4..a133b2d 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -9,6 +9,7 @@
#include <chrono>
#include <ctime>
#include <iostream>
+#include <memory>
#include <numeric>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
@@ -764,6 +765,30 @@
} // end namespace bios_type_string
+void traverseBIOSAttrTable(const Table& biosAttrTable,
+ AttrTableEntryHandler handler)
+{
+ std::unique_ptr<pldm_bios_table_iter, decltype(&pldm_bios_table_iter_free)>
+ iter(pldm_bios_table_iter_create(biosAttrTable.data(),
+ biosAttrTable.size(),
+ PLDM_BIOS_ATTR_TABLE),
+ pldm_bios_table_iter_free);
+ while (!pldm_bios_table_iter_is_end(iter.get()))
+ {
+ auto table_entry = pldm_bios_table_iter_attr_entry_value(iter.get());
+ try
+ {
+ handler(table_entry);
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>("handler fails when traversing BIOSAttrTable",
+ entry("ERROR=%s", e.what()));
+ }
+ pldm_bios_table_iter_next(iter.get());
+ }
+}
+
using typeHandler =
std::function<void(const BIOSTable& BIOSStringTable,
const char* biosJsonDir, Table& attributeTable)>;
diff --git a/libpldmresponder/bios.hpp b/libpldmresponder/bios.hpp
index 9bb7d23..412e07a 100644
--- a/libpldmresponder/bios.hpp
+++ b/libpldmresponder/bios.hpp
@@ -7,10 +7,12 @@
#include <stdint.h>
+#include <functional>
#include <map>
#include <vector>
#include "libpldm/bios.h"
+#include "libpldm/bios_table.h"
namespace pldm
{
@@ -23,6 +25,12 @@
namespace responder
{
+using AttrTableEntryHandler =
+ std::function<void(const struct pldm_bios_attr_table_entry*)>;
+
+void traverseBIOSAttrTable(const bios::Table& BIOSAttrTable,
+ AttrTableEntryHandler handler);
+
namespace bios
{
/** @brief Register handlers for command from the platform spec