Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #pragma once |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 2 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 3 | #include "registry.hpp" |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 4 | #include "section_header.hpp" |
| 5 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 6 | #include <optional> |
| 7 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 8 | namespace openpower |
| 9 | { |
| 10 | namespace pels |
| 11 | { |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 12 | /** |
| 13 | * @class Section |
| 14 | * |
| 15 | * The base class for a PEL section. It contains the SectionHeader |
| 16 | * as all sections start with it. |
| 17 | * |
| 18 | */ |
| 19 | class Section |
| 20 | { |
| 21 | public: |
| 22 | Section() = default; |
| 23 | virtual ~Section() = default; |
| 24 | Section(const Section&) = default; |
| 25 | Section& operator=(const Section&) = default; |
| 26 | Section(Section&&) = default; |
| 27 | Section& operator=(Section&&) = default; |
| 28 | |
| 29 | /** |
| 30 | * @brief Returns a reference to the SectionHeader |
| 31 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 32 | const SectionHeader& header() const |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 33 | { |
| 34 | return _header; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @brief Says if the section is valid. |
| 39 | */ |
| 40 | bool valid() const |
| 41 | { |
| 42 | return _valid; |
| 43 | } |
| 44 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 45 | /** |
| 46 | * @brief Flatten the section into the stream |
| 47 | * |
| 48 | * @param[in] stream - The stream to write to |
| 49 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 50 | virtual void flatten(Stream& stream) const = 0; |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 51 | |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 52 | /** |
| 53 | * @brief Get section in JSON. Derived classes to override when required to. |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 54 | * |
| 55 | * @param[in] creatorID - The creator ID for the PEL |
| 56 | * |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 57 | * @return std::optional<std::string> - If a section comes with a JSON |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 58 | * representation, this would return the string for it. |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 59 | */ |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 60 | virtual std::optional<std::string> getJSON(uint8_t /* creatorID*/) const |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 61 | { |
| 62 | return std::nullopt; |
| 63 | } |
| 64 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 65 | /** |
| 66 | * @brief Get section in JSON. Derived classes to override when required to. |
| 67 | * @param[in] registry - Registry object reference |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 68 | * @param[in] plugins - Vector of strings of plugins found in filesystem |
| 69 | * @param[in] creatorID - Creator Subsystem ID from Private Header |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 70 | * @return std::optional<std::string> - If a section comes with a JSON |
| 71 | * representation, this would return the string for it. |
| 72 | */ |
| 73 | virtual std::optional<std::string> |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 74 | getJSON(message::Registry& /*registry*/, |
| 75 | const std::vector<std::string>& /*plugins*/, |
| 76 | uint8_t /*creatorID*/) const |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 77 | { |
| 78 | return std::nullopt; |
| 79 | } |
| 80 | |
Matt Spinler | cbf3c4d | 2020-03-24 15:34:52 -0500 | [diff] [blame] | 81 | /** |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 82 | * @brief Get section in JSON. Derived classes to override when required to. |
| 83 | * @param[in] creatorID - Creator Subsystem ID from Private Header |
Harisuddin Mohamed Isa | 3fdcd4e | 2020-08-26 11:56:42 +0800 | [diff] [blame] | 84 | * @param[in] plugins - Vector of strings of plugins found in filesystem |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 85 | * @return std::optional<std::string> - If a section comes with a JSON |
| 86 | * representation, this would return the string for it. |
| 87 | */ |
Harisuddin Mohamed Isa | 3fdcd4e | 2020-08-26 11:56:42 +0800 | [diff] [blame] | 88 | virtual std::optional<std::string> |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 89 | getJSON(uint8_t /*creatorID*/, |
| 90 | const std::vector<std::string>& /*plugins*/) const |
Harisuddin Mohamed Isa | f67bafd | 2020-07-06 17:51:21 +0800 | [diff] [blame] | 91 | { |
| 92 | return std::nullopt; |
| 93 | } |
| 94 | |
| 95 | /** |
Matt Spinler | cbf3c4d | 2020-03-24 15:34:52 -0500 | [diff] [blame] | 96 | * @brief Shrinks a PEL section |
| 97 | * |
| 98 | * If this is even possible for a section depends on which section |
| 99 | * it is. If a section cannot be shrunk, it doesn't need to implement |
| 100 | * shrink so it will just return false, meaning no shrinking was done. |
| 101 | * |
| 102 | * If a section can be shrunk, this function will be overridden in that |
| 103 | * class. |
| 104 | * |
| 105 | * @param[in] newSize - The new size, in bytes, to shrink to |
| 106 | * |
| 107 | * @return bool - true if successful, false else |
| 108 | */ |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 109 | virtual bool shrink(size_t /*newSize*/) |
Matt Spinler | cbf3c4d | 2020-03-24 15:34:52 -0500 | [diff] [blame] | 110 | { |
| 111 | return false; |
| 112 | } |
| 113 | |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 114 | /** |
| 115 | * @brief Returns any debug data stored in the object |
| 116 | * |
| 117 | * @return std::vector<std::string>& - The debug data |
| 118 | */ |
| 119 | const std::vector<std::string>& getDebugData() const |
| 120 | { |
| 121 | return _debugData; |
| 122 | } |
| 123 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 124 | protected: |
| 125 | /** |
| 126 | * @brief Returns the flattened size of the section header |
| 127 | */ |
| 128 | static constexpr size_t flattenedSize() |
| 129 | { |
| 130 | return SectionHeader::flattenedSize(); |
| 131 | } |
| 132 | |
| 133 | /** |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 134 | * @brief Adds debug data to the object that may be displayed |
| 135 | * in a UserData section in the PEL. |
| 136 | * |
| 137 | * @param[in] data - The new entry to add to the vector of data. |
| 138 | */ |
| 139 | void addDebugData(const std::string& data) |
| 140 | { |
| 141 | _debugData.push_back(data); |
| 142 | } |
| 143 | |
| 144 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 145 | * @brief Used to validate the section. |
| 146 | * |
| 147 | * Implemented by derived classes. |
| 148 | */ |
| 149 | virtual void validate() = 0; |
| 150 | |
| 151 | /** |
| 152 | * @brief The section header structure. |
| 153 | * |
| 154 | * Filled in by derived classes. |
| 155 | */ |
| 156 | SectionHeader _header; |
| 157 | |
| 158 | /** |
| 159 | * @brief The section valid flag. |
| 160 | * |
| 161 | * This is determined by the derived class. |
| 162 | */ |
| 163 | bool _valid = false; |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * @brief Messages that derived classes can add during construction |
| 167 | * of a PEL when something happens that would be useful to |
| 168 | * store in the PEL. This may get added into a UserData section |
| 169 | * in the PEL. |
| 170 | */ |
| 171 | std::vector<std::string> _debugData; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 172 | }; |
| 173 | } // namespace pels |
| 174 | } // namespace openpower |