Revert "StorageCmd: Get fru data from different services"

This commit is being reverted as part of an on-going process to
migrate portions of intel-ipmi-oem code to general purpose
phosphor-ipmi-host functions.

Gerrit review: https://gerrit.openbmc.org/c/openbmc/intel-ipmi-oem/+/46931
SHA: f23fd543404a948ae436a5cf4092354dcb60a366

The phosphor-ipmi-host version of storagecommands in the dbus-sdr
subdirectory does not implement this commit. Despite not having this
code in place the FRU functionality works correctly.

The commit message does not provide a good explanation of why it
exists. In light of the fact that the FRU's are enumerated, and FRU
IPMI commands function correctly without this change, the code is
being removed. In the event that this code did provide value, it can
be addressed in the phosphor-ipmi-host base.

Change-Id: Ie25c2719dd4d5482d789c0249ec3e11916203813
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/storagecommands.cpp b/src/storagecommands.cpp
index 5f1a8f8..25eea96 100644
--- a/src/storagecommands.cpp
+++ b/src/storagecommands.cpp
@@ -24,6 +24,7 @@
 
 #include <boost/algorithm/string.hpp>
 #include <boost/container/flat_map.hpp>
+#include <boost/process.hpp>
 #include <ipmid/api.hpp>
 #include <ipmid/message.hpp>
 #include <phosphor-logging/log.hpp>
@@ -32,9 +33,10 @@
 
 #include <filesystem>
 #include <fstream>
+#include <functional>
 #include <iostream>
 #include <stdexcept>
-#include <unordered_set>
+#include <string_view>
 
 static constexpr bool DEBUG = false;
 
@@ -97,8 +99,6 @@
 using ManagedObjectType =
     boost::container::flat_map<sdbusplus::message::object_path, ObjectType>;
 using ManagedEntry = std::pair<sdbusplus::message::object_path, ObjectType>;
-using GetObjectType =
-    std::vector<std::pair<std::string, std::vector<std::string>>>;
 
 constexpr static const char* fruDeviceServiceName =
     "xyz.openbmc_project.FruDevice";
@@ -124,8 +124,6 @@
 // we unfortunately have to build a map of hashes in case there is a
 // collision to verify our dev-id
 boost::container::flat_map<uint8_t, std::pair<uint16_t, uint8_t>> deviceHashes;
-// Map devId to Object Path
-boost::container::flat_map<uint8_t, std::string> devicePath;
 
 void registerStorageFunctions() __attribute__((constructor));
 
@@ -164,7 +162,6 @@
 void recalculateHashes()
 {
     deviceHashes.clear();
-    devicePath.clear();
     // hash the object paths to create unique device id's. increment on
     // collision
     std::hash<std::string> hasher;
@@ -212,9 +209,6 @@
         while (!emplacePassed)
         {
             auto resp = deviceHashes.emplace(fruHash, newDev);
-
-            devicePath.emplace(fruHash, fru.first);
-
             emplacePassed = resp.second;
             if (!emplacePassed)
             {
@@ -234,64 +228,18 @@
                      boost::asio::yield_context& yield)
 {
     boost::system::error_code ec;
-    // ObjectPaths and Services which implements "xyz.openbmc_project.FruDevice"
-    // interface
-    GetSubTreeType fruServices = bus->yield_method_call<GetSubTreeType>(
-        yield, ec, "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
-        std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
 
+    frus = bus->yield_method_call<ManagedObjectType>(
+        yield, ec, fruDeviceServiceName, "/",
+        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
     if (ec)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
-            "GetSubTree failed for FruDevice Interface ",
+            "GetMangagedObjects for getSensorMap failed",
             phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
 
         return;
     }
-    // Get List of services which have implemented FruDevice interface
-    std::unordered_set<std::string> services;
-    for (const auto& [path, serviceMap] : fruServices)
-    {
-        for (const auto& [service, interfaces] : serviceMap)
-        {
-            services.insert(service);
-        }
-    }
-
-    // GetAll the objects under services which implement FruDevice interface
-    for (const std::string& service : services)
-    {
-        ec = boost::system::errc::make_error_code(boost::system::errc::success);
-        ManagedObjectType obj = bus->yield_method_call<ManagedObjectType>(
-            yield, ec, service, "/", "org.freedesktop.DBus.ObjectManager",
-            "GetManagedObjects");
-        if (ec)
-        {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "GetMangagedObjects failed",
-                phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
-            continue;
-        }
-        // Save the object path which has FruDevice interface
-        for (const auto& [path, serviceMap] : fruServices)
-        {
-            for (const auto& serv : serviceMap)
-            {
-                if (serv.first == service)
-                {
-                    auto fru = obj.find(path);
-                    if (fru == obj.end())
-                    {
-                        continue;
-                    }
-                    frus.emplace(fru->first, fru->second);
-                }
-            }
-        }
-    }
-
     recalculateHashes();
 }
 
@@ -303,8 +251,7 @@
     }
 
     auto deviceFind = deviceHashes.find(devId);
-    auto devPath = devicePath.find(devId);
-    if (deviceFind == deviceHashes.end() || devPath == devicePath.end())
+    if (deviceFind == deviceHashes.end())
     {
         return IPMI_CC_SENSOR_INVALID;
     }
@@ -321,38 +268,14 @@
     cacheAddr = deviceFind->second.second;
 
     boost::system::error_code ec;
-    GetObjectType fruService = ctx->bus->yield_method_call<GetObjectType>(
-        ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetObject", devPath->second,
-        std::array<const char*, 1>{"xyz.openbmc_project.FruDevice"});
 
+    fruCache = ctx->bus->yield_method_call<std::vector<uint8_t>>(
+        ctx->yield, ec, fruDeviceServiceName, "/xyz/openbmc_project/FruDevice",
+        "xyz.openbmc_project.FruDeviceManager", "GetRawFru", cacheBus,
+        cacheAddr);
     if (ec)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Couldn't get raw fru because of service",
-            phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
-        return ipmi::ccResponseError;
-    }
-
-    bool foundFru = false;
-    for (auto& service : fruService)
-    {
-        fruCache = ctx->bus->yield_method_call<std::vector<uint8_t>>(
-            ctx->yield, ec, service.first, "/xyz/openbmc_project/FruDevice",
-            "xyz.openbmc_project.FruDeviceManager", "GetRawFru", cacheBus,
-            cacheAddr);
-
-        if (!ec)
-        {
-            foundFru = true;
-            break;
-        }
-    }
-
-    if (!foundFru)
-    {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
             "Couldn't get raw fru",
             phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
         cacheBus = 0xFFFF;