blob: f7d0f046f313fe1e3ee7ff23de64496dbb91eab3 [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"
6#include "keyword_vpd_parser.hpp"
7#include "memory_vpd_parser.hpp"
Santosh Puranikdd453be2021-02-10 21:45:25 +05308#include "vpd_exceptions.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05009
10using namespace vpd::keyword::parser;
11using namespace openpower::vpd::memory::parser;
12using namespace openpower::vpd::parser::interface;
13using namespace openpower::vpd::ipz::parser;
Santosh Puranikdd453be2021-02-10 21:45:25 +053014using namespace openpower::vpd::exceptions;
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050015using namespace openpower::vpd::constants;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050016
17namespace openpower
18{
19namespace vpd
20{
21namespace parser
22{
23namespace factory
24{
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -050025interface::ParserInterface*
26 ParserFactory::getParser(const Binary& vpdVector,
27 const std::string& inventoryPath)
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050028{
29 vpdType type = vpdTypeCheck(vpdVector);
30
31 switch (type)
32 {
33 case IPZ_VPD:
34 {
Sunny Srivastavaf31a91b2022-06-09 08:11:29 -050035 return new IpzVpdParser(vpdVector, inventoryPath);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050036 }
37
38 case KEYWORD_VPD:
39 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050040 return new KeywordVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050041 }
42
43 case MEMORY_VPD:
44 {
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050045 return new memoryVpdParser(vpdVector);
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050046 }
47
48 default:
Santosh Puranikdd453be2021-02-10 21:45:25 +053049 throw VpdDataException("Unable to determine VPD format");
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050050 }
51}
52
53void ParserFactory::freeParser(interface::ParserInterface* parser)
54{
55 if (parser)
56 {
57 delete parser;
58 parser = nullptr;
59 }
60}
61
62} // namespace factory
63} // namespace parser
64} // namespace vpd
65} // namespace openpower