1 #pragma once
2 
3 #include <phal_exception.H>
4 
5 #include <nlohmann/json.hpp>
6 
7 #include <string>
8 #include <vector>
9 namespace openpower
10 {
11 namespace pel
12 {
13 using FFDCData = std::vector<std::pair<std::string, std::string>>;
14 
15 using json = nlohmann::json;
16 
17 using namespace openpower::phal;
18 
19 /**
20  * @brief Create boot error PEL
21  *
22  * @param[in] ffdcData - failure data to append to PEL
23  * @param[in] calloutData - callout data to append to PEL
24  */
25 void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
26 
27 /**
28  * @brief Create SBE boot error PEL
29  *
30  * @param[in] event - the event type
31  * @param[in] sbeError - SBE error object
32  * @param[in] ffdcData - failure data to append to PEL
33  */
34 void createSbeErrorPEL(const std::string& event, const sbeError_t& sbeError,
35                        const FFDCData& ffdcData);
36 
37 /**
38  * @brief Create a PEL for the specified event type and additional data
39  *
40  *  @param[in]  event - the event type
41  *  @param[in] ffdcData - failure data to append to PEL
42  */
43 void createPEL(const std::string& event, const FFDCData& ffdcData = {});
44 
45 /**
46  * @class FFDCFile
47  * @brief This class is used to create ffdc data file and to get fd
48  */
49 class FFDCFile
50 {
51   public:
52     FFDCFile() = delete;
53     FFDCFile(const FFDCFile&) = delete;
54     FFDCFile& operator=(const FFDCFile&) = delete;
55     FFDCFile(FFDCFile&&) = delete;
56     FFDCFile& operator=(FFDCFile&&) = delete;
57 
58     /**
59      * Used to pass json object to create unique ffdc file by using
60      * passed json data.
61      */
62     explicit FFDCFile(const json& pHALCalloutData);
63 
64     /**
65      * Used to remove created ffdc file.
66      */
67     ~FFDCFile();
68 
69     /**
70      * Used to get created ffdc file file descriptor id.
71      *
72      * @return file descriptor id
73      */
74     int getFileFD() const;
75 
76   private:
77     /**
78      * Used to store callout ffdc data from passed json object.
79      */
80     std::string calloutData;
81 
82     /**
83      * Used to store unique ffdc file name.
84      */
85     std::string calloutFile;
86 
87     /**
88      * Used to store created ffdc file descriptor id.
89      */
90     int fileFD;
91 
92     /**
93      * Used to create ffdc file to pass PEL api for creating
94      * pel records.
95      *
96      * @return NULL
97      */
98     void prepareFFDCFile();
99 
100     /**
101      * Create unique ffdc file.
102      *
103      * @return NULL
104      */
105     void createCalloutFile();
106 
107     /**
108      * Used write json object value into created file.
109      *
110      * @return NULL
111      */
112     void writeCalloutData();
113 
114     /**
115      * Used set ffdc file seek position begining to consume by PEL
116      *
117      * @return NULL
118      */
119     void setCalloutFileSeekPos();
120 
121     /**
122      * Used to remove created ffdc file.
123      *
124      * @return NULL
125      */
126     void removeCalloutFile();
127 
128 }; // FFDCFile end
129 
130 } // namespace pel
131 } // namespace openpower
132