Refactor : Add a helper function to addFruObjectToDbus
Refactoring addFruObjectToDbus function and created a new helper
function getProductName. Moved this function to fru_utils.cpp as
it is common for all fru-device deamons and avoid code duplication.
This patch is created based on suggestion on the below patch.
https://gerrit.openbmc.org/c/openbmc/entity-manager/+/51555
TESTED : Built Facebook YosemiteV2 images and loaded
on the target hardware. Verified all the fru's read and write.
Signed-off-by: Kumar Thangavel <thangavel.k@hcl.com>
Change-Id: I272d2fd2fc664a471774c668503d87147eb80a54
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index c4272cb..26ac516 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -657,40 +657,16 @@
std::shared_ptr<sdbusplus::asio::connection>& systemBus)
{
boost::container::flat_map<std::string, std::string> formattedFRU;
- resCodes res = formatIPMIFRU(device, formattedFRU);
- if (res == resCodes::resErr)
+
+ std::optional<std::string> optionalProductName = getProductName(
+ device, formattedFRU, bus, address, unknownBusObjectCount);
+ if (!optionalProductName)
{
- std::cerr << "failed to parse FRU for device at bus " << bus
- << " address " << address << "\n";
+ std::cerr << "getProductName failed. product name is empty.\n";
return;
}
- if (res == resCodes::resWarn)
- {
- std::cerr << "there were warnings while parsing FRU for device at bus "
- << bus << " address " << address << "\n";
- }
- auto productNameFind = formattedFRU.find("BOARD_PRODUCT_NAME");
- std::string productName;
- // Not found under Board section or an empty string.
- if (productNameFind == formattedFRU.end() ||
- productNameFind->second.empty())
- {
- productNameFind = formattedFRU.find("PRODUCT_PRODUCT_NAME");
- }
- // Found under Product section and not an empty string.
- if (productNameFind != formattedFRU.end() &&
- !productNameFind->second.empty())
- {
- productName = productNameFind->second;
- std::regex illegalObject("[^A-Za-z0-9_]");
- productName = std::regex_replace(productName, illegalObject, "_");
- }
- else
- {
- productName = "UNKNOWN" + std::to_string(unknownBusObjectCount);
- unknownBusObjectCount++;
- }
+ std::string productName = optionalProductName.value();
std::optional<int> index = findIndexForFRU(dbusInterfaceMap, productName);
if (index.has_value())