blob: 4ff766b320ad82119979e1f5f88a8fd605f441e3 [file] [log] [blame]
Alexander Hansen40fb5492025-10-28 17:56:12 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3
Matt Spinler131870c2019-09-25 13:29:04 -05004#include "section_factory.hpp"
5
Matt Spinler386a61e2020-08-13 15:51:12 -05006#include "extended_user_data.hpp"
Matt Spinlerc63e2e82019-12-02 15:50:12 -06007#include "extended_user_header.hpp"
Matt Spinler131870c2019-09-25 13:29:04 -05008#include "failing_mtms.hpp"
9#include "generic.hpp"
10#include "pel_types.hpp"
11#include "private_header.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -050012#include "src.hpp"
Aatir Manzur51c92632019-09-06 13:30:48 -050013#include "user_data.hpp"
Matt Spinler131870c2019-09-25 13:29:04 -050014#include "user_header.hpp"
15
16namespace openpower
17{
18namespace pels
19{
20namespace section_factory
21{
22std::unique_ptr<Section> create(Stream& pelData)
23{
24 std::unique_ptr<Section> section;
25
26 // Peek the section ID to create the appriopriate object.
27 // If not enough data remains to do so, an invalid
28 // Generic object will be created in the default case.
29 uint16_t sectionID = 0;
30
31 if (pelData.remaining() >= 2)
32 {
33 pelData >> sectionID;
34 pelData.offset(pelData.offset() - 2);
35 }
36
37 switch (sectionID)
38 {
39 case static_cast<uint16_t>(SectionID::privateHeader):
40 section = std::make_unique<PrivateHeader>(pelData);
41 break;
Aatir Manzur51c92632019-09-06 13:30:48 -050042 case static_cast<uint16_t>(SectionID::userData):
43 section = std::make_unique<UserData>(pelData);
44 break;
Matt Spinler131870c2019-09-25 13:29:04 -050045 case static_cast<uint16_t>(SectionID::userHeader):
46 section = std::make_unique<UserHeader>(pelData);
47 break;
48 case static_cast<uint16_t>(SectionID::failingMTMS):
49 section = std::make_unique<FailingMTMS>(pelData);
50 break;
Matt Spinlerf9bae182019-10-09 13:37:38 -050051 case static_cast<uint16_t>(SectionID::primarySRC):
52 case static_cast<uint16_t>(SectionID::secondarySRC):
53 section = std::make_unique<SRC>(pelData);
54 break;
Matt Spinlerc63e2e82019-12-02 15:50:12 -060055 case static_cast<uint16_t>(SectionID::extendedUserHeader):
56 section = std::make_unique<ExtendedUserHeader>(pelData);
57 break;
Matt Spinler386a61e2020-08-13 15:51:12 -050058 case static_cast<uint16_t>(SectionID::extUserData):
59 section = std::make_unique<ExtendedUserData>(pelData);
60 break;
Matt Spinler131870c2019-09-25 13:29:04 -050061 default:
62 // A generic object, but at least an object.
63 section = std::make_unique<Generic>(pelData);
64 break;
65 }
66
67 return section;
68}
69
70} // namespace section_factory
71} // namespace pels
72} // namespace openpower