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 | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 18 | #include "extended_user_header.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 19 | #include "failing_mtms.hpp" |
| 20 | #include "generic.hpp" |
| 21 | #include "pel_types.hpp" |
| 22 | #include "private_header.hpp" |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 23 | #include "src.hpp" |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 24 | #include "user_data.hpp" |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 25 | #include "user_header.hpp" |
| 26 | |
| 27 | namespace openpower |
| 28 | { |
| 29 | namespace pels |
| 30 | { |
| 31 | namespace section_factory |
| 32 | { |
| 33 | std::unique_ptr<Section> create(Stream& pelData) |
| 34 | { |
| 35 | std::unique_ptr<Section> section; |
| 36 | |
| 37 | // Peek the section ID to create the appriopriate object. |
| 38 | // If not enough data remains to do so, an invalid |
| 39 | // Generic object will be created in the default case. |
| 40 | uint16_t sectionID = 0; |
| 41 | |
| 42 | if (pelData.remaining() >= 2) |
| 43 | { |
| 44 | pelData >> sectionID; |
| 45 | pelData.offset(pelData.offset() - 2); |
| 46 | } |
| 47 | |
| 48 | switch (sectionID) |
| 49 | { |
| 50 | case static_cast<uint16_t>(SectionID::privateHeader): |
| 51 | section = std::make_unique<PrivateHeader>(pelData); |
| 52 | break; |
Aatir Manzur | 51c9263 | 2019-09-06 13:30:48 -0500 | [diff] [blame] | 53 | case static_cast<uint16_t>(SectionID::userData): |
| 54 | section = std::make_unique<UserData>(pelData); |
| 55 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 56 | case static_cast<uint16_t>(SectionID::userHeader): |
| 57 | section = std::make_unique<UserHeader>(pelData); |
| 58 | break; |
| 59 | case static_cast<uint16_t>(SectionID::failingMTMS): |
| 60 | section = std::make_unique<FailingMTMS>(pelData); |
| 61 | break; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 62 | case static_cast<uint16_t>(SectionID::primarySRC): |
| 63 | case static_cast<uint16_t>(SectionID::secondarySRC): |
| 64 | section = std::make_unique<SRC>(pelData); |
| 65 | break; |
Matt Spinler | c63e2e8 | 2019-12-02 15:50:12 -0600 | [diff] [blame] | 66 | case static_cast<uint16_t>(SectionID::extendedUserHeader): |
| 67 | section = std::make_unique<ExtendedUserHeader>(pelData); |
| 68 | break; |
Matt Spinler | 131870c | 2019-09-25 13:29:04 -0500 | [diff] [blame] | 69 | default: |
| 70 | // A generic object, but at least an object. |
| 71 | section = std::make_unique<Generic>(pelData); |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | return section; |
| 76 | } |
| 77 | |
| 78 | } // namespace section_factory |
| 79 | } // namespace pels |
| 80 | } // namespace openpower |