Move initial set up to OEM class

Currently the call to perform initial set up executes functionalities
which are specific to OEM.
Hence moving the call to the OEM class.

Change-Id: Ied0c3eb6f6604b5a15db1b0426e78222a80613b8
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/worker.hpp b/vpd-manager/include/worker.hpp
index 305045e..b560162 100644
--- a/vpd-manager/include/worker.hpp
+++ b/vpd-manager/include/worker.hpp
@@ -55,17 +55,6 @@
      */
     ~Worker() = default;
 
-#ifdef IBM_SYSTEM
-    /**
-     * @brief API to perform initial setup before manager claims Bus name.
-     *
-     * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
-     * corret device tree, inventory JSON w.r.t system should be linked and
-     * system VPD should be on DBus.
-     */
-    void performInitialSetup();
-#endif
-
     /**
      * @brief An API to check if system VPD is already published.
      *
@@ -181,6 +170,25 @@
      */
     void performVpdRecollection();
 
+    /**
+     * @brief API to prime inventory Objects.
+     *
+     * @param[in] i_vpdFilePath - EEPROM file path.
+     * @return true if the prime inventory is success, false otherwise.
+     */
+    bool primeInventory(const std::string& i_vpdFilePath);
+
+    /**
+     * @brief An API to set appropriate device tree and JSON.
+     *
+     * This API based on system chooses corresponding device tree and JSON.
+     * If device tree change is required, it updates the "fitconfig" and reboots
+     * the system. Else it is NOOP.
+     *
+     * @throw std::exception
+     */
+    void setDeviceTreeAndJson();
+
   private:
     /**
      * @brief An API to parse and publish a FRU VPD over D-Bus.
@@ -196,17 +204,6 @@
         const std::string& i_vpdFilePath);
 
     /**
-     * @brief An API to set appropriate device tree and JSON.
-     *
-     * This API based on system chooses corresponding device tree and JSON.
-     * If device tree change is required, it updates the "fitconfig" and reboots
-     * the system. Else it is NOOP.
-     *
-     * @throw std::exception
-     */
-    void setDeviceTreeAndJson();
-
-    /**
      * @brief API to select system specific JSON.
      *
      * The API based on the IM value of VPD, will select appropriate JSON for
@@ -362,14 +359,6 @@
     bool isCPUIOGoodOnly(const std::string& pgKeyword);
 
     /**
-     * @brief API to prime inventory Objects.
-     *
-     * @param[in] i_vpdFilePath - EEPROM file path.
-     * @return true if the prime inventory is success, false otherwise.
-     */
-    bool primeInventory(const std::string& i_vpdFilePath);
-
-    /**
      * @brief API to process preAction(base_action) defined in config JSON.
      *
      * @note sequence of tags under any given flag of preAction is EXTREMELY
@@ -441,16 +430,6 @@
         const std::optional<types::VPDMapVariant> i_parsedVpd = std::nullopt);
 
     /**
-     * @brief Function to enable and bring MUX out of idle state.
-     *
-     * This finds all the MUX defined in the system json and enables them by
-     * setting the holdidle parameter to 0.
-     *
-     * @throw std::runtime_error
-     */
-    void enableMuxChips();
-
-    /**
      * @brief An API to perform backup or restore of VPD.
      *
      * @param[in,out] io_srcVpdMap - Source VPD map.
@@ -500,14 +479,6 @@
         const types::VPDMapVariant& i_parsedVpdMap);
 
     /**
-     * @brief API to prime system blueprint.
-     *
-     * The API will traverse the system config JSON and will prime all the FRU
-     * paths which qualifies for priming.
-     */
-    void primeSystemBlueprint();
-
-    /**
      * @brief API to set symbolic link for system config JSON.
      *
      * Once correct device tree is set, symbolic link to the correct sytsem
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index 1c39acc..ea8bb97 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -4,6 +4,7 @@
 
 #include "parser.hpp"
 
+#include <utility/common_utility.hpp>
 #include <utility/dbus_utility.hpp>
 #include <utility/json_utility.hpp>
 #include <utility/vpd_specific_utility.hpp>
@@ -34,10 +35,7 @@
     }
 
     // Set up minimal things that is needed before bus name is claimed.
-    m_worker->performInitialSetup();
-
-    // Get the system config JSON object
-    m_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
+    performInitialSetup();
 
     if (!m_sysCfgJsonObj.empty() &&
         jsonUtility::isBackupAndRestoreRequired(m_sysCfgJsonObj))
@@ -503,4 +501,116 @@
         logging::logMessage(l_ex.what());
     }
 }
+
+void IbmHandler::primeSystemBlueprint()
+{
+    if (m_sysCfgJsonObj.empty())
+    {
+        return;
+    }
+
+    const nlohmann::json& l_listOfFrus =
+        m_sysCfgJsonObj["frus"].get_ref<const nlohmann::json::object_t&>();
+
+    for (const auto& l_itemFRUS : l_listOfFrus.items())
+    {
+        const std::string& l_vpdFilePath = l_itemFRUS.key();
+
+        if (l_vpdFilePath == SYSTEM_VPD_FILE_PATH)
+        {
+            continue;
+        }
+
+        // Prime the inventry for FRUs which
+        // are not present/processing had some error.
+        if (m_worker.get() != nullptr &&
+            !m_worker->primeInventory(l_vpdFilePath))
+        {
+            logging::logMessage(
+                "Priming of inventory failed for FRU " + l_vpdFilePath);
+        }
+    }
+}
+
+void IbmHandler::enableMuxChips()
+{
+    if (m_sysCfgJsonObj.empty())
+    {
+        // config JSON should not be empty at this point of execution.
+        throw std::runtime_error("Config JSON is empty. Can't enable muxes");
+        return;
+    }
+
+    if (!m_sysCfgJsonObj.contains("muxes"))
+    {
+        logging::logMessage("No mux defined for the system in config JSON");
+        return;
+    }
+
+    // iterate over each MUX detail and enable them.
+    for (const auto& item : m_sysCfgJsonObj["muxes"])
+    {
+        if (item.contains("holdidlepath"))
+        {
+            std::string cmd = "echo 0 > ";
+            cmd += item["holdidlepath"];
+
+            logging::logMessage("Enabling mux with command = " + cmd);
+
+            commonUtility::executeCmd(cmd);
+            continue;
+        }
+
+        logging::logMessage(
+            "Mux Entry does not have hold idle path. Can't enable the mux");
+    }
+}
+
+void IbmHandler::performInitialSetup()
+{
+    try
+    {
+        if (!dbusUtility::isChassisPowerOn())
+        {
+            logging::logMessage("Chassis is in Off state.");
+            if (m_worker.get() != nullptr)
+            {
+                m_worker->setDeviceTreeAndJson();
+                // Get the system config JSON object.
+                m_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
+            }
+            else
+            {
+                throw std::runtime_error(
+                    "Worker object not found. Can't set up device tree and Json.");
+            }
+            primeSystemBlueprint();
+        }
+        else
+        {
+            // get the JSON from worker.
+            m_sysCfgJsonObj = m_worker->getSysCfgJsonObj();
+        }
+
+        // Enable all mux which are used for connecting to the i2c on the
+        // pcie slots for pcie cards. These are not enabled by kernel due to
+        // an issue seen with Castello cards, where the i2c line hangs on a
+        // probe.
+        enableMuxChips();
+
+        // Nothing needs to be done. Service restarted or BMC re-booted for
+        // some reason at system power on.
+        return;
+    }
+    catch (const std::exception& l_ex)
+    {
+        // Any issue in system's inital set up is handled in this catch. Error
+        // will not propogate to manager.
+        EventLogger::createSyncPel(
+            EventLogger::getErrorType(l_ex), types::SeverityType::Critical,
+            __FILE__, __FUNCTION__, 0, EventLogger::getErrorMsg(l_ex),
+            std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+    }
+}
+
 } // namespace vpd
diff --git a/vpd-manager/oem-handler/ibm_handler.hpp b/vpd-manager/oem-handler/ibm_handler.hpp
index 5bf6d65..3a6ea42 100644
--- a/vpd-manager/oem-handler/ibm_handler.hpp
+++ b/vpd-manager/oem-handler/ibm_handler.hpp
@@ -118,6 +118,33 @@
      */
     void ConfigurePowerVsSystem();
 
