1 #pragma once
2 
3 #include "pel_common.hpp"
4 #include "pel_section.hpp"
5 #include "stream.hpp"
6 
7 namespace attn
8 {
9 namespace pel
10 {
11 
12 /**
13  * @class UserHeader
14  *
15  * This represents the User Header section in a PEL.
16  *
17  * |--------+----------------+----------------+----------------+------------|
18  * | length | byte0          | byte1          | byte2          | byte3      |
19  * |--------+----------------+----------------+----------------+------------|
20  * | 8      | Section Header                                                |
21  * |        |                                                               |
22  * |--------+----------------+----------------+----------------+------------|
23  * | 4      | Subsystem ID   | Event Scope    | Event Severity | Event Type |
24  * |--------+----------------+----------------+----------------+------------|
25  * | 4      | reserved                                                      |
26  * |--------+----------------+----------------+-----------------------------|
27  * | 4      | Problem Domain | Problem Vector | Event Action Flags          |
28  * |--------+----------------+----------------+-----------------------------|
29  * | 4      | reserved                                                      |
30  * |--------+---------------------------------------------------------------|
31  *
32  */
33 class UserHeader : public Section
34 {
35   public:
36     UserHeader() = delete;
37     ~UserHeader() = default;
38     UserHeader(const UserHeader&) = default;
39     UserHeader& operator=(const UserHeader&) = default;
40     UserHeader(UserHeader&&) = default;
41     UserHeader& operator=(UserHeader&&) = default;
42 
43     /**
44      * @brief Constructor
45      *
46      * Fills in this class's data fields from raw data.
47      *
48      * @param[in] pel - the PEL data stream
49      */
50     explicit UserHeader(Stream& pel);
51 
52     /**
53      * @brief Flatten the section into the stream
54      *
55      * @param[in] stream - The stream to write to
56      */
57     void flatten(Stream& stream) const override;
58 
59     /**
60      * @brief Fills in the object from the stream data
61      *
62      * @param[in] stream - The stream to read from
63      */
64     void unflatten(Stream& stream);
65 
66     /**
67      * @brief Returns the size of this section when flattened into a PEL
68      *
69      * @return size_t - the size of the section
70      */
flattenedSize()71     static constexpr size_t flattenedSize()
72     {
73         return Section::flattenedSize() + sizeof(_eventSubsystem) +
74                sizeof(_eventScope) + sizeof(_eventSeverity) +
75                sizeof(_eventType) + sizeof(_reserved4Byte1) +
76                sizeof(_problemDomain) + sizeof(_problemVector) +
77                sizeof(_actionFlags) + sizeof(_reserved4Byte2);
78     }
79 
80     /**
81      * @brief Set the subsystem field
82      *
83      * @param[in] subsystem - The subsystem value
84      */
85     void setSubsystem(uint8_t subsystem);
86 
87     /**
88      * @brief Set the severity field
89      *
90      * @param[in] severity - The severity to set
91      */
92     void setSeverity(uint8_t severity);
93 
94     /**
95      * @brief Set the event type field
96      *
97      * @param[in] type - The event type
98      */
99     void setType(uint8_t type);
100 
101     /**
102      * @brief Set the action flags field
103      *
104      * @param[in] action - The action flags to set
105      */
106     void setAction(uint16_t action);
107 
108   private:
109     /**
110      * @brief The subsystem associated with the event.
111      */
112     uint8_t _eventSubsystem;
113 
114     /**
115      * @brief The event scope field.
116      */
117     uint8_t _eventScope = static_cast<uint8_t>(EventScope::platform);
118 
119     /**
120      * @brief The event severity.
121      */
122     uint8_t _eventSeverity; // set by constructor
123 
124     /**
125      * @brief The event type.
126      */
127     uint8_t _eventType = static_cast<uint8_t>(EventType::trace);
128 
129     /**
130      * @brief A reserved 4 byte placeholder
131      */
132     uint32_t _reserved4Byte1 = 0;
133 
134     /**
135      * @brief The problem domain field.
136      */
137     uint8_t _problemDomain = 0;
138 
139     /**
140      * @brief The problem vector field.
141      */
142     uint8_t _problemVector = 0;
143 
144     /**
145      * @brief The action flags field.
146      */
147     uint16_t _actionFlags; // set by contructor
148 
149     /**
150      * @brief A reserved 4 byte
151      * placeholder
152      */
153     uint32_t _reserved4Byte2 = 0;
154 };
155 
156 } // namespace pel
157 } // namespace attn
158