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 | { |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame^] | 25 | interface::ParserInterface* |
| 26 | ParserFactory::getParser(const Binary& vpdVector, |
| 27 | const std::string& inventoryPath) |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 28 | { |
| 29 | vpdType type = vpdTypeCheck(vpdVector); |
| 30 | |
| 31 | switch (type) |
| 32 | { |
| 33 | case IPZ_VPD: |
| 34 | { |
Sunny Srivastava | f31a91b | 2022-06-09 08:11:29 -0500 | [diff] [blame^] | 35 | return new IpzVpdParser(vpdVector, inventoryPath); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | case KEYWORD_VPD: |
| 39 | { |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 40 | return new KeywordVpdParser(vpdVector); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | case MEMORY_VPD: |
| 44 | { |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 45 | return new memoryVpdParser(vpdVector); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | default: |
Santosh Puranik | dd453be | 2021-02-10 21:45:25 +0530 | [diff] [blame] | 49 | throw VpdDataException("Unable to determine VPD format"); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | void 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 |