blob: 2e32ca5aa6a9a995f4ef7ac69a9784e5c87d0919 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#pragma once
2
3#include "parser_factory.hpp"
4#include "parser_interface.hpp"
5#include "types.hpp"
6
7#include <string.h>
8
9#include <nlohmann/json.hpp>
10
11#include <iostream>
12
13namespace vpd
14{
15/**
16 * @brief Class to implement a wrapper around concrete parser class.
17 * The class based on VPD file passed, selects the required parser and exposes
18 * API to parse the VPD and return the parsed data in required format to the
19 * caller.
20 */
21class Parser
22{
23 public:
24 /**
25 * @brief Constructor
26 *
27 * @param[in] vpdFilePath - Path to the VPD file.
28 * @param[in] parsedJson - Parsed JSON.
29 */
30 Parser(const std::string& vpdFilePath, nlohmann::json parsedJson);
31
32 /**
33 * @brief API to implement a generic parsing logic.
34 *
35 * This API is called to select parser based on the vpd data extracted from
36 * the VPD file path passed to the constructor of the class.
37 * It further parses the data based on the parser selected and returned
38 * parsed map to the caller.
39 */
40 types::VPDMapVariant parse();
41
42 /**
43 * @brief API to get parser instance based on VPD type.
44 *
45 * This API detects the VPD type based on the file path passed to the
46 * constructor of the class and returns the respective parser instance.
47 *
48 * @return Parser instance.
49 */
50 std::shared_ptr<vpd::ParserInterface> getVpdParserInstance();
51
52 /**
53 * @brief Update keyword value.
54 *
55 * This API is used to update keyword value on the EEPROM path and its
56 * redundant path(s) if any taken from system config JSON. And also updates
57 * keyword value on DBus.
58 *
59 * To update IPZ type VPD, input parameter for writing should be in the form
60 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
61 *
62 * To update Keyword type VPD, input parameter for writing should be in the
63 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
64 *
65 * @param[in] i_paramsToWriteData - Input details.
66 *
67 * @return On success returns number of bytes written, on failure returns
68 * -1.
69 */
70 int updateVpdKeyword(const types::WriteVpdParams& i_paramsToWriteData);
71
72 /**
Souvik Roy9b0b0fd2025-08-08 05:20:23 +000073 * @brief Update keyword value.
74 *
75 * This API is used to update keyword value on the EEPROM path and its
76 * redundant path(s) if any taken from system config JSON. And also updates
77 * keyword value on DBus.
78 *
79 * To update IPZ type VPD, input parameter for writing should be in the form
80 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
81 *
82 * To update Keyword type VPD, input parameter for writing should be in the
83 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
84 *
85 * @param[in] i_paramsToWriteData - Input details.
86 * @param[in] o_updatedValue - Actual value which has been updated on
87 * hardware.
88 *
89 * @return On success returns number of bytes written, on failure returns
90 * -1.
91 */
92 int updateVpdKeyword(const types::WriteVpdParams& i_paramsToWriteData,
93 types::DbusVariantType& o_updatedValue);
94
95 /**
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050096 * @brief Update keyword value on hardware.
97 *
98 * This API is used to update keyword value on the hardware path.
99 *
100 * To update IPZ type VPD, input parameter for writing should be in the form
101 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
102 *
103 * To update Keyword type VPD, input parameter for writing should be in the
104 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
105 *
106 * @param[in] i_paramsToWriteData - Input details.
107 *
108 * @return On success returns number of bytes written, on failure returns
109 * -1.
110 */
111 int updateVpdKeywordOnHardware(
112 const types::WriteVpdParams& i_paramsToWriteData);
113
114 private:
115 /**
116 * @brief Update keyword value on redundant path.
117 *
118 * This API is used to update keyword value on the given redundant path(s).
119 *
120 * To update IPZ type VPD, input parameter for writing should be in the form
121 * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
122 *
123 * To update Keyword type VPD, input parameter for writing should be in the
124 * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
125 *
126 * @param[in] i_fruPath - Redundant EEPROM path.
127 * @param[in] i_paramsToWriteData - Input details.
128 *
129 * @return On success returns number of bytes written, on failure returns
130 * -1.
131 */
132 int updateVpdKeywordOnRedundantPath(
133 const std::string& i_fruPath,
134 const types::WriteVpdParams& i_paramsToWriteData);
135
136 // holds offfset to VPD if applicable.
137 size_t m_vpdStartOffset = 0;
138
139 // Path to the VPD file
140 const std::string& m_vpdFilePath;
141
142 // Path to configuration file, can be empty.
143 nlohmann::json m_parsedJson;
144
145 // Vector to hold VPD.
146 types::BinaryVector m_vpdVector;
147
148}; // parser
149} // namespace vpd