blob: a95da12dddfa930dcd3cbf38efbe61305f4658be [file] [log] [blame]
Matt Spinler131870c2019-09-25 13:29:04 -05001#include "section_factory.hpp"
2
3#include "failing_mtms.hpp"
4#include "generic.hpp"
5#include "pel_types.hpp"
6#include "private_header.hpp"
Matt Spinlerf9bae182019-10-09 13:37:38 -05007#include "src.hpp"
Aatir Manzur51c92632019-09-06 13:30:48 -05008#include "user_data.hpp"
Matt Spinler131870c2019-09-25 13:29:04 -05009#include "user_header.hpp"
10
11namespace openpower
12{
13namespace pels
14{
15namespace section_factory
16{
17std::unique_ptr<Section> create(Stream& pelData)
18{
19 std::unique_ptr<Section> section;
20
21 // Peek the section ID to create the appriopriate object.
22 // If not enough data remains to do so, an invalid
23 // Generic object will be created in the default case.
24 uint16_t sectionID = 0;
25
26 if (pelData.remaining() >= 2)
27 {
28 pelData >> sectionID;
29 pelData.offset(pelData.offset() - 2);
30 }
31
32 switch (sectionID)
33 {
34 case static_cast<uint16_t>(SectionID::privateHeader):
35 section = std::make_unique<PrivateHeader>(pelData);
36 break;
Aatir Manzur51c92632019-09-06 13:30:48 -050037 case static_cast<uint16_t>(SectionID::userData):
38 section = std::make_unique<UserData>(pelData);
39 break;
Matt Spinler131870c2019-09-25 13:29:04 -050040 case static_cast<uint16_t>(SectionID::userHeader):
41 section = std::make_unique<UserHeader>(pelData);
42 break;
43 case static_cast<uint16_t>(SectionID::failingMTMS):
44 section = std::make_unique<FailingMTMS>(pelData);
45 break;
Matt Spinlerf9bae182019-10-09 13:37:38 -050046 case static_cast<uint16_t>(SectionID::primarySRC):
47 case static_cast<uint16_t>(SectionID::secondarySRC):
48 section = std::make_unique<SRC>(pelData);
49 break;
Matt Spinler131870c2019-09-25 13:29:04 -050050 default:
51 // A generic object, but at least an object.
52 section = std::make_unique<Generic>(pelData);
53 break;
54 }
55
56 return section;
57}
58
59} // namespace section_factory
60} // namespace pels
61} // namespace openpower