blob: 11d8386a266e489f45c9f6ff23751f757105e714 [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"
Aatir Manzur51c92632019-09-06 13:30:48 -05007#include "user_data.hpp"
Matt Spinler131870c2019-09-25 13:29:04 -05008#include "user_header.hpp"
9
10namespace openpower
11{
12namespace pels
13{
14namespace section_factory
15{
16std::unique_ptr<Section> create(Stream& pelData)
17{
18 std::unique_ptr<Section> section;
19
20 // Peek the section ID to create the appriopriate object.
21 // If not enough data remains to do so, an invalid
22 // Generic object will be created in the default case.
23 uint16_t sectionID = 0;
24
25 if (pelData.remaining() >= 2)
26 {
27 pelData >> sectionID;
28 pelData.offset(pelData.offset() - 2);
29 }
30
31 switch (sectionID)
32 {
33 case static_cast<uint16_t>(SectionID::privateHeader):
34 section = std::make_unique<PrivateHeader>(pelData);
35 break;
Aatir Manzur51c92632019-09-06 13:30:48 -050036 case static_cast<uint16_t>(SectionID::userData):
37 section = std::make_unique<UserData>(pelData);
38 break;
Matt Spinler131870c2019-09-25 13:29:04 -050039 case static_cast<uint16_t>(SectionID::userHeader):
40 section = std::make_unique<UserHeader>(pelData);
41 break;
42 case static_cast<uint16_t>(SectionID::failingMTMS):
43 section = std::make_unique<FailingMTMS>(pelData);
44 break;
45 default:
46 // A generic object, but at least an object.
47 section = std::make_unique<Generic>(pelData);
48 break;
49 }
50
51 return section;
52}
53
54} // namespace section_factory
55} // namespace pels
56} // namespace openpower