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. |
| 54 | * @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] | 55 | * representation, this would return the string for it. |
Aatir Manzur | ad0e047 | 2019-10-07 13:18:37 -0500 | [diff] [blame] | 56 | */ |
| 57 | virtual std::optional<std::string> getJSON() const |
| 58 | { |
| 59 | return std::nullopt; |
| 60 | } |
| 61 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 62 | /** |
| 63 | * @brief Get section in JSON. Derived classes to override when required to. |
| 64 | * @param[in] registry - Registry object reference |
| 65 | * @return std::optional<std::string> - If a section comes with a JSON |
| 66 | * representation, this would return the string for it. |
| 67 | */ |
| 68 | virtual std::optional<std::string> |
| 69 | getJSON(message::Registry& registry) const |
| 70 | { |
| 71 | return std::nullopt; |
| 72 | } |
| 73 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 74 | protected: |
| 75 | /** |
| 76 | * @brief Returns the flattened size of the section header |
| 77 | */ |
| 78 | static constexpr size_t flattenedSize() |
| 79 | { |
| 80 | return SectionHeader::flattenedSize(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @brief Used to validate the section. |
| 85 | * |
| 86 | * Implemented by derived classes. |
| 87 | */ |
| 88 | virtual void validate() = 0; |
| 89 | |
| 90 | /** |
| 91 | * @brief The section header structure. |
| 92 | * |
| 93 | * Filled in by derived classes. |
| 94 | */ |
| 95 | SectionHeader _header; |
| 96 | |
| 97 | /** |
| 98 | * @brief The section valid flag. |
| 99 | * |
| 100 | * This is determined by the derived class. |
| 101 | */ |
| 102 | bool _valid = false; |
| 103 | }; |
| 104 | } // namespace pels |
| 105 | } // namespace openpower |