Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 16 | #include "section_factory.hpp" |
| 17 | |
Matt Spinler | 386a61e | 2020-08-13 15:51:12 -0500 | [diff] [blame] | 18 | #include "extended_user_data.hpp" |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 19 | #include "extended_user_header.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 20 | #include "failing_mtms.hpp" |
| 21 | #include "generic.hpp" |
| 22 | #include "pel_types.hpp" |
| 23 | #include "private_header.hpp" |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 24 | #include "src.hpp" |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 25 | #include "user_data.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 26 | #include "user_header.hpp" |
| 27 | |
| 28 | namespace openpower |
| 29 | { |
| 30 | namespace pels |
| 31 | { |
| 32 | namespace section_factory |
| 33 | { |
| 34 | std::unique_ptr<Section> create(Stream& pelData) |
| 35 | { |
| 36 | std::unique_ptr<Section> section; |
| 37 | |
| 38 | // Peek the section ID to create the appriopriate object. |
| 39 | // If not enough data remains to do so, an invalid |
| 40 | // Generic object will be created in the default case. |
| 41 | uint16_t sectionID = 0; |
| 42 | |
| 43 | if (pelData.remaining() >= 2) |
| 44 | { |
| 45 | pelData >> sectionID; |
| 46 | pelData.offset(pelData.offset() - 2); |
| 47 | } |
| 48 | |
| 49 | switch (sectionID) |
| 50 | { |
| 51 | case static_cast<uint16_t>(SectionID::privateHeader): |
| 52 | section = std::make_unique<PrivateHeader>(pelData); |
| 53 | break; |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 54 | case static_cast<uint16_t>(SectionID::userData): |
| 55 | section = std::make_unique<UserData>(pelData); |
| 56 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 57 | case static_cast<uint16_t>(SectionID::userHeader): |
| 58 | section = std::make_unique<UserHeader>(pelData); |
| 59 | break; |
| 60 | case static_cast<uint16_t>(SectionID::failingMTMS): |
| 61 | section = std::make_unique<FailingMTMS>(pelData); |
| 62 | break; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 63 | case static_cast<uint16_t>(SectionID::primarySRC): |
| 64 | case static_cast<uint16_t>(SectionID::secondarySRC): |
| 65 | section = std::make_unique<SRC>(pelData); |
| 66 | break; |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 67 | case static_cast<uint16_t>(SectionID::extendedUserHeader): |
| 68 | section = std::make_unique<ExtendedUserHeader>(pelData); |
| 69 | break; |
Matt Spinler | 386a61e | 2020-08-13 15:51:12 -0500 | [diff] [blame] | 70 | case static_cast<uint16_t>(SectionID::extUserData): |
| 71 | section = std::make_unique<ExtendedUserData>(pelData); |
| 72 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 73 | default: |
| 74 | // A generic object, but at least an object. |
| 75 | section = std::make_unique<Generic>(pelData); |
| 76 | break; |
| 77 | } |
| 78 | |
| 79 | return section; |
| 80 | } |
| 81 | |
| 82 | } // namespace section_factory |
| 83 | } // namespace pels |
| 84 | } // namespace openpower |