Code refactoring
Moved implementation to set collection mode into a separate API.
The change is being done to move independent code from constructor to a
separate API, making the code more readable and easy to maintain.
Change-Id: I886d9a7bed45142173e1f042ab5683cf3fd1bb77
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index 607ba34..dcb0ddd 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -26,39 +26,27 @@
m_ioContext(i_ioCon), m_asioConnection(i_asioConnection),
m_logger(Logger::getLoggerInstance())
{
- uint16_t l_errCode{0};
-
- // check VPD collection mode
- const auto l_vpdCollectionMode =
- commonUtility::isFieldModeEnabled()
- ? types::VpdCollectionMode::DEFAULT_MODE
- : commonUtility::getVpdCollectionMode(l_errCode);
-
- if (l_errCode)
- {
- m_logger->logMessage(
- "Error while trying to read VPD collection mode: " +
- commonUtility::getErrCodeMsg(l_errCode));
- }
+ readVpdCollectionMode();
if (dbusUtility::isChassisPowerOn())
{
// At power on, less number of FRU(s) needs collection. we can scale
// down the threads to reduce CPU utilization.
m_worker = std::make_shared<Worker>(
- INVENTORY_JSON_DEFAULT, constants::VALUE_1, l_vpdCollectionMode);
+ INVENTORY_JSON_DEFAULT, constants::VALUE_1, m_vpdCollectionMode);
}
else
{
// Initialize with default configuration
m_worker = std::make_shared<Worker>(INVENTORY_JSON_DEFAULT,
constants::MAX_THREADS,
- l_vpdCollectionMode);
+ m_vpdCollectionMode);
}
// Set up minimal things that is needed before bus name is claimed.
performInitialSetup();
+ uint16_t l_errCode{0};
// If the object is created, implies back up and restore took place in
// system VPD flow.
if ((m_backupAndRestoreObj == nullptr) && !m_sysCfgJsonObj.empty() &&
@@ -98,6 +86,22 @@
std::make_shared<GpioMonitor>(m_sysCfgJsonObj, m_worker, m_ioContext);
}
+void IbmHandler::readVpdCollectionMode() noexcept
+{
+ uint16_t l_errCode{0};
+ // check VPD collection mode
+ m_vpdCollectionMode = commonUtility::isFieldModeEnabled()
+ ? types::VpdCollectionMode::DEFAULT_MODE
+ : commonUtility::getVpdCollectionMode(l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage(
+ "Default mode set. Error while trying to read VPD collection mode: " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
+}
+
void IbmHandler::SetTimerToDetectVpdCollectionStatus()
{
// Keeping max retry for 2 minutes. TODO: Make it configurable based on
diff --git a/vpd-manager/oem-handler/ibm_handler.hpp b/vpd-manager/oem-handler/ibm_handler.hpp
index d10323b..e9bb187 100644
--- a/vpd-manager/oem-handler/ibm_handler.hpp
+++ b/vpd-manager/oem-handler/ibm_handler.hpp
@@ -203,6 +203,14 @@
*/
void checkAndUpdateBmcPosition(size_t& o_bmcPosition) const noexcept;
+ /**
+ * @brief API to read VPD collection mode.
+ *
+ * Collection mode denotes if the VPD needs to be read from file or actual
+ * hardware.
+ */
+ void readVpdCollectionMode() noexcept;
+
// Parsed system config json object.
nlohmann::json m_sysCfgJsonObj{};
@@ -232,5 +240,9 @@
// Shared pointer to Logger object.
std::shared_ptr<Logger> m_logger;
+
+ // vpd collection mode
+ types::VpdCollectionMode m_vpdCollectionMode =
+ types::VpdCollectionMode::DEFAULT_MODE;
};
} // namespace vpd