blob: 0081c68d1af11ac18c7cc0f36d7fdc5e313ef1a6 [file] [log] [blame]
Brad Bishopf6783cd2020-10-27 19:25:09 -04001#pragma once
2
3#include <nlohmann/json.hpp>
Brad Bishop5e5d4452020-10-27 19:46:13 -04004
Brad Bishopf6783cd2020-10-27 19:25:09 -04005#include <string>
6#include <vector>
7namespace openpower
8{
Brad Bishopf6783cd2020-10-27 19:25:09 -04009namespace pel
10{
11using FFDCData = std::vector<std::pair<std::string, std::string>>;
12
13using json = nlohmann::json;
14
15/**
16 * Create boot error PEL
17 *
18 * @param[in] ffdcData - failure data to append to PEL
19 * @param[in] calloutData - callout data to append to PEL
20 */
21void createBootErrorPEL(const FFDCData& ffdcData, const json& calloutData);
22
23/**
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050024 * @brief Create a PEL for the specified event type and additional data
Andrew Geissler61febf02021-06-22 17:19:32 -050025 *
Jayanth Othayothac95c562021-07-16 05:56:04 -050026 * @param event - the event type
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050027 * @param[in] ffdcData - failure data to append to PEL
Andrew Geissler61febf02021-06-22 17:19:32 -050028 */
Jayanth Othayotha8d2f712021-09-20 07:02:51 -050029void createPEL(const std::string& event, const FFDCData& ffdcData = {});
Andrew Geissler61febf02021-06-22 17:19:32 -050030
31/**
Brad Bishopf6783cd2020-10-27 19:25:09 -040032 * @class FFDCFile
33 * @brief This class is used to create ffdc data file and to get fd
34 */
35class FFDCFile
36{
37 public:
38 FFDCFile() = delete;
39 FFDCFile(const FFDCFile&) = delete;
40 FFDCFile& operator=(const FFDCFile&) = delete;
41 FFDCFile(FFDCFile&&) = delete;
42 FFDCFile& operator=(FFDCFile&&) = delete;
43
44 /**
45 * Used to pass json object to create unique ffdc file by using
46 * passed json data.
47 */
48 explicit FFDCFile(const json& pHALCalloutData);
49
50 /**
51 * Used to remove created ffdc file.
52 */
53 ~FFDCFile();
54
55 /**
56 * Used to get created ffdc file file descriptor id.
57 *
58 * @return file descriptor id
59 */
60 int getFileFD() const;
61
62 private:
63 /**
64 * Used to store callout ffdc data from passed json object.
65 */
66 std::string calloutData;
67
68 /**
69 * Used to store unique ffdc file name.
70 */
71 std::string calloutFile;
72
73 /**
74 * Used to store created ffdc file descriptor id.
75 */
76 int fileFD;
77
78 /**
79 * Used to create ffdc file to pass PEL api for creating
80 * pel records.
81 *
82 * @return NULL
83 */
84 void prepareFFDCFile();
85
86 /**
87 * Create unique ffdc file.
88 *
89 * @return NULL
90 */
91 void createCalloutFile();
92
93 /**
94 * Used write json object value into created file.
95 *
96 * @return NULL
97 */
98 void writeCalloutData();
99
100 /**
101 * Used set ffdc file seek position begining to consume by PEL
102 *
103 * @return NULL
104 */
105 void setCalloutFileSeekPos();
106
107 /**
108 * Used to remove created ffdc file.
109 *
110 * @return NULL
111 */
112 void removeCalloutFile();
113
114}; // FFDCFile end
115
116} // namespace pel
117} // namespace openpower