Code refactoring
Moved all the constants to const.hpp and utility method to
utils.cpp/hpp.
Removed file ibm_vpd_type_check.cpp/hpp and keyword_vpd_types.hpp.
Signed-off-by: SunnySrivastava1984 <sunnsr25@in.ibm.com>
Change-Id: Ie7b54e6fd03a499fab7c3124e17292c6d525e471
diff --git a/const.hpp b/const.hpp
index 1ee8c89..6153410 100644
--- a/const.hpp
+++ b/const.hpp
@@ -49,6 +49,23 @@
static constexpr auto SYSTEM_2U = "50001001";
static constexpr auto SYSTEM_4U = "50001000";
+constexpr uint8_t KW_VPD_START_TAG = 0x82;
+constexpr uint8_t KW_VPD_END_TAG = 0x78;
+constexpr uint8_t ALT_KW_VAL_PAIR_START_TAG = 0x90;
+constexpr uint8_t KW_VAL_PAIR_END_TAG = 0x79;
+constexpr auto MEMORY_VPD_START_TAG = "11S";
+constexpr int TWO_BYTES = 2;
+constexpr int KW_VPD_DATA_START = 0;
+constexpr auto MEMORY_VPD_DATA_START = 416;
+constexpr auto FORMAT_11S_LEN = 3;
+static constexpr auto PART_NUM_LEN = 7;
+static constexpr auto SERIAL_NUM_LEN = 12;
+static constexpr auto CCIN_LEN = 4;
+
+using namespace std::string_literals;
+constexpr auto pimPath = "/xyz/openbmc_project/inventory";
+constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager";
+
namespace lengths
{
enum Lengths
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index b761b10..24363d0 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -1,7 +1,6 @@
#include "config.h"
#include "defines.hpp"
-#include "ibm_vpd_type_check.hpp"
#include "keyword_vpd_parser.hpp"
#include "parser.hpp"
#include "utils.hpp"
@@ -21,10 +20,10 @@
using namespace openpower::vpd;
using namespace CLI;
using namespace vpd::keyword::parser;
-using namespace vpdFormat;
using namespace openpower::vpd::constants;
namespace fs = filesystem;
using json = nlohmann::json;
+using namespace openpower::vpd::inventory;
/**
* @brief Expands location codes
diff --git a/ibm_vpd_type_check.cpp b/ibm_vpd_type_check.cpp
deleted file mode 100644
index 41303ee..0000000
--- a/ibm_vpd_type_check.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "ibm_vpd_type_check.hpp"
-
-#include "keyword_vpd_types.hpp"
-
-using namespace vpd::keyword::parser;
-
-namespace vpdFormat
-{
-vpdType vpdTypeCheck(const Binary& vpdVector)
-{
- if (vpdVector[IPZ_DATA_START] == KW_VAL_PAIR_START_TAG)
- {
- // IPZ VPD FORMAT
- return vpdType::IPZ_VPD;
- }
- else if (vpdVector[KW_VPD_DATA_START] == KW_VPD_START_TAG)
- {
- // KEYWORD VPD FORMAT
- return vpdType::KEYWORD_VPD;
- }
-
- // INVALID VPD FORMAT
- return vpdType::INVALID_VPD_FORMAT;
-}
-} // namespace vpdFormat
diff --git a/ibm_vpd_type_check.hpp b/ibm_vpd_type_check.hpp
deleted file mode 100644
index d122473..0000000
--- a/ibm_vpd_type_check.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-#include <types.hpp>
-
-using namespace openpower::vpd;
-
-namespace vpdFormat
-{
-/**
- * @brief Types of VPD
- */
-enum vpdType
-{
- IPZ_VPD, /**< IPZ VPD type */
- KEYWORD_VPD, /**< Keyword VPD type */
- INVALID_VPD_FORMAT /**< Invalid VPD type */
-};
-
-/**
- * @brief Check the type of VPD.
- *
- * Checks the type of vpd based on the start tag.
- * @param[in] vector - Vpd data in vector format
- *
- * @return enum of type vpdType
- */
-vpdType vpdTypeCheck(const Binary& vector);
-} // namespace vpdFormat
diff --git a/keyword_vpd_parser.cpp b/keyword_vpd_parser.cpp
index eef17b8..9e147b5 100644
--- a/keyword_vpd_parser.cpp
+++ b/keyword_vpd_parser.cpp
@@ -1,5 +1,7 @@
#include "keyword_vpd_parser.hpp"
+#include "const.hpp"
+
#include <iostream>
#include <numeric>
#include <string>
@@ -10,6 +12,9 @@
{
namespace parser
{
+using namespace openpower::vpd::constants;
+using namespace openpower::vpd::inventory;
+
KeywordVpdMap KeywordVpdParser::parseKwVpd()
{
int kwVpdType;
diff --git a/keyword_vpd_parser.hpp b/keyword_vpd_parser.hpp
index 769a83a..f2339fa 100644
--- a/keyword_vpd_parser.hpp
+++ b/keyword_vpd_parser.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "keyword_vpd_types.hpp"
+#include "types.hpp"
namespace vpd
{
@@ -31,7 +31,6 @@
* 6) Validate the 'small resource type last end tag'.
* 7) Return the keyword-value map.
*/
-
class KeywordVpdParser
{
public:
@@ -45,7 +44,7 @@
*
* Move kwVpdVector to parser object's kwVpdVector
*/
- KeywordVpdParser(Binary&& kwVpdVector) :
+ KeywordVpdParser(openpower::vpd::Binary&& kwVpdVector) :
keywordVpdVector(std::move(kwVpdVector))
{
}
@@ -59,15 +58,19 @@
*
* @return map of keyword:value
*/
- KeywordVpdMap parseKwVpd();
+ openpower::vpd::inventory::KeywordVpdMap parseKwVpd();
private:
- Binary::iterator checkSumStart; //!< Pointer to the start byte from where
- //!< the checksum need to be calculated
- Binary::iterator checkSumEnd; //!< Pointer to the end byte until which the
- //!< checksum need to be calculated
- Binary::iterator kwVpdIterator; //!< Iterator to parse the vector
- Binary keywordVpdVector; //!< Vector which stores keyword VPD data
+ openpower::vpd::Binary::iterator
+ checkSumStart; //!< Pointer to the start byte from where
+ //!< the checksum need to be calculated
+ openpower::vpd::Binary::iterator
+ checkSumEnd; //!< Pointer to the end byte until which the
+ //!< checksum need to be calculated
+ openpower::vpd::Binary::iterator
+ kwVpdIterator; //!< Iterator to parse the vector
+ openpower::vpd::Binary
+ keywordVpdVector; //!< Vector which stores keyword VPD data
/**
* @brief Validate the large resource identifier string
@@ -86,7 +89,7 @@
*
* @return map of keyword:value
*/
- KeywordVpdMap kwValParser();
+ openpower::vpd::inventory::KeywordVpdMap kwValParser();
/**
* @brief Validate small resource type end tag
diff --git a/keyword_vpd_types.hpp b/keyword_vpd_types.hpp
deleted file mode 100644
index b219da7..0000000
--- a/keyword_vpd_types.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-namespace vpd
-{
-namespace keyword
-{
-namespace parser
-{
-constexpr uint8_t KW_VPD_START_TAG = 0x82;
-constexpr uint8_t KW_VPD_END_TAG = 0x78;
-constexpr uint8_t KW_VAL_PAIR_START_TAG = 0x84;
-constexpr uint8_t ALT_KW_VAL_PAIR_START_TAG = 0x90;
-constexpr uint8_t KW_VAL_PAIR_END_TAG = 0x79;
-constexpr int TWO_BYTES = 2;
-constexpr int IPZ_DATA_START = 11;
-constexpr int KW_VPD_DATA_START = 0;
-
-using Binary = std::vector<uint8_t>;
-using KeywordVpdMap = std::unordered_map<std::string, std::vector<uint8_t>>;
-} // namespace parser
-} // namespace keyword
-} // namespace vpd
diff --git a/meson.build b/meson.build
index 35947a2..7d76402 100644
--- a/meson.build
+++ b/meson.build
@@ -41,7 +41,6 @@
if get_option('ibm-parser').enabled()
ibm_read_vpd_SOURCES = ['ibm_vpd_app.cpp',
- 'ibm_vpd_type_check.cpp',
'parser.cpp',
'impl.cpp',
'utils.cpp',
diff --git a/test/keyword_vpd_parser_test/kw_vpd_test.cpp b/test/keyword_vpd_parser_test/kw_vpd_test.cpp
index c09d494..115d60a 100644
--- a/test/keyword_vpd_parser_test/kw_vpd_test.cpp
+++ b/test/keyword_vpd_parser_test/kw_vpd_test.cpp
@@ -1,4 +1,5 @@
#include "keyword_vpd_parser.hpp"
+#include "types.hpp"
#include <exception>
#include <fstream>
@@ -6,6 +7,8 @@
#include <gtest/gtest.h>
using namespace vpd::keyword::parser;
+using namespace openpower::vpd;
+using namespace openpower::vpd::inventory;
class KeywordVpdParserTest : public ::testing::Test
{
diff --git a/types.hpp b/types.hpp
index d48b317..5ff2959 100644
--- a/types.hpp
+++ b/types.hpp
@@ -43,6 +43,7 @@
using namespace std::string_literals;
constexpr auto pimPath = "/xyz/openbmc_project/inventory";
constexpr auto pimIntf = "xyz.openbmc_project.Inventory.Manager";
+using KeywordVpdMap = std::unordered_map<std::string, Binary>;
} // namespace inventory
diff --git a/utils.cpp b/utils.cpp
index 6002b9c..24d7b4c 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -11,7 +11,7 @@
{
namespace vpd
{
-
+using namespace openpower::vpd::constants;
namespace inventory
{
@@ -68,7 +68,35 @@
} // namespace inventory
-using namespace openpower::vpd::constants;
+vpdType vpdTypeCheck(const Binary& vpdVector)
+{
+ // Read first 3 Bytes to check the 11S bar code format
+ std::string is11SFormat = "";
+ for (uint8_t i = 0; i < FORMAT_11S_LEN; i++)
+ {
+ is11SFormat += vpdVector[MEMORY_VPD_DATA_START + i];
+ }
+
+ if (vpdVector[IPZ_DATA_START] == KW_VAL_PAIR_START_TAG)
+ {
+ // IPZ VPD FORMAT
+ return vpdType::IPZ_VPD;
+ }
+ else if (vpdVector[KW_VPD_DATA_START] == KW_VPD_START_TAG)
+ {
+ // KEYWORD VPD FORMAT
+ return vpdType::KEYWORD_VPD;
+ }
+ else if (is11SFormat.compare(MEMORY_VPD_START_TAG) == 0)
+ {
+ // Memory VPD format
+ return vpdType::MEMORY_VPD;
+ }
+
+ // INVALID VPD FORMAT
+ return vpdType::INVALID_VPD_FORMAT;
+}
+
LE2ByteData readUInt16LE(Binary::const_iterator iterator)
{
LE2ByteData lowByte = *iterator;
diff --git a/utils.hpp b/utils.hpp
index da6546c..54e562c 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -10,6 +10,27 @@
{
namespace vpd
{
+/**
+ * @brief Types of VPD
+ */
+enum vpdType
+{
+ IPZ_VPD, /**< IPZ VPD type */
+ KEYWORD_VPD, /**< Keyword VPD type */
+ MEMORY_VPD, /**< Memory VPD type */
+ INVALID_VPD_FORMAT /**< Invalid VPD type */
+};
+
+/**
+ * @brief Check the type of VPD.
+ *
+ * Checks the type of vpd based on the start tag.
+ * @param[in] vector - Vpd data in vector format
+ *
+ * @return enum of type vpdType
+ */
+vpdType vpdTypeCheck(const Binary& vector);
+
/** @brief Return the hex representation of the incoming byte
*
* @param [in] c - The input byte