blob: a4c882df7e8efc716334d25d0bdeb12fd91a27f0 [file] [log] [blame]
Eddie James2f9f9bb2021-09-20 14:26:31 -05001#pragma once
2
3#include "config.h"
4
5#include "occ_errors.hpp"
6
7namespace open_power
8{
9namespace occ
10{
11
12/** @class FFDC
13 * @brief Monitors for SBE FFDC availability
14 */
15class FFDC : public Error
16{
17 public:
18 FFDC() = delete;
19 FFDC(const FFDC&) = delete;
20 FFDC& operator=(const FFDC&) = delete;
21 FFDC(FFDC&&) = default;
22 FFDC& operator=(FFDC&&) = default;
23
24 /** @brief Constructs the FFDC object
25 *
26 * @param[in] event - reference to sd_event unique_ptr
27 * @param[in] file - File used by driver to communicate FFDC data
28 * @param[in] instance - OCC instance number
29 */
30 FFDC(EventPtr& event, const fs::path& file, unsigned int instance) :
31 Error(event, file, nullptr), instance(instance)
32 {
33 // Nothing to do here.
34 }
35
36 ~FFDC()
37 {
38 for (auto&& it : temporaryFiles)
39 {
40 close(it.second);
41 fs::remove(it.first);
42 }
43 }
44
45 /** @brief Helper function to create a PEL with the OpenPower DBus
46 * interface
47 *
48 * @param[in] path - the DBus error path
49 * @param[in] src6 - the SBE error SRC6 word
50 * @param[in] msg - the error message
51 * @param[in] fd - the file descriptor for any FFDC
52 */
53 static uint32_t createPEL(const char* path, uint32_t src6, const char* msg,
54 int fd = -1);
55
56 private:
57 /** @brief OCC instance number. Ex, 0,1, etc */
58 unsigned int instance;
59
60 /** @brief Stores the temporary files and file descriptors
61 * in usage. They will be cleaned up when the class
62 * is destroyed (when the application exits).
63 */
64 std::vector<std::pair<fs::path, int>> temporaryFiles;
65
66 /** @brief When the error event is received, analyzes it
67 * and makes a callback to error handler if the
68 * content denotes an error condition
69 */
70 void analyzeEvent() override;
71};
72
73} // namespace occ
74} // namespace open_power