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