+    /**
+     * @brief API to perform initial setup before manager claims Bus name.
+     *
+     * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
+     * corret device tree, inventory JSON w.r.t system should be linked and
+     * system VPD should be on DBus.
+     */
+    void performInitialSetup();
+
+    /**
+     * @brief API to prime system blueprint.
+     *
+     * The API will traverse the system config JSON and will prime all the FRU
+     * paths which qualifies for priming.
+     */
+    void primeSystemBlueprint();
+
+    /**
+     * @brief Function to enable and bring MUX out of idle state.
+     *
+     * This finds all the MUX defined in the system json and enables them by
+     * setting the holdidle parameter to 0.
+     *
+     * @throw std::runtime_error
+     */
+    void enableMuxChips();
+
     // Parsed system config json object.
     nlohmann::json m_sysCfgJsonObj{};
 
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index ec21810..87112ce 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -61,103 +61,6 @@
     }
 }
 
-void Worker::enableMuxChips()
-{
-    if (m_parsedJson.empty())
-    {
-        // config JSON should not be empty at this point of execution.
-        throw std::runtime_error("Config JSON is empty. Can't enable muxes");
-        return;
-    }
-
-    if (!m_parsedJson.contains("muxes"))
-    {
-        logging::logMessage("No mux defined for the system in config JSON");
-        return;
-    }
-
-    // iterate over each MUX detail and enable them.
-    for (const auto& item : m_parsedJson["muxes"])
-    {
-        if (item.contains("holdidlepath"))
-        {
-            std::string cmd = "echo 0 > ";
-            cmd += item["holdidlepath"];
-
-            logging::logMessage("Enabling mux with command = " + cmd);
-
-            commonUtility::executeCmd(cmd);
-            continue;
-        }
-
-        logging::logMessage(
-            "Mux Entry does not have hold idle path. Can't enable the mux");
-    }
-}
-
-#ifdef IBM_SYSTEM
-void Worker::primeSystemBlueprint()
-{
-    if (m_parsedJson.empty())
-    {
-        return;
-    }
-
-    const nlohmann::json& l_listOfFrus =
-        m_parsedJson["frus"].get_ref<const nlohmann::json::object_t&>();
-
-    for (const auto& l_itemFRUS : l_listOfFrus.items())
-    {
-        const std::string& l_vpdFilePath = l_itemFRUS.key();
-
-        if (l_vpdFilePath == SYSTEM_VPD_FILE_PATH)
-        {
-            continue;
-        }
-
-        // Prime the inventry for FRUs which
-        // are not present/processing had some error.
-        if (!primeInventory(l_vpdFilePath))
-        {
-            logging::logMessage(
-                "Priming of inventory failed for FRU " + l_vpdFilePath);
-        }
-    }
-}
-
-void Worker::performInitialSetup()
-{
-    try
-    {
-        if (!dbusUtility::isChassisPowerOn())
-        {
-            logging::logMessage("Chassis is in Off state.");
-            setDeviceTreeAndJson();
-            primeSystemBlueprint();
-        }
-
-        // Enable all mux which are used for connecting to the i2c on the
-        // pcie slots for pcie cards. These are not enabled by kernel due to
-        // an issue seen with Castello cards, where the i2c line hangs on a
-        // probe.
-        enableMuxChips();
-
-        // Nothing needs to be done. Service restarted or BMC re-booted for
-        // some reason at system power on.
-        return;
-    }
-    catch (const std::exception& l_ex)
-    {
-        // Any issue in system's inital set up is handled in this catch. Error
-        // will not propogate to manager.
-        EventLogger::createSyncPel(
-            EventLogger::getErrorType(l_ex), types::SeverityType::Critical,
-            __FILE__, __FUNCTION__, 0, EventLogger::getErrorMsg(l_ex),
-            std::nullopt, std::nullopt, std::nullopt, std::nullopt);
-    }
-}
-#endif
-
 static std::string readFitConfigValue()
 {
     std::vector<std::string> output =