xref: /openbmc/openpower-vpd-parser/vpd-manager/include/parser_interface.hpp (revision 43fedabc032ba7c209b58111b6c35c7d95a9f14e)
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 Virtual destructor.
66       */
~ParserInterface()67      virtual ~ParserInterface() {}
68  };
69  } // namespace vpd
70