1*b64983f0SShantappa Teekappanavar #pragma once 2*b64983f0SShantappa Teekappanavar 3*b64983f0SShantappa Teekappanavar #include "file_descriptor.hpp" 4*b64983f0SShantappa Teekappanavar #include "utils.hpp" 5*b64983f0SShantappa Teekappanavar #include "xyz/openbmc_project/Logging/Create/server.hpp" 6*b64983f0SShantappa Teekappanavar 7*b64983f0SShantappa Teekappanavar #include <nlohmann/json.hpp> 8*b64983f0SShantappa Teekappanavar 9*b64983f0SShantappa Teekappanavar #include <cstdint> 10*b64983f0SShantappa Teekappanavar #include <filesystem> 11*b64983f0SShantappa Teekappanavar 12*b64983f0SShantappa Teekappanavar namespace watchdog 13*b64983f0SShantappa Teekappanavar { 14*b64983f0SShantappa Teekappanavar namespace dump 15*b64983f0SShantappa Teekappanavar { 16*b64983f0SShantappa Teekappanavar 17*b64983f0SShantappa Teekappanavar namespace fs = std::filesystem; 18*b64983f0SShantappa Teekappanavar using FFDCFormat = 19*b64983f0SShantappa Teekappanavar sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat; 20*b64983f0SShantappa Teekappanavar using FFDCTuple = 21*b64983f0SShantappa Teekappanavar std::tuple<FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>; 22*b64983f0SShantappa Teekappanavar 23*b64983f0SShantappa Teekappanavar using ::nlohmann::json; 24*b64983f0SShantappa Teekappanavar /** 25*b64983f0SShantappa Teekappanavar * @class FFDCFile 26*b64983f0SShantappa Teekappanavar * 27*b64983f0SShantappa Teekappanavar * File that contains FFDC (first failure data capture) data in json format. 28*b64983f0SShantappa Teekappanavar * 29*b64983f0SShantappa Teekappanavar * This class is used to store FFDC json callout data in an error log. 30*b64983f0SShantappa Teekappanavar */ 31*b64983f0SShantappa Teekappanavar class FFDCFile 32*b64983f0SShantappa Teekappanavar { 33*b64983f0SShantappa Teekappanavar public: 34*b64983f0SShantappa Teekappanavar // Specify which compiler-generated methods we want 35*b64983f0SShantappa Teekappanavar FFDCFile() = delete; 36*b64983f0SShantappa Teekappanavar FFDCFile(const FFDCFile&) = delete; 37*b64983f0SShantappa Teekappanavar FFDCFile(FFDCFile&&) = default; 38*b64983f0SShantappa Teekappanavar FFDCFile& operator=(const FFDCFile&) = delete; 39*b64983f0SShantappa Teekappanavar FFDCFile& operator=(FFDCFile&&) = default; 40*b64983f0SShantappa Teekappanavar ~FFDCFile(); 41*b64983f0SShantappa Teekappanavar 42*b64983f0SShantappa Teekappanavar /** 43*b64983f0SShantappa Teekappanavar * @brief Constructor 44*b64983f0SShantappa Teekappanavar * 45*b64983f0SShantappa Teekappanavar * @details Creates the FFDC file by using passed json data. 46*b64983f0SShantappa Teekappanavar * 47*b64983f0SShantappa Teekappanavar * Throws an exception if an error occurs. 48*b64983f0SShantappa Teekappanavar */ 49*b64983f0SShantappa Teekappanavar explicit FFDCFile(const json& calloutData); 50*b64983f0SShantappa Teekappanavar 51*b64983f0SShantappa Teekappanavar /** 52*b64983f0SShantappa Teekappanavar * @brief Returns the file descriptor for the file. 53*b64983f0SShantappa Teekappanavar * 54*b64983f0SShantappa Teekappanavar * @details The file is open for both reading and writing. 55*b64983f0SShantappa Teekappanavar * 56*b64983f0SShantappa Teekappanavar * @return file descriptor 57*b64983f0SShantappa Teekappanavar */ getFileDescriptor() const58*b64983f0SShantappa Teekappanavar int getFileDescriptor() const 59*b64983f0SShantappa Teekappanavar { 60*b64983f0SShantappa Teekappanavar // Return the integer file descriptor within the FileDescriptor object 61*b64983f0SShantappa Teekappanavar return descriptor(); 62*b64983f0SShantappa Teekappanavar } 63*b64983f0SShantappa Teekappanavar 64*b64983f0SShantappa Teekappanavar /** 65*b64983f0SShantappa Teekappanavar * @brief Returns the absolute path to the file. 66*b64983f0SShantappa Teekappanavar * 67*b64983f0SShantappa Teekappanavar * @return absolute path 68*b64983f0SShantappa Teekappanavar */ getPath() const69*b64983f0SShantappa Teekappanavar const fs::path& getPath() const 70*b64983f0SShantappa Teekappanavar { 71*b64983f0SShantappa Teekappanavar return tempFile.getPath(); 72*b64983f0SShantappa Teekappanavar } 73*b64983f0SShantappa Teekappanavar 74*b64983f0SShantappa Teekappanavar private: 75*b64983f0SShantappa Teekappanavar /** 76*b64983f0SShantappa Teekappanavar * @brief Temporary file where FFDC data is stored. 77*b64983f0SShantappa Teekappanavar * 78*b64983f0SShantappa Teekappanavar * @details The TemporaryFile destructor will automatically delete the file 79*b64983f0SShantappa Teekappanavar * if it was not explicitly deleted using remove(). 80*b64983f0SShantappa Teekappanavar */ 81*b64983f0SShantappa Teekappanavar TemporaryFile tempFile{}; 82*b64983f0SShantappa Teekappanavar 83*b64983f0SShantappa Teekappanavar /** 84*b64983f0SShantappa Teekappanavar * @brief File descriptor for reading from/writing to the file. 85*b64983f0SShantappa Teekappanavar * 86*b64983f0SShantappa Teekappanavar * @details The FileDescriptor destructor will automatically close the file 87*b64983f0SShantappa Teekappanavar * if it was not explicitly closed using remove(). 88*b64983f0SShantappa Teekappanavar */ 89*b64983f0SShantappa Teekappanavar FileDescriptor descriptor{}; 90*b64983f0SShantappa Teekappanavar 91*b64983f0SShantappa Teekappanavar /** 92*b64983f0SShantappa Teekappanavar * @brief Used to store callout ffdc data from passed json object 93*b64983f0SShantappa Teekappanavar */ 94*b64983f0SShantappa Teekappanavar std::string calloutData; 95*b64983f0SShantappa Teekappanavar 96*b64983f0SShantappa Teekappanavar /** 97*b64983f0SShantappa Teekappanavar * @brief Creates FFDC file for creating PEL records. 98*b64983f0SShantappa Teekappanavar */ 99*b64983f0SShantappa Teekappanavar void prepareFFDCFile(); 100*b64983f0SShantappa Teekappanavar }; 101*b64983f0SShantappa Teekappanavar 102*b64983f0SShantappa Teekappanavar } // namespace dump 103*b64983f0SShantappa Teekappanavar } // namespace watchdog 104