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