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