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