1 #pragma once 2 3 #include "types.hpp" 4 5 #include <variant> 6 7 namespace vpd 8 { 9 /** 10 * @brief Interface class for parsers. 11 * 12 * Any concrete parser class, implementing parsing logic need to derive from 13 * this interface class and override the parse method declared in this class. 14 */ 15 class ParserInterface 16 { 17 public: 18 /** 19 * @brief Pure virtual function for parsing VPD file. 20 * 21 * The API needs to be overridden by all the classes deriving from parser 22 * inerface class to implement respective VPD parsing logic. 23 * 24 * @return parsed format for VPD data, depending upon the 25 * parsing logic. 26 */ 27 virtual types::VPDMapVariant parse() = 0; 28 29 /** 30 * @brief Read keyword's value from hardware 31 * 32 * @param[in] types::ReadVpdParams - Parameters required to perform read. 33 * 34 * @return keyword's value on successful read. Exception on failure. 35 */ readKeywordFromHardware(const types::ReadVpdParams)36 virtual types::DbusVariantType readKeywordFromHardware( 37 const types::ReadVpdParams) 38 { 39 return types::DbusVariantType(); 40 } 41 42 /** 43 * @brief API to write keyword's value on hardware. 44 * 45 * This virtual method is created to achieve runtime polymorphism for 46 * hardware writes on VPD of different types. This virtual method can be 47 * redefined at derived classess to implement write according to the type of 48 * VPD. 49 * 50 * @param[in] i_paramsToWriteData - Data required to perform write. 51 * 52 * @throw May throw exception depending on the implementation of derived 53 * methods. 54 * @return On success returns number of bytes written on hardware, On 55 * failure returns -1. 56 */ writeKeywordOnHardware(const types::WriteVpdParams i_paramsToWriteData)57 virtual int writeKeywordOnHardware( 58 const types::WriteVpdParams i_paramsToWriteData) 59 { 60 (void)i_paramsToWriteData; 61 return -1; 62 } 63 64 /** 65 * @brief Compares the parsed VPD data in this instance with that of 66 * the provided redundant VPD parser. 67 * 68 * This virtual method is created to achieve runtime polymorphism for 69 * comparing VPDs of different types. This virtual method can be 70 * redefined at derived classess to implement VPD comparion according to the 71 * type of VPD. 72 * 73 * @param[in] i_redundantParser - Shared pointer to redundant parser 74 * instance. 75 * 76 * @return true if all corresponding VPD fields match; false otherwise. 77 */ compareData(const std::shared_ptr<vpd::ParserInterface> & i_redundantParser)78 virtual bool compareData( 79 [[maybe_unused]] const std::shared_ptr<vpd::ParserInterface>& 80 i_redundantParser) noexcept 81 { 82 // @todo IpzVpdParser implements this API. Add implementations for all 83 // remaining concrete parser classes. 84 return false; 85 } 86 87 /** 88 * @brief Virtual destructor. 89 */ ~ParserInterface()90 virtual ~ParserInterface() {} 91 }; 92 } // namespace vpd 93