Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 1 | #include "section_factory.hpp" |
| 2 | |
| 3 | #include "failing_mtms.hpp" |
| 4 | #include "generic.hpp" |
| 5 | #include "pel_types.hpp" |
| 6 | #include "private_header.hpp" |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 7 | #include "src.hpp" |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 8 | #include "user_data.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 9 | #include "user_header.hpp" |
| 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace pels |
| 14 | { |
| 15 | namespace section_factory |
| 16 | { |
| 17 | std::unique_ptr<Section> create(Stream& pelData) |
| 18 | { |
| 19 | std::unique_ptr<Section> section; |
| 20 | |
| 21 | // Peek the section ID to create the appriopriate object. |
| 22 | // If not enough data remains to do so, an invalid |
| 23 | // Generic object will be created in the default case. |
| 24 | uint16_t sectionID = 0; |
| 25 | |
| 26 | if (pelData.remaining() >= 2) |
| 27 | { |
| 28 | pelData >> sectionID; |
| 29 | pelData.offset(pelData.offset() - 2); |
| 30 | } |
| 31 | |
| 32 | switch (sectionID) |
| 33 | { |
| 34 | case static_cast<uint16_t>(SectionID::privateHeader): |
| 35 | section = std::make_unique<PrivateHeader>(pelData); |
| 36 | break; |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 37 | case static_cast<uint16_t>(SectionID::userData): |
| 38 | section = std::make_unique<UserData>(pelData); |
| 39 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 40 | case static_cast<uint16_t>(SectionID::userHeader): |
| 41 | section = std::make_unique<UserHeader>(pelData); |
| 42 | break; |
| 43 | case static_cast<uint16_t>(SectionID::failingMTMS): |
| 44 | section = std::make_unique<FailingMTMS>(pelData); |
| 45 | break; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 46 | case static_cast<uint16_t>(SectionID::primarySRC): |
| 47 | case static_cast<uint16_t>(SectionID::secondarySRC): |
| 48 | section = std::make_unique<SRC>(pelData); |
| 49 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 50 | default: |
| 51 | // A generic object, but at least an object. |
| 52 | section = std::make_unique<Generic>(pelData); |
| 53 | break; |
| 54 | } |
| 55 | |
| 56 | return section; |
| 57 | } |
| 58 | |
| 59 | } // namespace section_factory |
| 60 | } // namespace pels |
| 61 | } // namespace openpower |