1d3335dfaSMatt Spinler #pragma once 2ad0e0476SAatir Manzur 3*a214ed30SHarisuddin Mohamed Isa #include "registry.hpp" 4d3335dfaSMatt Spinler #include "section_header.hpp" 5d3335dfaSMatt Spinler 6ad0e0476SAatir Manzur #include <optional> 7ad0e0476SAatir Manzur 8d3335dfaSMatt Spinler namespace openpower 9d3335dfaSMatt Spinler { 10d3335dfaSMatt Spinler namespace pels 11d3335dfaSMatt Spinler { 12d3335dfaSMatt Spinler /** 13d3335dfaSMatt Spinler * @class Section 14d3335dfaSMatt Spinler * 15d3335dfaSMatt Spinler * The base class for a PEL section. It contains the SectionHeader 16d3335dfaSMatt Spinler * as all sections start with it. 17d3335dfaSMatt Spinler * 18d3335dfaSMatt Spinler */ 19d3335dfaSMatt Spinler class Section 20d3335dfaSMatt Spinler { 21d3335dfaSMatt Spinler public: 22d3335dfaSMatt Spinler Section() = default; 23d3335dfaSMatt Spinler virtual ~Section() = default; 24d3335dfaSMatt Spinler Section(const Section&) = default; 25d3335dfaSMatt Spinler Section& operator=(const Section&) = default; 26d3335dfaSMatt Spinler Section(Section&&) = default; 27d3335dfaSMatt Spinler Section& operator=(Section&&) = default; 28d3335dfaSMatt Spinler 29d3335dfaSMatt Spinler /** 30d3335dfaSMatt Spinler * @brief Returns a reference to the SectionHeader 31d3335dfaSMatt Spinler */ 320688545bSMatt Spinler const SectionHeader& header() const 33d3335dfaSMatt Spinler { 34d3335dfaSMatt Spinler return _header; 35d3335dfaSMatt Spinler } 36d3335dfaSMatt Spinler 37d3335dfaSMatt Spinler /** 38d3335dfaSMatt Spinler * @brief Says if the section is valid. 39d3335dfaSMatt Spinler */ 40d3335dfaSMatt Spinler bool valid() const 41d3335dfaSMatt Spinler { 42d3335dfaSMatt Spinler return _valid; 43d3335dfaSMatt Spinler } 44d3335dfaSMatt Spinler 45cf5a8d0fSMatt Spinler /** 46cf5a8d0fSMatt Spinler * @brief Flatten the section into the stream 47cf5a8d0fSMatt Spinler * 48cf5a8d0fSMatt Spinler * @param[in] stream - The stream to write to 49cf5a8d0fSMatt Spinler */ 500688545bSMatt Spinler virtual void flatten(Stream& stream) const = 0; 51cf5a8d0fSMatt Spinler 52ad0e0476SAatir Manzur /** 53ad0e0476SAatir Manzur * @brief Get section in JSON. Derived classes to override when required to. 54ad0e0476SAatir Manzur * @return std::optional<std::string> - If a section comes with a JSON 55*a214ed30SHarisuddin Mohamed Isa * representation, this would return the string for it. 56ad0e0476SAatir Manzur */ 57ad0e0476SAatir Manzur virtual std::optional<std::string> getJSON() const 58ad0e0476SAatir Manzur { 59ad0e0476SAatir Manzur return std::nullopt; 60ad0e0476SAatir Manzur } 61ad0e0476SAatir Manzur 62*a214ed30SHarisuddin Mohamed Isa /** 63*a214ed30SHarisuddin Mohamed Isa * @brief Get section in JSON. Derived classes to override when required to. 64*a214ed30SHarisuddin Mohamed Isa * @param[in] registry - Registry object reference 65*a214ed30SHarisuddin Mohamed Isa * @return std::optional<std::string> - If a section comes with a JSON 66*a214ed30SHarisuddin Mohamed Isa * representation, this would return the string for it. 67*a214ed30SHarisuddin Mohamed Isa */ 68*a214ed30SHarisuddin Mohamed Isa virtual std::optional<std::string> 69*a214ed30SHarisuddin Mohamed Isa getJSON(message::Registry& registry) const 70*a214ed30SHarisuddin Mohamed Isa { 71*a214ed30SHarisuddin Mohamed Isa return std::nullopt; 72*a214ed30SHarisuddin Mohamed Isa } 73*a214ed30SHarisuddin Mohamed Isa 74d3335dfaSMatt Spinler protected: 75d3335dfaSMatt Spinler /** 76d3335dfaSMatt Spinler * @brief Returns the flattened size of the section header 77d3335dfaSMatt Spinler */ 78d3335dfaSMatt Spinler static constexpr size_t flattenedSize() 79d3335dfaSMatt Spinler { 80d3335dfaSMatt Spinler return SectionHeader::flattenedSize(); 81d3335dfaSMatt Spinler } 82d3335dfaSMatt Spinler 83d3335dfaSMatt Spinler /** 84d3335dfaSMatt Spinler * @brief Used to validate the section. 85d3335dfaSMatt Spinler * 86d3335dfaSMatt Spinler * Implemented by derived classes. 87d3335dfaSMatt Spinler */ 88d3335dfaSMatt Spinler virtual void validate() = 0; 89d3335dfaSMatt Spinler 90d3335dfaSMatt Spinler /** 91d3335dfaSMatt Spinler * @brief The section header structure. 92d3335dfaSMatt Spinler * 93d3335dfaSMatt Spinler * Filled in by derived classes. 94d3335dfaSMatt Spinler */ 95d3335dfaSMatt Spinler SectionHeader _header; 96d3335dfaSMatt Spinler 97d3335dfaSMatt Spinler /** 98d3335dfaSMatt Spinler * @brief The section valid flag. 99d3335dfaSMatt Spinler * 100d3335dfaSMatt Spinler * This is determined by the derived class. 101d3335dfaSMatt Spinler */ 102d3335dfaSMatt Spinler bool _valid = false; 103d3335dfaSMatt Spinler }; 104d3335dfaSMatt Spinler } // namespace pels 105d3335dfaSMatt Spinler } // namespace openpower 106