Fix CI unused variable error
"checkAndListenPldmService" API which was being called as a part of bios
handler construction has been moved out and called explicitly to avoid
unused variable error for bios handler object in manager main cpp file.
Change-Id: Ibbc77b6f340ae793b6daf4a4f53ecc6c5326f882
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/bios_handler.hpp b/vpd-manager/include/bios_handler.hpp
index 2408b2f..45ebba6 100644
--- a/vpd-manager/include/bios_handler.hpp
+++ b/vpd-manager/include/bios_handler.hpp
@@ -235,33 +235,15 @@
*
* @param[in] i_connection - Asio connection object.
* @param[in] i_manager - Manager object.
+ * @throw std::exception
*/
BiosHandler(
const std::shared_ptr<sdbusplus::asio::connection>& i_connection,
const std::shared_ptr<Manager>& i_manager) : m_asioConn(i_connection)
{
- try
- {
- m_specificBiosHandler = std::make_shared<T>(i_manager);
- checkAndListenPldmService();
- }
- catch (std::exception& l_ex)
- {
- // catch any exception here itself and don't pass it to main as it
- // will mark the service failed. Since VPD-Manager is a critical
- // service, failing it can push BMC to quiesced state whic is not
- // required in this case.
- std::string l_errMsg = "Instantiation of BIOS Handler failed. { ";
- l_errMsg += l_ex.what() + std::string(" }");
-
- EventLogger::createSyncPel(
- types::ErrorType::FirmwareError, types::SeverityType::Warning,
- __FILE__, __FUNCTION__, 0, l_errMsg, std::nullopt, std::nullopt,
- std::nullopt, std::nullopt);
- }
+ m_specificBiosHandler = std::make_shared<T>(i_manager);
}
- private:
/**
* @brief API to check if PLDM service is running and run BIOS sync.
*
@@ -270,8 +252,9 @@
* registers a listener to be notified when the service starts so that a
* restore can be performed.
*/
- void checkAndListenPldmService();
+ void checkAndListenPldmService() noexcept;
+ private:
/**
* @brief Register listener for BIOS attribute property change.
*
diff --git a/vpd-manager/src/bios_handler.cpp b/vpd-manager/src/bios_handler.cpp
index 73dd229..3334f0a 100644
--- a/vpd-manager/src/bios_handler.cpp
+++ b/vpd-manager/src/bios_handler.cpp
@@ -17,51 +17,61 @@
template class BiosHandler<IbmBiosHandler>;
template <typename T>
-void BiosHandler<T>::checkAndListenPldmService()
+void BiosHandler<T>::checkAndListenPldmService() noexcept
{
- // Setup a call back match on NameOwnerChanged to determine when PLDM is up.
- static std::shared_ptr<sdbusplus::bus::match_t> l_nameOwnerMatch =
- std::make_shared<sdbusplus::bus::match_t>(
- *m_asioConn,
- sdbusplus::bus::match::rules::nameOwnerChanged(
- constants::pldmServiceName),
- [this](sdbusplus::message_t& l_msg) {
- if (l_msg.is_method_error())
- {
- logging::logMessage(
- "Error in reading PLDM name owner changed signal.");
- return;
- }
-
- std::string l_name;
- std::string l_newOwner;
- std::string l_oldOwner;
-
- l_msg.read(l_name, l_oldOwner, l_newOwner);
-
- if (!l_newOwner.empty() &&
- (l_name.compare(constants::pldmServiceName) ==
- constants::STR_CMP_SUCCESS))
- {
- m_specificBiosHandler->backUpOrRestoreBiosAttributes();
-
- // Start listener now that we have done the restore.
- listenBiosAttributes();
-
- // We don't need the match anymore
- l_nameOwnerMatch.reset();
- }
- });
-
- // Based on PLDM service status reset owner match registered above and
- // trigger BIOS attribute sync.
- if (dbusUtility::isServiceRunning(constants::pldmServiceName))
+ try
{
- l_nameOwnerMatch.reset();
- m_specificBiosHandler->backUpOrRestoreBiosAttributes();
+ // Setup a call back match on NameOwnerChanged to determine when PLDM is
+ // up.
+ static std::shared_ptr<sdbusplus::bus::match_t> l_nameOwnerMatch =
+ std::make_shared<sdbusplus::bus::match_t>(
+ *m_asioConn,
+ sdbusplus::bus::match::rules::nameOwnerChanged(
+ constants::pldmServiceName),
+ [this](sdbusplus::message_t& l_msg) {
+ if (l_msg.is_method_error())
+ {
+ logging::logMessage(
+ "Error in reading PLDM name owner changed signal.");
+ return;
+ }
- // Start listener now that we have done the restore.
- listenBiosAttributes();
+ std::string l_name;
+ std::string l_newOwner;
+ std::string l_oldOwner;
+
+ l_msg.read(l_name, l_oldOwner, l_newOwner);
+
+ if (!l_newOwner.empty() &&
+ (l_name.compare(constants::pldmServiceName) ==
+ constants::STR_CMP_SUCCESS))
+ {
+ m_specificBiosHandler->backUpOrRestoreBiosAttributes();
+
+ // Start listener now that we have done the restore.
+ listenBiosAttributes();
+
+ // We don't need the match anymore
+ l_nameOwnerMatch.reset();
+ }
+ });
+
+ // Based on PLDM service status reset owner match registered above and
+ // trigger BIOS attribute sync.
+ if (dbusUtility::isServiceRunning(constants::pldmServiceName))
+ {
+ l_nameOwnerMatch.reset();
+ m_specificBiosHandler->backUpOrRestoreBiosAttributes();
+
+ // Start listener now that we have done the restore.
+ listenBiosAttributes();
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ logging::logMessage(
+ "Failed to register callback for PLDM servce. Error: " +
+ std::string(l_ex.what()));
}
}
diff --git a/vpd-manager/src/manager_main.cpp b/vpd-manager/src/manager_main.cpp
index ab1d374..0f8424f 100644
--- a/vpd-manager/src/manager_main.cpp
+++ b/vpd-manager/src/manager_main.cpp
@@ -35,10 +35,28 @@
auto vpdManager = std::make_shared<vpd::Manager>(
io_con, interface, progressInf, connection);
- // TODO: Take this under conditional compilation for IBM
- auto biosHandler =
- std::make_shared<vpd::BiosHandler<vpd::IbmBiosHandler>>(
- connection, vpdManager);
+ try
+ {
+ // TODO: Take this under conditional compilation for IBM
+ auto biosHandler =
+ std::make_shared<vpd::BiosHandler<vpd::IbmBiosHandler>>(
+ connection, vpdManager);
+ biosHandler->checkAndListenPldmService();
+ }
+ catch (const std::exception& l_ex)
+ {
+ // Cathcing exception here explicitly to let VPD-Manager service
+ // continue even when bios handler fails.
+ const std::string& l_errMsg =
+ "Instantiation of BIOS Handler failed. { " +
+ std::string(l_ex.what()) + std::string(" }");
+
+ vpd::EventLogger::createSyncPel(
+ vpd::types::ErrorType::FirmwareError,
+ vpd::types::SeverityType::Warning, __FILE__, __FUNCTION__, 0,
+ l_errMsg, std::nullopt, std::nullopt, std::nullopt,
+ std::nullopt);
+ }
interface->initialize();
progressInf->initialize();