1 #pragma once
2 
3 #include "private_header.hpp"
4 #include "user_header.hpp"
5 
6 #include <memory>
7 #include <vector>
8 
9 namespace openpower
10 {
11 namespace pels
12 {
13 
14 /** @class PEL
15  *
16  * @brief This class represents a specific event log format referred to as a
17  * Platform Event Log.
18  *
19  * Every field in a PEL are in structures call sections, of which there are
20  * several types.  Some sections are required, and some are optional.  In some
21  * cases there may be more than one instance of a section type.
22  *
23  * The only two required sections for every type of PEL are the Private Header
24  * section and User Header section, which must be in the first and second
25  * positions, respectively.
26  *
27  * Every section starts with an 8 byte section header, which has the section
28  * size and type, among other things.
29  *
30  * This class represents all sections with objects.
31  *
32  * The available constructors are:
33  * - PEL(const std::vector<uint8_t>& data) - build this object out of a fully
34  *   formed flattened PEL.
35  *
36  * The data() method allows one to retrieve the PEL as a vector<uint8_t>.  This
37  * is the format in which it is stored and transmitted.
38  */
39 class PEL
40 {
41   public:
42     PEL() = delete;
43     ~PEL() = default;
44     PEL(const PEL&) = delete;
45     PEL& operator=(const PEL&) = delete;
46     PEL(PEL&&) = delete;
47     PEL& operator=(PEL&&) = delete;
48 
49     /**
50      * @brief Constructor
51      *
52      * Build a PEL from raw data.
53      *
54      * @param[in] data - The PEL data
55      */
56     PEL(const std::vector<uint8_t>& data);
57 
58     /**
59      * @brief Constructor
60      *
61      * Build a PEL from the raw data.
62      *
63      * @param[in] data - the PEL data
64      * @param[in] obmcLogID - the corresponding OpenBMC event log ID
65      */
66     PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID);
67 
68     /**
69      * @brief Convenience function to return the log ID field from the
70      *        Private Header section.
71      *
72      * @return uint32_t - the ID
73      */
74     uint32_t id() const
75     {
76         return _ph->id();
77     }
78 
79     /**
80      * @brief Convenience function to return the PLID field from the
81      *        Private Header section.
82      *
83      * @return uint32_t - the PLID
84      */
85     uint32_t plid() const
86     {
87         return _ph->plid();
88     }
89 
90     /**
91      * @brief Convenience function to return the OpenBMC event log ID field
92      * from the Private Header section.
93      *
94      * @return uint32_t - the OpenBMC event log ID
95      */
96     uint32_t obmcLogID() const
97     {
98         return _ph->obmcLogID();
99     }
100 
101     /**
102      * @brief Convenience function to return the commit time field from
103      *        the Private Header section.
104      *
105      * @return BCDTime - the timestamp
106      */
107     BCDTime commitTime() const
108     {
109         return _ph->commitTimestamp();
110     }
111 
112     /**
113      * @brief Convenience function to return the create time field from
114      *        the Private Header section.
115      *
116      * @return BCDTime - the timestamp
117      */
118     BCDTime createTime() const
119     {
120         return _ph->createTimestamp();
121     }
122 
123     /**
124      * @brief Gives access to the Private Header section class
125      *
126      * @return std::unique_ptr<PrivateHeader>& the private header
127      */
128     std::unique_ptr<PrivateHeader>& privateHeader()
129     {
130         return _ph;
131     }
132 
133     /**
134      * @brief Gives access to the User Header section class
135      *
136      * @return std::unique_ptr<UserHeader>& the user header
137      */
138     std::unique_ptr<UserHeader>& userHeader()
139     {
140         return _uh;
141     }
142 
143     /**
144      * @brief Returns the PEL data.
145      *
146      * @return std::vector<uint8_t> - the raw PEL data
147      */
148     std::vector<uint8_t> data();
149 
150     /**
151      * @brief Says if the PEL is valid (the sections are all valid)
152      *
153      * @return bool - if the PEL is valid
154      */
155     bool valid() const;
156 
157     /**
158      * @brief Sets the commit timestamp to the current time
159      */
160     void setCommitTime();
161 
162     /**
163      * @brief Sets the error log ID field to a unique ID.
164      */
165     void assignID();
166 
167   private:
168     /**
169      * @brief Builds the section objects from a PEL data buffer
170      *
171      * @param[in] obmcLogID - The OpenBMC event log ID to use for that
172      *                        field in the Private Header.
173      */
174     void populateFromRawData(uint32_t obmcLogID);
175 
176     /**
177      * @brief Flattens the PEL objects into the buffer
178      *
179      * @param[out] pelBuffer - What the data will be written to
180      */
181     void flatten(std::vector<uint8_t>& pelBuffer);
182 
183     /**
184      * @brief The PEL Private Header section
185      */
186     std::unique_ptr<PrivateHeader> _ph;
187 
188     /**
189      * @brief The PEL User Header section
190      */
191     std::unique_ptr<UserHeader> _uh;
192 
193     /**
194      * @brief The PEL itself.
195      *
196      * This should be able to be removed when this class is able to
197      * serialize/deserialize a complete PEL from its objects, as
198      * then there will be no need to keep around the data anymore.
199      */
200     std::vector<uint8_t> _rawPEL;
201 };
202 
203 } // namespace pels
204 } // namespace openpower
205