blob: 04d496015e63894c4d26edc1dd98d1bcacaaf143 [file] [log] [blame]
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001#include "parser_factory.hpp"
2
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05003#include "const.hpp"
4#include "ibm_vpd_utils.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05005#include "ipz_parser.hpp"
jinuthomas6555e7e2023-02-14 21:48:00 -06006#include "isdimm_vpd_parser.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05007#include "keyword_vpd_parser.hpp"
8#include "memory_vpd_parser.hpp"
Santosh Puranikdd453be2021-02-10 21:45:25 +05309#include "vpd_exceptions.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050010
11using namespace vpd::keyword::parser;
12using namespace openpower::vpd::memory::parser;
jinuthomas5700b3c2023-03-07 22:51:00 -060013using namespace openpower::vpd::isdimm::parser;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050014using namespace openpower::vpd::parser::interface;
15using namespace openpower::vpd::ipz::parser;
Santosh Puranikdd453be2021-02-10 21:45:25 +053016using namespace openpower::vpd::exceptions;
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050017using namespace openpower::vpd::constants;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050018
19namespace openpower
20{
21namespace vpd
22{
23namespace parser
24{
25namespace factory
26{
girik18bb9852022-11-16 05:48:13 -060027interface::ParserInterface* ParserFactory::getParser(
28 const Binary& vpdVector, const std::string& inventoryPath,
29 const std::string& vpdFilePath, uint32_t vpdStartOffset)
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050030{
31 vpdType type = vpdTypeCheck(vpdVector);
32
33 switch (type)
34 {
35 case IPZ_VPD:
36 {
girik18bb9852022-11-16 05:48:13 -060037 return new IpzVpdParser(vpdVector, inventoryPath, vpdFilePath,
38 vpdStartOffset);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050039 }
40
41 case KEYWORD_VPD:
42 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050043 return new KeywordVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050044 }
45
jinuthomas6555e7e2023-02-14 21:48:00 -060046 case DDR4_DDIMM_MEMORY_VPD:
47 case DDR5_DDIMM_MEMORY_VPD:
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050048 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050049 return new memoryVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050050 }
51
jinuthomas6555e7e2023-02-14 21:48:00 -060052 case DDR4_ISDIMM_MEMORY_VPD:
53 case DDR5_ISDIMM_MEMORY_VPD:
54 {
55 return new isdimmVpdParser(vpdVector);
56 }
57
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050058 default:
Santosh Puranikdd453be2021-02-10 21:45:25 +053059 throw VpdDataException("Unable to determine VPD format");
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050060 }
61}
62
63void ParserFactory::freeParser(interface::ParserInterface* parser)
64{
65 if (parser)
66 {
67 delete parser;
68 parser = nullptr;
69 }
70}
71
72} // namespace factory
73} // namespace parser
74} // namespace vpd
75} // namespace openpower