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-manager/editor_impl.cpp b/vpd-manager/editor_impl.cpp
index e5d698a..a20cd44 100644
--- a/vpd-manager/editor_impl.cpp
+++ b/vpd-manager/editor_impl.cpp
@@ -2,11 +2,17 @@
#include "editor_impl.hpp"
-#include "parser.hpp"
+#include "ipz_parser.hpp"
+#include "parser_factory.hpp"
#include "utils.hpp"
#include "vpdecc/vpdecc.h"
+using namespace openpower::vpd::parser::interface;
+using namespace openpower::vpd::constants;
+using namespace openpower::vpd::parser::factory;
+using namespace openpower::vpd::ipz::parser;
+
namespace openpower
{
namespace vpd
@@ -15,7 +21,6 @@
{
namespace editor
{
-using namespace openpower::vpd::constants;
void EditorImpl::checkPTForRecord(Binary::const_iterator& iterator,
Byte ptLength)
@@ -95,7 +100,7 @@
#else
// update data in EEPROM as well. As we will not write complete file back
- vpdFileStream.seekp(offset + thisRecord.kwDataOffset, std::ios::beg);
+ vpdFileStream.seekp(startOffset + thisRecord.kwDataOffset, std::ios::beg);
iteratorToNewdata = kwdData.cbegin();
std::copy(iteratorToNewdata, end,
@@ -187,7 +192,7 @@
std::advance(end, thisRecord.recECCLength);
#ifndef ManagerTest
- vpdFileStream.seekp(offset + thisRecord.recECCoffset, std::ios::beg);
+ vpdFileStream.seekp(startOffset + thisRecord.recECCoffset, std::ios::beg);
std::copy(itrToRecordECC, end,
std::ostreambuf_iterator<char>(vpdFileStream));
#endif
@@ -575,18 +580,17 @@
void EditorImpl::updateKeyword(const Binary& kwdData)
{
- offset = 0;
+ startOffset = 0;
#ifndef ManagerTest
getVpdPathForCpu();
- uint32_t offset = 0;
// check if offset present?
for (const auto& item : jsonFile["frus"][vpdFilePath])
{
if (item.find("offset") != item.end())
{
- offset = item["offset"];
+ startOffset = item["offset"];
}
}
@@ -596,7 +600,7 @@
vpdFileStream.open(vpdFilePath,
std::ios::in | std::ios::out | std::ios::binary);
- vpdFileStream.seekg(offset, ios_base::cur);
+ vpdFileStream.seekg(startOffset, ios_base::cur);
vpdFileStream.read(reinterpret_cast<char*>(&completeVPDFile[0]), 65504);
completeVPDFile.resize(vpdFileStream.gcount());
vpdFileStream.clear(std::ios_base::eofbit);
@@ -618,24 +622,46 @@
Byte vpdType = *iterator;
if (vpdType == KW_VAL_PAIR_START_TAG)
{
- openpower::vpd::keyword::editor::processHeader(
- std::move(completeVPDFile));
+ ParserInterface* Iparser =
+ ParserFactory::getParser(std::move(completeVPDFile));
+ IpzVpdParser* ipzParser = dynamic_cast<IpzVpdParser*>(Iparser);
- // process VTOC for PTT rkwd
- readVTOC();
+ try
+ {
+ if (ipzParser == nullptr)
+ {
+ throw std::runtime_error("Invalid cast");
+ }
- // check record for keywrod
- checkRecordForKwd();
+ ipzParser->processHeader();
+ delete ipzParser;
+ ipzParser = nullptr;
+ // ParserFactory::freeParser(Iparser);
- // update the data to the file
- updateData(kwdData);
+ // process VTOC for PTT rkwd
+ readVTOC();
- // update the ECC data for the record once data has been updated
- updateRecordECC();
+ // check record for keywrod
+ checkRecordForKwd();
+
+ // update the data to the file
+ updateData(kwdData);
+
+ // update the ECC data for the record once data has been updated
+ updateRecordECC();
#ifndef ManagerTest
- // update the cache once data has been updated
- updateCache();
+ // update the cache once data has been updated
+ updateCache();
#endif
+ }
+ catch (const std::exception& e)
+ {
+ if (ipzParser != nullptr)
+ {
+ delete ipzParser;
+ }
+ throw std::runtime_error(e.what());
+ }
return;
}
}
diff --git a/vpd-manager/editor_impl.hpp b/vpd-manager/editor_impl.hpp
index d4d5598..9cf3b8a 100644
--- a/vpd-manager/editor_impl.hpp
+++ b/vpd-manager/editor_impl.hpp
@@ -47,7 +47,9 @@
EditorImpl& operator=(const EditorImpl&) = delete;
EditorImpl(EditorImpl&&) = delete;
EditorImpl& operator=(EditorImpl&&) = delete;
- ~EditorImpl() = default;
+ ~EditorImpl()
+ {
+ }
/** @brief Construct EditorImpl class
*
@@ -55,8 +57,8 @@
*/
EditorImpl(const std::string& record, const std::string& kwd,
Binary&& vpd) :
- thisRecord(record, kwd),
- vpdFile(std::move(vpd))
+ startOffset(0),
+ thisRecord(record, kwd), vpdFile(std::move(vpd))
{
}
@@ -68,7 +70,8 @@
const std::string& record, const std::string& kwd,
const sdbusplus::message::object_path& inventoryPath) :
vpdFilePath(path),
- objPath(inventoryPath), jsonFile(json), thisRecord(record, kwd)
+ objPath(inventoryPath), startOffset(0), jsonFile(json),
+ thisRecord(record, kwd)
{
}
@@ -161,7 +164,7 @@
std::fstream vpdFileStream;
// offset to get vpd data from EEPROM
- uint32_t offset;
+ uint32_t startOffset;
// file to store parsed json
const nlohmann::json jsonFile;
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index 717a83a..a313e86 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -3,7 +3,7 @@
#include "manager.hpp"
#include "editor_impl.hpp"
-#include "parser.hpp"
+#include "ipz_parser.hpp"
#include "reader_impl.hpp"
#include "utils.hpp"
diff --git a/vpd-manager/meson.build b/vpd-manager/meson.build
index 7255dad..56b139e 100644
--- a/vpd-manager/meson.build
+++ b/vpd-manager/meson.build
@@ -1,21 +1,23 @@
-systemd = dependency('libsystemd', version : '>= 221')
+systemd = dependency('libsystemd', version: '>= 221')
phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
-configuration_inc = include_directories('.', '../')
+configuration_inc = include_directories('.', '../', '../vpd-parser/')
-vpd_manager_SOURCES =[
- 'manager_main.cpp',
- 'manager.cpp',
- 'server.cpp',
- 'error.cpp',
- 'editor_impl.cpp',
- 'reader_impl.cpp',
- '../impl.cpp',
- '../parser.cpp',
- '../utils.cpp',
- '../vpdecc/vpdecc.c',
- '../vpdecc/vpdecc_support.c'
- ]
+vpd_manager_SOURCES =['manager_main.cpp',
+ 'manager.cpp',
+ 'server.cpp',
+ 'error.cpp',
+ 'editor_impl.cpp',
+ 'reader_impl.cpp',
+ '../impl.cpp',
+ '../vpd-parser/ipz_parser.cpp',
+ '../utils.cpp',
+ '../vpdecc/vpdecc.c',
+ '../vpdecc/vpdecc_support.c',
+ '../vpd-parser//keyword_vpd_parser.cpp',
+ '../vpd-parser/memory_vpd_parser.cpp',
+ '../vpd-parser/parser_factory.cpp'
+ ]
vpd_manager_dependencies =[sdbusplus,
phosphor_logging,
@@ -23,10 +25,12 @@
phosphor_dbus_interfaces,
]
-vpd_manager_exe = executable('vpd-manager',
- vpd_manager_SOURCES,
- include_directories : configuration_inc,
- dependencies :[vpd_manager_dependencies,
- ],
- install: true
- )
+vpd_manager_exe = executable(
+ 'vpd-manager',
+ vpd_manager_SOURCES,
+ include_directories : configuration_inc,
+ dependencies : [
+ vpd_manager_dependencies,
+ ],
+ install : true
+ )