blob: 1afe96abdee706aa4ea0930e3b42c5fb9a9f166c [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{
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -050027interface::ParserInterface*
28 ParserFactory::getParser(const Binary& vpdVector,
29 const std::string& inventoryPath)
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050030{
31 vpdType type = vpdTypeCheck(vpdVector);
32
33 switch (type)
34 {
35 case IPZ_VPD:
36 {
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -050037 return new IpzVpdParser(vpdVector, inventoryPath);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050038 }
39
40 case KEYWORD_VPD:
41 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050042 return new KeywordVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050043 }
44
jinuthomas6555e7e2023-02-14 21:48:00 -060045 case DDR4_DDIMM_MEMORY_VPD:
46 case DDR5_DDIMM_MEMORY_VPD:
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050047 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050048 return new memoryVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050049 }
50
jinuthomas6555e7e2023-02-14 21:48:00 -060051 case DDR4_ISDIMM_MEMORY_VPD:
52 case DDR5_ISDIMM_MEMORY_VPD:
53 {
54 return new isdimmVpdParser(vpdVector);
55 }
56
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050057 default:
Santosh Puranikdd453be2021-02-10 21:45:25 +053058 throw VpdDataException("Unable to determine VPD format");
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050059 }
60}
61
62void ParserFactory::freeParser(interface::ParserInterface* parser)
63{
64 if (parser)
65 {
66 delete parser;
67 parser = nullptr;
68 }
69}
70
71} // namespace factory
72} // namespace parser
73} // namespace vpd
74} // namespace openpower