blob: 8a52a029e585a570ba5e5ad421f2ff0079c3fee8 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
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 Spinler131870c2019-09-25 13:29:04 -050016#include "section_factory.hpp"
17
18#include "failing_mtms.hpp"
19#include "generic.hpp"
20#include "pel_types.hpp"
21#include "private_header.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -050022#include "src.hpp"
Aatir Manzur51c92632019-09-06 13:30:48 -050023#include "user_data.hpp"
Matt Spinler131870c2019-09-25 13:29:04 -050024#include "user_header.hpp"
25
26namespace openpower
27{
28namespace pels
29{
30namespace section_factory
31{
32std::unique_ptr<Section> create(Stream& pelData)
33{
34 std::unique_ptr<Section> section;
35
36 // Peek the section ID to create the appriopriate object.
37 // If not enough data remains to do so, an invalid
38 // Generic object will be created in the default case.
39 uint16_t sectionID = 0;
40
41 if (pelData.remaining() >= 2)
42 {
43 pelData >> sectionID;
44 pelData.offset(pelData.offset() - 2);
45 }
46
47 switch (sectionID)
48 {
49 case static_cast<uint16_t>(SectionID::privateHeader):
50 section = std::make_unique<PrivateHeader>(pelData);
51 break;
Aatir Manzur51c92632019-09-06 13:30:48 -050052 case static_cast<uint16_t>(SectionID::userData):
53 section = std::make_unique<UserData>(pelData);
54 break;
Matt Spinler131870c2019-09-25 13:29:04 -050055 case static_cast<uint16_t>(SectionID::userHeader):
56 section = std::make_unique<UserHeader>(pelData);
57 break;
58 case static_cast<uint16_t>(SectionID::failingMTMS):
59 section = std::make_unique<FailingMTMS>(pelData);
60 break;
Matt Spinlerf9bae182019-10-09 13:37:38 -050061 case static_cast<uint16_t>(SectionID::primarySRC):
62 case static_cast<uint16_t>(SectionID::secondarySRC):
63 section = std::make_unique<SRC>(pelData);
64 break;
Matt Spinler131870c2019-09-25 13:29:04 -050065 default:
66 // A generic object, but at least an object.
67 section = std::make_unique<Generic>(pelData);
68 break;
69 }
70
71 return section;
72}
73
74} // namespace section_factory
75} // namespace pels
76} // namespace openpower