@@ -991,7 +991,53 @@ int VpdTool::handleMoreOption(
991991 throw std::runtime_error (" Invalid JSON" );
992992 }
993993
994- while (true )
994+ std::string l_srcVpdPath;
995+
996+ if (auto l_vpdPath = i_parsedJsonObj[" source" ].value (" hardwarePath" ,
997+ " " );
998+ !l_vpdPath.empty ())
999+ {
1000+ l_srcVpdPath = l_vpdPath;
1001+ }
1002+ else if (auto l_vpdPath =
1003+ i_parsedJsonObj[" source" ].value (" inventoryPath" , " " );
1004+ !l_vpdPath.empty ())
1005+ {
1006+ l_srcVpdPath = l_vpdPath;
1007+ }
1008+ else
1009+ {
1010+ throw std::runtime_error (
1011+ " source path information is missing in JSON" );
1012+ }
1013+
1014+ auto updateKeywordValue =
1015+ [](std::string io_vpdPath, const std::string& i_recordName,
1016+ const std::string& i_keywordName,
1017+ const types::BinaryVector& i_keywordValue) -> int {
1018+ int l_rc = constants::FAILURE;
1019+
1020+ try
1021+ {
1022+ auto l_paramsToWrite = std::make_tuple (
1023+ i_recordName, i_keywordName, i_keywordValue);
1024+ l_rc = utils::writeKeyword (io_vpdPath, l_paramsToWrite);
1025+
1026+ if (l_rc > 0 )
1027+ {
1028+ std::cout << std::endl
1029+ << " Data updated successfully." << std::endl;
1030+ }
1031+ }
1032+ catch (const std::exception& l_ex)
1033+ {
1034+ // TODO: Enable log when verbose is enabled.
1035+ std::cerr << l_ex.what () << std::endl;
1036+ }
1037+ return l_rc;
1038+ };
1039+
1040+ do
9951041 {
9961042 int l_slNum = 0 ;
9971043 bool l_exit = false ;
@@ -1066,17 +1112,44 @@ int VpdTool::handleMoreOption(
10661112 if (types::UserOption::UseBackupDataForCurrent ==
10671113 l_userSelectedOption)
10681114 {
1069- // ToDo: Implementation needs to be added
1115+ l_rc = updateKeywordValue (
1116+ l_srcVpdPath, l_aRecordKwInfo[" sourceRecord" ],
1117+ l_aRecordKwInfo[" sourceKeyword" ],
1118+ l_aRecordKwInfo[" destinationkeywordValue" ]);
10701119 }
10711120 else if (types::UserOption::UseSystemBackplaneDataForCurrent ==
10721121 l_userSelectedOption)
10731122 {
1074- // ToDo: Implementation needs to be added
1123+ l_rc = updateKeywordValue (
1124+ l_srcVpdPath, l_aRecordKwInfo[" sourceRecord" ],
1125+ l_aRecordKwInfo[" sourceKeyword" ],
1126+ l_aRecordKwInfo[" sourcekeywordValue" ]);
10751127 }
10761128 else if (types::UserOption::NewValueOnBoth ==
10771129 l_userSelectedOption)
10781130 {
1079- // ToDo: Implementation needs to be added
1131+ std::string l_newValue;
1132+ std::cout
1133+ << std::endl
1134+ << " Enter the new value to update on both "
1135+ " primary & backup. Value should be in ASCII or "
1136+ " in HEX(prefixed with 0x) : " ;
1137+ std::cin >> l_newValue;
1138+ std::cout << std::endl
1139+ << std::string (191 , ' =' ) << std::endl;
1140+
1141+ try
1142+ {
1143+ l_rc = updateKeywordValue (
1144+ l_srcVpdPath, l_aRecordKwInfo[" sourceRecord" ],
1145+ l_aRecordKwInfo[" sourceKeyword" ],
1146+ utils::convertToBinary (l_newValue));
1147+ }
1148+ catch (const std::exception& l_ex)
1149+ {
1150+ // TODO: Enable logging when verbose is enabled.
1151+ std::cerr << l_ex.what () << std::endl;
1152+ }
10801153 }
10811154 else if (types::UserOption::SkipCurrent == l_userSelectedOption)
10821155 {
@@ -1103,7 +1176,7 @@ int VpdTool::handleMoreOption(
11031176 l_rc = constants::SUCCESS;
11041177 break ;
11051178 }
1106- }
1179+ } while ( true );
11071180 }
11081181 catch (const std::exception& l_ex)
11091182 {
0 commit comments