From 44a957d80ba0bed05829e655b9f8008b8f58e522 Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Sat, 20 Oct 2018 09:41:29 -0700 Subject: style: rename update_inventory, move into anonymous Move ipmi_update_inventory into an anonymous namespace and rename per the openbmc style naming conventions. Change-Id: I931bd9a50ca695d667eb5703089f1ca020ca6995 Signed-off-by: Patrick Venture --- writefrudata.cpp | 269 +++++++++++++++++++++++++++---------------------------- 1 file changed, 134 insertions(+), 135 deletions(-) diff --git a/writefrudata.cpp b/writefrudata.cpp index 130f30f..5304929 100644 --- a/writefrudata.cpp +++ b/writefrudata.cpp @@ -138,6 +138,139 @@ auto getService(sdbusplus::bus::bus& bus, const std::string& intf, return mapperResponse.begin()->first; } +// Takes FRU data, invokes Parser for each fru record area and updates +// Inventory +//------------------------------------------------------------------------ +int updateInventory(fru_area_vec_t& area_vec, sd_bus* bus_sd) +{ + // Generic error reporter + int rc = 0; + uint8_t fruid = 0; + IPMIFruInfo fruData; + + // For each FRU area, extract the needed data , get it parsed and update + // the Inventory. + for (const auto& fruArea : area_vec) + { + fruid = fruArea->get_fruid(); + // Fill the container with information + rc = parse_fru_area((fruArea)->get_type(), (void*)(fruArea)->get_data(), + (fruArea)->get_len(), fruData); + if (rc < 0) + { + log("Error parsing FRU records"); + return rc; + } + } // END walking the vector of areas and updating + + // For each Fru we have the list of instances which needs to be updated. + // Each instance object implements certain interfaces. + // Each Interface is having Dbus properties. + // Each Dbus Property would be having metaData(eg section,VpdPropertyName). + + // Here we are just printing the object,interface and the properties. + // which needs to be called with the new inventory manager implementation. + sdbusplus::bus::bus bus{bus_sd}; + using namespace std::string_literals; + static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; + static const auto path = "/xyz/openbmc_project/inventory"s; + std::string service; + try + { + service = getService(bus, intf, path); + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return -1; + } + + auto iter = frus.find(fruid); + if (iter == frus.end()) + { + log("Unable to get the fru info", + entry("FRU=%d", static_cast(fruid))); + return -1; + } + + auto& instanceList = iter->second; + if (instanceList.size() <= 0) + { + log("Object list empty for this FRU", + entry("FRU=%d", static_cast(fruid))); + } + + ObjectMap objects; + for (auto& instance : instanceList) + { + InterfaceMap interfaces; + const auto& extrasIter = extras.find(instance.path); + + for (auto& interfaceList : instance.interfaces) + { + PropertyMap props; // store all the properties + for (auto& properties : interfaceList.second) + { + std::string value; + decltype(auto) pdata = properties.second; + + if (!pdata.section.empty() && !pdata.property.empty()) + { + value = getFRUValue(pdata.section, pdata.property, + pdata.delimiter, fruData); + } + props.emplace(std::move(properties.first), std::move(value)); + } + // Check and update extra properties + if (extras.end() != extrasIter) + { + const auto& propsIter = + (extrasIter->second).find(interfaceList.first); + if ((extrasIter->second).end() != propsIter) + { + for (const auto& map : propsIter->second) + { + props.emplace(map.first, map.second); + } + } + } + interfaces.emplace(std::move(interfaceList.first), + std::move(props)); + } + + // Call the inventory manager + sdbusplus::message::object_path path = instance.path; + // Check and update extra properties + if (extras.end() != extrasIter) + { + for (const auto& entry : extrasIter->second) + { + if (interfaces.end() == interfaces.find(entry.first)) + { + interfaces.emplace(entry.first, entry.second); + } + } + } + objects.emplace(path, interfaces); + } + + auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), + intf.c_str(), "Notify"); + pimMsg.append(std::move(objects)); + + try + { + auto inventoryMgrResponseMsg = bus.call(pimMsg); + } + catch (const sdbusplus::exception::SdBusError& ex) + { + log("Error in notify call", entry("WHAT=%s", ex.what())); + return -1; + } + + return rc; +} + } // namespace //---------------------------------------------------------------- @@ -315,140 +448,6 @@ int verify_fru_data(const uint8_t* data, const size_t len) return EXIT_SUCCESS; } -//------------------------------------------------------------------------ -// Takes FRU data, invokes Parser for each fru record area and updates -// Inventory -//------------------------------------------------------------------------ -int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd) -{ - // Generic error reporter - int rc = 0; - uint8_t fruid = 0; - IPMIFruInfo fruData; - - // For each FRU area, extract the needed data , get it parsed and update - // the Inventory. - for (const auto& fruArea : area_vec) - { - fruid = fruArea->get_fruid(); - // Fill the container with information - rc = parse_fru_area((fruArea)->get_type(), (void*)(fruArea)->get_data(), - (fruArea)->get_len(), fruData); - if (rc < 0) - { - log("Error parsing FRU records"); - return rc; - } - } // END walking the vector of areas and updating - - // For each Fru we have the list of instances which needs to be updated. - // Each instance object implements certain interfaces. - // Each Interface is having Dbus properties. - // Each Dbus Property would be having metaData(eg section,VpdPropertyName). - - // Here we are just printing the object,interface and the properties. - // which needs to be called with the new inventory manager implementation. - sdbusplus::bus::bus bus{bus_sd}; - using namespace std::string_literals; - static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; - static const auto path = "/xyz/openbmc_project/inventory"s; - std::string service; - try - { - service = getService(bus, intf, path); - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return -1; - } - - auto iter = frus.find(fruid); - if (iter == frus.end()) - { - log("Unable to get the fru info", - entry("FRU=%d", static_cast(fruid))); - return -1; - } - - auto& instanceList = iter->second; - if (instanceList.size() <= 0) - { - log("Object list empty for this FRU", - entry("FRU=%d", static_cast(fruid))); - } - - ObjectMap objects; - for (auto& instance : instanceList) - { - InterfaceMap interfaces; - const auto& extrasIter = extras.find(instance.path); - - for (auto& interfaceList : instance.interfaces) - { - PropertyMap props; // store all the properties - for (auto& properties : interfaceList.second) - { - std::string value; - decltype(auto) pdata = properties.second; - - if (!pdata.section.empty() && !pdata.property.empty()) - { - value = getFRUValue(pdata.section, pdata.property, - pdata.delimiter, fruData); - } - props.emplace(std::move(properties.first), std::move(value)); - } - // Check and update extra properties - if (extras.end() != extrasIter) - { - const auto& propsIter = - (extrasIter->second).find(interfaceList.first); - if ((extrasIter->second).end() != propsIter) - { - for (const auto& map : propsIter->second) - { - props.emplace(map.first, map.second); - } - } - } - interfaces.emplace(std::move(interfaceList.first), - std::move(props)); - } - - // Call the inventory manager - sdbusplus::message::object_path path = instance.path; - // Check and update extra properties - if (extras.end() != extrasIter) - { - for (const auto& entry : extrasIter->second) - { - if (interfaces.end() == interfaces.find(entry.first)) - { - interfaces.emplace(entry.first, entry.second); - } - } - } - objects.emplace(path, interfaces); - } - - auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), - intf.c_str(), "Notify"); - pimMsg.append(std::move(objects)); - - try - { - auto inventoryMgrResponseMsg = bus.call(pimMsg); - } - catch (const sdbusplus::exception::SdBusError& ex) - { - log("Error in notify call", entry("WHAT=%s", ex.what())); - return -1; - } - - return rc; -} - ///---------------------------------------------------- // Checks if a particular fru area is populated or not ///---------------------------------------------------- @@ -688,7 +687,7 @@ int validateFRUArea(const uint8_t fruid, const char* fru_file_name, #ifdef __IPMI_DEBUG__ std::printf("\n SIZE of vector is : [%d] \n", fru_area_vec.size()); #endif - rc = ipmi_update_inventory(fru_area_vec, bus_type); + rc = updateInventory(fru_area_vec, bus_type); if (rc < 0) { log("Error updating inventory."); -- cgit v1.2.1