blob: 795365529fde27dd926546b0dde9493fdc64f15a [file] [log] [blame]
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05001#include "parser_factory.hpp"
2
3#include "ipz_parser.hpp"
4#include "keyword_vpd_parser.hpp"
5#include "memory_vpd_parser.hpp"
6#include "utils.hpp"
Santosh Puranikdd453be2021-02-10 21:45:25 +05307#include "vpd_exceptions.hpp"
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05008
9using namespace vpd::keyword::parser;
10using namespace openpower::vpd::memory::parser;
11using namespace openpower::vpd::parser::interface;
12using namespace openpower::vpd::ipz::parser;
Santosh Puranikdd453be2021-02-10 21:45:25 +053013using namespace openpower::vpd::exceptions;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050014
15namespace openpower
16{
17namespace vpd
18{
19namespace parser
20{
21namespace factory
22{
23interface::ParserInterface* ParserFactory::getParser(Binary&& vpdVector)
24{
25 vpdType type = vpdTypeCheck(vpdVector);
26
27 switch (type)
28 {
29 case IPZ_VPD:
30 {
31 return new IpzVpdParser(std::move(vpdVector));
32 }
33
34 case KEYWORD_VPD:
35 {
36 return new KeywordVpdParser(std::move(vpdVector));
37 }
38
39 case MEMORY_VPD:
40 {
41 return new memoryVpdParser(std::move(vpdVector));
42 }
43
44 default:
Santosh Puranikdd453be2021-02-10 21:45:25 +053045 throw VpdDataException("Unable to determine VPD format");
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050046 }
47}
48
49void ParserFactory::freeParser(interface::ParserInterface* parser)
50{
51 if (parser)
52 {
53 delete parser;
54 parser = nullptr;
55 }
56}
57
58} // namespace factory
59} // namespace parser
60} // namespace vpd
61} // namespace openpower