manager: Move System VPD Restore to Manager

This commit moves the system VPD restore functionality to the VPD
manager.

This ensures there are no race conditions with doing it in the parser
process when the manager is synchronizing BIOS attributes to VPD.

Tested: I tested both the VPD restore as well as the BIOS attribute sync
paths. They tested out fine.

Signed-off-by: Santosh Puranik <santosh.puranik@in.ibm.com>
Change-Id: I4e3c274a72f86ad4b4821529ffbe0526203b7df5
diff --git a/ibm_vpd_utils.cpp b/ibm_vpd_utils.cpp
index 554092e..11d0faf 100644
--- a/ibm_vpd_utils.cpp
+++ b/ibm_vpd_utils.cpp
@@ -934,5 +934,54 @@
     cout << "Power state is: " << powerState << endl;
     return powerState;
 }
+
+Binary getVpdDataInVector(const nlohmann::json& js, const std::string& file)
+{
+    uint32_t offset = 0;
+    // check if offset present?
+    for (const auto& item : js["frus"][file])
+    {
+        if (item.find("offset") != item.end())
+        {
+            offset = item["offset"];
+        }
+    }
+
+    // TODO: Figure out a better way to get max possible VPD size.
+    auto maxVPDSize = std::min(std::filesystem::file_size(file),
+                               static_cast<uintmax_t>(65504));
+
+    Binary vpdVector;
+    vpdVector.resize(maxVPDSize);
+    ifstream vpdFile;
+    vpdFile.open(file, ios::binary);
+
+    vpdFile.seekg(offset, ios_base::cur);
+    vpdFile.read(reinterpret_cast<char*>(&vpdVector[0]), maxVPDSize);
+    vpdVector.resize(vpdFile.gcount());
+
+    // Make sure we reset the EEPROM pointer to a "safe" location if it was DIMM
+    // SPD that we just read.
+    for (const auto& item : js["frus"][file])
+    {
+        if (item.find("extraInterfaces") != item.end())
+        {
+            if (item["extraInterfaces"].find(
+                    "xyz.openbmc_project.Inventory.Item.Dimm") !=
+                item["extraInterfaces"].end())
+            {
+                // moves the EEPROM pointer to 2048 'th byte.
+                vpdFile.seekg(2047, std::ios::beg);
+                // Read that byte and discard - to affirm the move
+                // operation.
+                char ch;
+                vpdFile.read(&ch, sizeof(ch));
+                break;
+            }
+        }
+    }
+
+    return vpdVector;
+}
 } // namespace vpd
 } // namespace openpower