Skip PCIe cards collection at power on

Collection of PCIe card is skipped in case of BMC reboot at chassis
power on.

Since PCIe cards are CMable and not hot pluggable, any removal or
addition of card will be handled in the CM flow. No need to explicit
collection when BMC is coming up while chassis is on.

Change-Id: Ib43c817e07593ea72a21b433b88cfc970344cded
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/worker.hpp b/vpd-manager/include/worker.hpp
index a0da85d..ba88d33 100644
--- a/vpd-manager/include/worker.hpp
+++ b/vpd-manager/include/worker.hpp
@@ -507,6 +507,16 @@
      */
     void setPresentProperty(const std::string& i_fruPath, const bool& i_value);
 
+    /**
+     * @brief API to check if the path needs to be skipped for collection.
+     *
+     * Some FRUs, under some given scenarios should not be collected and
+     * skipped.
+     *
+     * @return True - if path is empty or should be skipped, false otherwise.
+     */
+    bool skipPathForCollection(const std::string& i_vpdFilePath);
+
     // Parsed JSON file.
     nlohmann::json m_parsedJson{};
 
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 82ec973..a0b8a24 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1481,6 +1481,43 @@
     return std::make_tuple(true, i_vpdFilePath);
 }
 
+bool Worker::skipPathForCollection(const std::string& i_vpdFilePath)
+{
+    if (i_vpdFilePath.empty())
+    {
+        return true;
+    }
+
+    // skip processing of system VPD again as it has been already collected.
+    if (i_vpdFilePath == SYSTEM_VPD_FILE_PATH)
+    {
+        return true;
+    }
+
+    if (dbusUtility::isChassisPowerOn())
+    {
+        // If chassis is powered on, skip collecting FRUs which are
+        // powerOffOnly.
+        if (jsonUtility::isFruPowerOffOnly(m_parsedJson, i_vpdFilePath))
+        {
+            return true;
+        }
+
+        const std::string& l_invPathLeafValue =
+            sdbusplus::message::object_path(
+                jsonUtility::getInventoryObjPathFromJson(m_parsedJson,
+                                                         i_vpdFilePath))
+                .filename();
+
+        if ((l_invPathLeafValue.find("pcie_card", 0) != std::string::npos))
+        {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 void Worker::collectFrusFromJson()
 {
     // A parsed JSON file should be present to pick FRUs EEPROM paths
@@ -1497,22 +1534,13 @@
     {
         const std::string& vpdFilePath = itemFRUS.key();
 
-        // skip processing of system VPD again as it has been already collected.
-        // Also, if chassis is powered on, skip collecting FRUs which are
-        // powerOffOnly.
-        // TODO: Need to revisit for P-Future to reduce code update time.
-        if (vpdFilePath == SYSTEM_VPD_FILE_PATH ||
-            (jsonUtility::isFruPowerOffOnly(m_parsedJson, vpdFilePath) &&
-             dbusUtility::isChassisPowerOn()))
+        if (skipPathForCollection(vpdFilePath))
         {
             continue;
         }
 
         std::thread{[vpdFilePath, this]() {
-            auto l_futureObject =
-                std::async(&Worker::parseAndPublishVPD, this, vpdFilePath);
-
-            std::tuple<bool, std::string> l_threadInfo = l_futureObject.get();
+            const auto& l_parseResult = parseAndPublishVPD(vpdFilePath);
 
             // thread returned.
             m_mutex.lock();