Interface & Factory implementation for VPD Parsers
This commit abstracts the implementation logic of different parser.
A parser factory is implemented to provide instance of required
parser based on the type of vpd file needed to be parsed.
The interface should be derived to implement any further parser logic
related to vpd.
Status: This does not add any new function, so basic testing of
VPD parsing, VPD tool and writes was performed.
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I3ce1a2d6b7e8d8984fd7800132e78ab8a9a21e56
diff --git a/vpd-parser/ipz_parser.hpp b/vpd-parser/ipz_parser.hpp
new file mode 100644
index 0000000..cb8c489
--- /dev/null
+++ b/vpd-parser/ipz_parser.hpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "const.hpp"
+#include "parser_interface.hpp"
+#include "store.hpp"
+#include "types.hpp"
+
+#include <vector>
+
+namespace openpower
+{
+namespace vpd
+{
+namespace ipz
+{
+namespace parser
+{
+
+using ParserInterface = openpower::vpd::parser::interface::ParserInterface;
+using kwdVpdMap = openpower::vpd::inventory::KeywordVpdMap;
+
+class IpzVpdParser : public ParserInterface
+{
+ public:
+ IpzVpdParser() = delete;
+ IpzVpdParser(const IpzVpdParser&) = delete;
+ IpzVpdParser& operator=(const IpzVpdParser&) = delete;
+ IpzVpdParser(IpzVpdParser&&) = delete;
+ IpzVpdParser& operator=(IpzVpdParser&&) = delete;
+ ~IpzVpdParser() = default;
+
+ /**
+ * @brief Constructor
+ */
+ IpzVpdParser(Binary&& VpdVector) : vpd(std::move(VpdVector))
+ {
+ }
+
+ /**
+ * @brief Parse the memory VPD binary data.
+ * Collects and emplace the keyword-value pairs in map.
+ *
+ * @return map of keyword:value
+ */
+ std::variant<kwdVpdMap, Store> parse();
+
+ /**
+ * @brief An api to return interface name with respect to
+ * the parser selected.
+ *
+ * @return - Interface name for that vpd type.
+ */
+ std::string getInterfaceName() const;
+
+ /** @brief API to check vpd header
+ * @param [in] vpd - VPDheader in binary format
+ */
+ void processHeader();
+
+ private:
+ Binary vpd;
+}; // class IpzVpdParser
+
+} // namespace parser
+} // namespace ipz
+} // namespace vpd
+} // namespace openpower