blob: 0489ef10d41fe8ac0c4d08c4c292bc735bb5f842 [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{
25interface::ParserInterface* ParserFactory::getParser(Binary&& vpdVector)
26{
27 vpdType type = vpdTypeCheck(vpdVector);
28
29 switch (type)
30 {
31 case IPZ_VPD:
32 {
33 return new IpzVpdParser(std::move(vpdVector));
34 }
35
36 case KEYWORD_VPD:
37 {
38 return new KeywordVpdParser(std::move(vpdVector));
39 }
40
41 case MEMORY_VPD:
42 {
43 return new memoryVpdParser(std::move(vpdVector));
44 }
45
46 default:
Santosh Puranikdd453be2021-02-10 21:45:25 +053047 throw VpdDataException("Unable to determine VPD format");
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050048 }
49}
50
51void ParserFactory::freeParser(interface::ParserInterface* parser)
52{
53 if (parser)
54 {
55 delete parser;
56 parser = nullptr;
57 }
58}
59
60} // namespace factory
61} // namespace parser
62} // namespace vpd
63} // namespace openpower