summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2016-11-24 06:50:43 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2016-12-08 12:37:27 -0600
commit683bf721d7f524aefd7d06502cfe0dfa755ac063 (patch)
tree76531961a98ce9c1f9d2af8ffc1cbc72952a3a55
parent4a475bda35c8c6c985f81f1dbecdba9a55d46782 (diff)
downloadopenpower-vpd-parser-683bf721d7f524aefd7d06502cfe0dfa755ac063.tar.gz
openpower-vpd-parser-683bf721d7f524aefd7d06502cfe0dfa755ac063.zip
parser : parse keyword section of a record
For a given OpenPOWER VPD record, get to it's keyword section and find all contained keywords, and read the data for each of those. Change-Id: I87001b3bc0a7b842543aa387e319b98aac8ca3ff Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--impl.cpp37
-rw-r--r--impl.hpp11
2 files changed, 48 insertions, 0 deletions
diff --git a/impl.cpp b/impl.cpp
index de1896f..9a6d8f9 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -2,6 +2,7 @@
#include <exception>
#include <iostream>
#include <iterator>
+#include <unordered_map>
#include <iomanip>
#include <tuple>
#include <algorithm>
@@ -23,6 +24,7 @@ static const std::unordered_map<std::string, Record> supportedRecords =
};
static constexpr auto MAC_ADDRESS_LEN_BYTES = 6;
+static constexpr auto LAST_KW = "PF";
static const std::unordered_map<std::string,
internal::KeywordInfo> supportedKeywords =
@@ -256,6 +258,41 @@ std::string Impl::readKwData(const internal::KeywordInfo& keyword,
return {};
}
+internal::KeywordMap Impl::readKeywords(Binary::const_iterator iterator)
+{
+ internal::KeywordMap map {};
+ while (true)
+ {
+ // Note keyword name
+ std::string kw(iterator, iterator + lengths::KW_NAME);
+ if (LAST_KW == kw)
+ {
+ // We're done
+ break;
+ }
+ // Jump past keyword name
+ std::advance(iterator, lengths::KW_NAME);
+ // Note keyword data length
+ std::size_t length = *iterator;
+ // Jump past keyword length
+ std::advance(iterator, sizeof(KwSize));
+ // Pointing to keyword data now
+ if (supportedKeywords.end() != supportedKeywords.find(kw))
+ {
+ // Keyword is of interest to us
+ std::string data = readKwData(
+ (supportedKeywords.find(kw))->second,
+ length,
+ iterator);
+ map.emplace(std::move(kw), std::move(data));
+ }
+ // Jump past keyword data length
+ std::advance(iterator, length);
+ }
+
+ return map;
+}
+
} // namespace parser
} // namespace vpd
} // namespace openpower
diff --git a/impl.hpp b/impl.hpp
index 42a5c44..d8af32d 100644
--- a/impl.hpp
+++ b/impl.hpp
@@ -28,6 +28,7 @@ namespace internal
using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>;
using OffsetList = std::vector<uint32_t>;
+using KeywordMap = Parsed::mapped_type;
}
@@ -113,6 +114,16 @@ class Impl
std::size_t dataLength,
Binary::const_iterator iterator);
+ /** @brief While we're pointing at the keyword section of
+ * a record in the VPD, this will read all contained
+ * keywords and their values.
+ *
+ * @param[in] iterator - iterator pointing to a Keyword in the VPD
+ *
+ * @returns map of keyword:data
+ */
+ internal::KeywordMap readKeywords(Binary::const_iterator iterator);
+
/** @brief Checks if the VHDR record is present in the VPD */
void checkHeader() const;
OpenPOWER on IntegriCloud