blob: 3b12089420de51c4bc8384edd4da6dc4a5de29f0 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#pragma once
2
3#include "types.hpp"
4
5#include <variant>
6
7namespace 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 */
15class 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 */
Patrick Williams43fedab2025-02-03 14:28:05 -050036 virtual types::DbusVariantType readKeywordFromHardware(
37 const types::ReadVpdParams)
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050038 {
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 */
Patrick Williams43fedab2025-02-03 14:28:05 -050057 virtual int writeKeywordOnHardware(
58 const types::WriteVpdParams i_paramsToWriteData)
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050059 {
60 (void)i_paramsToWriteData;
61 return -1;
62 }
63
64 /**
65 * @brief Virtual destructor.
66 */
67 virtual ~ParserInterface() {}
68};
69} // namespace vpd