SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 1 | #include "parser_factory.hpp" |
| 2 | |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 3 | #include "const.hpp" |
| 4 | #include "ibm_vpd_utils.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 5 | #include "ipz_parser.hpp" |
| 6 | #include "keyword_vpd_parser.hpp" |
| 7 | #include "memory_vpd_parser.hpp" |
Santosh Puranik | dd453be | 2021-02-10 21:45:25 +0530 | [diff] [blame] | 8 | #include "vpd_exceptions.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 9 | |
| 10 | using namespace vpd::keyword::parser; |
| 11 | using namespace openpower::vpd::memory::parser; |
| 12 | using namespace openpower::vpd::parser::interface; |
| 13 | using namespace openpower::vpd::ipz::parser; |
Santosh Puranik | dd453be | 2021-02-10 21:45:25 +0530 | [diff] [blame] | 14 | using namespace openpower::vpd::exceptions; |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 15 | using namespace openpower::vpd::constants; |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 16 | |
| 17 | namespace openpower |
| 18 | { |
| 19 | namespace vpd |
| 20 | { |
| 21 | namespace parser |
| 22 | { |
| 23 | namespace factory |
| 24 | { |
| 25 | interface::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 Puranik | dd453be | 2021-02-10 21:45:25 +0530 | [diff] [blame] | 47 | throw VpdDataException("Unable to determine VPD format"); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | void 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 |