1 #pragma once 2 3 #include "section.hpp" 4 #include "stream.hpp" 5 6 namespace openpower::pels 7 { 8 9 /** 10 * @class ExtendedUserData 11 * 12 * This represents the Extended User Data section in a PEL. It is free form 13 * data that the creator knows the contents of. The component ID, version, and 14 * sub-type fields in the section header are used to identify the format. 15 * 16 * This section is used for one subsystem to add FFDC data to a PEL created 17 * by another subsystem. It is basically the same as a UserData section, 18 * except it has the creator ID of the section creator stored in the section. 19 * 20 * The Section base class handles the section header structure that every 21 * PEL section has at offset zero. 22 */ 23 class ExtendedUserData : public Section 24 { 25 public: 26 ExtendedUserData() = delete; 27 ~ExtendedUserData() = default; 28 ExtendedUserData(const ExtendedUserData&) = default; 29 ExtendedUserData& operator=(const ExtendedUserData&) = default; 30 ExtendedUserData(ExtendedUserData&&) = default; 31 ExtendedUserData& operator=(ExtendedUserData&&) = default; 32 33 /** 34 * @brief Constructor 35 * 36 * Fills in this class's data fields from the stream. 37 * 38 * @param[in] pel - the PEL data stream 39 */ 40 explicit ExtendedUserData(Stream& pel); 41 42 /** 43 * @brief Constructor 44 * 45 * Create a valid ExtendedUserData object with the passed in data. 46 * 47 * The component ID, subtype, and version are used to identify 48 * the data to know which parser to call. 49 * 50 * @param[in] componentID - Component ID of the creator 51 * @param[in] subType - The type of user data 52 * @param[in] version - The version of the data 53 */ 54 ExtendedUserData(uint16_t componentID, uint8_t subType, uint8_t version, 55 uint8_t creatorID, const std::vector<uint8_t>& data); 56 57 /** 58 * @brief Flatten the section into the stream 59 * 60 * @param[in] stream - The stream to write to 61 */ 62 void flatten(Stream& stream) const override; 63 64 /** 65 * @brief Returns the size of this section when flattened into a PEL 66 * 67 * @return size_t - the size of the section 68 */ 69 size_t flattenedSize() 70 { 71 return Section::flattenedSize() + sizeof(_creatorID) + 72 sizeof(_reserved1B) + sizeof(_reserved2B) + _data.size(); 73 } 74 75 /** 76 * @brief Returns the section creator ID field. 77 * 78 * @return uint8_t - The creator ID 79 */ 80 const uint8_t creatorID() const 81 { 82 return _creatorID; 83 } 84 85 /** 86 * @brief Returns the raw section data 87 * 88 * This doesn't include the creator ID. 89 * 90 * @return std::vector<uint8_t>& 91 */ 92 const std::vector<uint8_t>& data() const 93 { 94 return _data; 95 } 96 97 /** 98 * @brief Get the section contents in JSON 99 * 100 * @param[in] creatorID - Creator Subsystem ID - unused (see the .cpp) 101 * @param[in] plugins - Vector of strings of plugins found in filesystem 102 * 103 * @return The JSON as a string if a parser was found, 104 * otherwise std::nullopt. 105 */ 106 std::optional<std::string> 107 getJSON(uint8_t creatorID, 108 const std::vector<std::string>& plugins) const override; 109 110 /** 111 * @brief Shrink the section 112 * 113 * The new size must be between the current size and the minimum 114 * size, which is 12 bytes. If it isn't a 4 byte aligned value 115 * the code will do the aligning before the resize takes place. 116 * 117 * @param[in] newSize - The new size in bytes 118 * 119 * @return bool - true if successful, false else. 120 */ 121 bool shrink(size_t newSize) override; 122 123 private: 124 /** 125 * @brief Fills in the object from the stream data 126 * 127 * @param[in] stream - The stream to read from 128 */ 129 void unflatten(Stream& stream); 130 131 /** 132 * @brief Validates the section contents 133 * 134 * Updates _valid (in Section) with the results. 135 */ 136 void validate() override; 137 138 /** 139 * @brief The subsystem creator ID of the code that 140 * created this section. 141 */ 142 uint8_t _creatorID; 143 144 /** 145 * @brief Reserved 146 */ 147 uint8_t _reserved1B; 148 149 /** 150 * @brief Reserved 151 */ 152 uint16_t _reserved2B; 153 154 /** 155 * @brief The section data 156 */ 157 std::vector<uint8_t> _data; 158 }; 159 160 } // namespace openpower::pels 161