|
1 | 1 | #include "parser.hpp"
|
2 | 2 |
|
| 3 | +#include "constants.hpp" |
| 4 | + |
3 | 5 | #include <utility/dbus_utility.hpp>
|
4 | 6 | #include <utility/json_utility.hpp>
|
5 | 7 | #include <utility/vpd_specific_utility.hpp>
|
@@ -56,111 +58,144 @@ types::VPDMapVariant Parser::parse()
|
56 | 58 |
|
57 | 59 | int Parser::updateVpdKeyword(const types::WriteVpdParams& i_paramsToWriteData)
|
58 | 60 | {
|
59 |
| - // Update keyword's value on hardware |
60 | 61 | int l_bytesUpdatedOnHardware = -1;
|
61 | 62 | try
|
62 | 63 | {
|
63 |
| - std::shared_ptr<ParserInterface> l_vpdParserInstance = |
64 |
| - getVpdParserInstance(); |
65 |
| - l_bytesUpdatedOnHardware = |
66 |
| - l_vpdParserInstance->writeKeywordOnHardware(i_paramsToWriteData); |
67 |
| - } |
68 |
| - catch (const std::exception& l_exception) |
69 |
| - { |
70 |
| - logging::logMessage( |
71 |
| - "Error while updating keyword's value on hardware path " + |
72 |
| - m_vpdFilePath + ", error: " + std::string(l_exception.what())); |
73 |
| - // TODO : Log PEL |
74 |
| - return -1; |
75 |
| - } |
| 64 | + // Update keyword's value on hardware |
| 65 | + try |
| 66 | + { |
| 67 | + std::shared_ptr<ParserInterface> l_vpdParserInstance = |
| 68 | + getVpdParserInstance(); |
| 69 | + l_bytesUpdatedOnHardware = |
| 70 | + l_vpdParserInstance->writeKeywordOnHardware( |
| 71 | + i_paramsToWriteData); |
| 72 | + } |
| 73 | + catch (const std::exception& l_exception) |
| 74 | + { |
| 75 | + std::string l_errMsg( |
| 76 | + "Error while updating keyword's value on hardware path " + |
| 77 | + m_vpdFilePath + ", error: " + std::string(l_exception.what())); |
76 | 78 |
|
77 |
| - auto [l_fruPath, l_inventoryObjPath, l_redundantFruPath] = |
78 |
| - jsonUtility::getAllPathsToUpdateKeyword(m_parsedJson, m_vpdFilePath); |
| 79 | + // TODO : Log PEL |
79 | 80 |
|
80 |
| - // If inventory D-bus object path is present, update keyword's value on DBus |
81 |
| - if (!l_inventoryObjPath.empty()) |
82 |
| - { |
83 |
| - types::Record l_recordName; |
84 |
| - std::string l_interfaceName; |
85 |
| - std::string l_propertyName; |
86 |
| - types::DbusVariantType l_keywordValue; |
| 81 | + throw std::runtime_error(l_errMsg); |
| 82 | + } |
87 | 83 |
|
88 |
| - if (const types::IpzData* l_ipzData = |
89 |
| - std::get_if<types::IpzData>(&i_paramsToWriteData)) |
| 84 | + auto [l_fruPath, l_inventoryObjPath, l_redundantFruPath] = |
| 85 | + jsonUtility::getAllPathsToUpdateKeyword(m_parsedJson, |
| 86 | + m_vpdFilePath); |
| 87 | + |
| 88 | + // If inventory D-bus object path is present, update keyword's value on |
| 89 | + // DBus |
| 90 | + if (!l_inventoryObjPath.empty()) |
90 | 91 | {
|
91 |
| - l_recordName = std::get<0>(*l_ipzData); |
92 |
| - l_interfaceName = constants::ipzVpdInf + l_recordName; |
93 |
| - l_propertyName = std::get<1>(*l_ipzData); |
| 92 | + types::Record l_recordName; |
| 93 | + std::string l_interfaceName; |
| 94 | + std::string l_propertyName; |
| 95 | + types::DbusVariantType l_keywordValue; |
94 | 96 |
|
95 |
| - try |
| 97 | + if (const types::IpzData* l_ipzData = |
| 98 | + std::get_if<types::IpzData>(&i_paramsToWriteData)) |
96 | 99 | {
|
97 |
| - // Read keyword's value from hardware to write the same on |
98 |
| - // D-bus. |
99 |
| - std::shared_ptr<ParserInterface> l_vpdParserInstance = |
100 |
| - getVpdParserInstance(); |
101 |
| - |
102 |
| - logging::logMessage("Performing VPD read on " + m_vpdFilePath); |
103 |
| - |
104 |
| - l_keywordValue = l_vpdParserInstance->readKeywordFromHardware( |
105 |
| - types::ReadVpdParams( |
106 |
| - std::make_tuple(l_recordName, l_propertyName))); |
| 100 | + l_recordName = std::get<0>(*l_ipzData); |
| 101 | + l_interfaceName = constants::ipzVpdInf + l_recordName; |
| 102 | + l_propertyName = std::get<1>(*l_ipzData); |
| 103 | + |
| 104 | + try |
| 105 | + { |
| 106 | + // Read keyword's value from hardware to write the same on |
| 107 | + // D-bus. |
| 108 | + std::shared_ptr<ParserInterface> l_vpdParserInstance = |
| 109 | + getVpdParserInstance(); |
| 110 | + |
| 111 | + logging::logMessage("Performing VPD read on " + |
| 112 | + m_vpdFilePath); |
| 113 | + |
| 114 | + l_keywordValue = |
| 115 | + l_vpdParserInstance->readKeywordFromHardware( |
| 116 | + types::ReadVpdParams( |
| 117 | + std::make_tuple(l_recordName, l_propertyName))); |
| 118 | + } |
| 119 | + catch (const std::exception& l_exception) |
| 120 | + { |
| 121 | + // Unable to read keyword's value from hardware. |
| 122 | + std::string l_errMsg( |
| 123 | + "Error while reading keyword's value from hadware path " + |
| 124 | + m_vpdFilePath + |
| 125 | + ", error: " + std::string(l_exception.what())); |
| 126 | + |
| 127 | + // TODO: Log PEL |
| 128 | + |
| 129 | + throw std::runtime_error(l_errMsg); |
| 130 | + } |
107 | 131 | }
|
108 |
| - catch (const std::exception& l_exception) |
| 132 | + else |
109 | 133 | {
|
110 |
| - // Unable to read keyword's value from hardware. |
111 |
| - logging::logMessage( |
112 |
| - "Error while reading keyword's value from hadware path " + |
113 |
| - m_vpdFilePath + |
114 |
| - ", error: " + std::string(l_exception.what())); |
115 |
| - // TODO: Log PEL |
116 |
| - return -1; |
| 134 | + // Input parameter type provided isn't compatible to perform |
| 135 | + // update. |
| 136 | + std::string l_errMsg( |
| 137 | + "Input parameter type isn't compatible to update keyword's value on DBus for object path: " + |
| 138 | + l_inventoryObjPath); |
| 139 | + throw std::runtime_error(l_errMsg); |
117 | 140 | }
|
118 |
| - } |
119 |
| - else |
120 |
| - { |
121 |
| - // Input parameter type provided isn't compatible to perform update. |
122 |
| - logging::logMessage( |
123 |
| - "Input parameter type isn't compatible to update keyword's value on DBus for object path: " + |
124 |
| - l_inventoryObjPath); |
125 |
| - return -1; |
126 |
| - } |
127 | 141 |
|
128 |
| - // Get D-bus name for the given keyword |
129 |
| - l_propertyName = |
130 |
| - vpdSpecificUtility::getDbusPropNameForGivenKw(l_propertyName); |
| 142 | + // Get D-bus name for the given keyword |
| 143 | + l_propertyName = |
| 144 | + vpdSpecificUtility::getDbusPropNameForGivenKw(l_propertyName); |
131 | 145 |
|
132 |
| - // Create D-bus object map |
133 |
| - types::ObjectMap l_dbusObjMap = {std::make_pair( |
134 |
| - l_inventoryObjPath, |
135 |
| - types::InterfaceMap{std::make_pair( |
136 |
| - l_interfaceName, types::PropertyMap{std::make_pair( |
137 |
| - l_propertyName, l_keywordValue)})})}; |
| 146 | + // Create D-bus object map |
| 147 | + types::ObjectMap l_dbusObjMap = {std::make_pair( |
| 148 | + l_inventoryObjPath, |
| 149 | + types::InterfaceMap{std::make_pair( |
| 150 | + l_interfaceName, types::PropertyMap{std::make_pair( |
| 151 | + l_propertyName, l_keywordValue)})})}; |
138 | 152 |
|
139 |
| - // Call PIM's Notify method to perform update |
140 |
| - if (!dbusUtility::callPIM(std::move(l_dbusObjMap))) |
| 153 | + // Call PIM's Notify method to perform update |
| 154 | + if (!dbusUtility::callPIM(std::move(l_dbusObjMap))) |
| 155 | + { |
| 156 | + // Call to PIM's Notify method failed. |
| 157 | + std::string l_errMsg("Notify PIM is failed for object path: " + |
| 158 | + l_inventoryObjPath); |
| 159 | + throw std::runtime_error(l_errMsg); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + // Update keyword's value on redundant hardware if present |
| 164 | + if (!l_redundantFruPath.empty()) |
141 | 165 | {
|
142 |
| - // Call to PIM's Notify method failed. |
143 |
| - logging::logMessage("Notify PIM is failed for object path: " + |
144 |
| - l_inventoryObjPath); |
145 |
| - return -1; |
| 166 | + if (updateVpdKeywordOnRedundantPath(l_redundantFruPath, |
| 167 | + i_paramsToWriteData) < 0) |
| 168 | + { |
| 169 | + std::string l_errMsg( |
| 170 | + "Error while updating keyword's value on redundant path " + |
| 171 | + l_redundantFruPath); |
| 172 | + throw std::runtime_error(l_errMsg); |
| 173 | + } |
146 | 174 | }
|
147 |
| - } |
148 | 175 |
|
149 |
| - // Update keyword's value on redundant hardware if present |
150 |
| - if (!l_redundantFruPath.empty()) |
| 176 | + // TODO: Check if revert is required when any of the writes fails. |
| 177 | + // TODO: Handle error logging |
| 178 | + } |
| 179 | + catch (const std::exception& l_ex) |
151 | 180 | {
|
152 |
| - if (updateVpdKeywordOnRedundantPath(l_redundantFruPath, |
153 |
| - i_paramsToWriteData) < 0) |
| 181 | + std::string l_keywordIdentifier{}; |
| 182 | + if (const types::IpzData* l_ipzData = |
| 183 | + std::get_if<types::IpzData>(&i_paramsToWriteData)) |
154 | 184 | {
|
155 |
| - logging::logMessage( |
156 |
| - "Error while updating keyword's value on redundant path " + |
157 |
| - l_redundantFruPath); |
158 |
| - return -1; |
| 185 | + l_keywordIdentifier = std::get<0>(*l_ipzData) + ":" + |
| 186 | + std::get<1>(*l_ipzData); |
159 | 187 | }
|
160 |
| - } |
| 188 | + else if (const types::KwData* l_kwData = |
| 189 | + std::get_if<types::KwData>(&i_paramsToWriteData)) |
| 190 | + { |
| 191 | + l_keywordIdentifier = std::get<0>(*l_kwData); |
| 192 | + } |
| 193 | + logging::logMessage( |
| 194 | + "Update VPD Keyword failed for : " + l_keywordIdentifier + |
| 195 | + " failed due to error: " + l_ex.what()); |
161 | 196 |
|
162 |
| - // TODO: Check if revert is required when any of the writes fails. |
163 |
| - // TODO: Handle error logging |
| 197 | + return constants::FAILURE; |
| 198 | + } |
164 | 199 |
|
165 | 200 | // All updates are successful.
|
166 | 201 | return l_bytesUpdatedOnHardware;
|
|
0 commit comments