Refactor reading and parsing of inventory data

Refactored to use 'GetAll' dbus method call over multiple 'Get'
dbus method calls to read the properties of a inventory object.

Change-Id: I0ddc2150830961666fafa661cf29042f66137977
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
diff --git a/read_fru_data.cpp b/read_fru_data.cpp
index b23498e..a7a3256 100644
--- a/read_fru_data.cpp
+++ b/read_fru_data.cpp
@@ -5,6 +5,7 @@
 #include "fruread.hpp"
 #include "host-ipmid/ipmid-api.h"
 #include "utils.hpp"
+#include "types.hpp"
 
 extern const FruMap frus;
 namespace ipmi
@@ -30,40 +31,36 @@
     FRUAreaMap fruMap;
 }
 /**
- * @brief Read the property value from Inventory
+ * @brief Read all the property value's for the specified interface
+ *  from Inventory.
  *
- * @param[in] bus dbus
  * @param[in] intf Interface
- * @param[in] propertyName Name of the property
  * @param[in] path Object path
- * @return property value
+ * @return map of properties
  */
-std::string readProperty(const std::string& intf,
-                         const std::string& propertyName,
-                         const std::string& path)
+ipmi::PropertyMap readAllProperties(const std::string& intf,
+                                  const std::string& path)
 {
+    ipmi::PropertyMap properties;
     sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
     auto service = ipmi::getService(bus, INV_INTF, OBJ_PATH);
     std::string objPath = OBJ_PATH + path;
     auto method = bus.new_method_call(service.c_str(),
                                       objPath.c_str(),
                                       PROP_INTF,
-                                      "Get");
-    method.append(intf, propertyName);
+                                      "GetAll");
+    method.append(intf);
     auto reply = bus.call(method);
     if (reply.is_method_error())
     {
         //If property is not found simply return empty value
-        log<level::INFO>("Property value not set",
-            entry("Property=%s", propertyName),
+        log<level::ERR>("Error in reading property values from inventory",
+            entry("Interface=%s", intf),
             entry("Path=%s", objPath));
-        return {};
+        return properties;
     }
-    sdbusplus::message::variant<std::string> property;
-    reply.read(property);
-    std::string value =
-        sdbusplus::message::variant_ns::get<std::string>(property);
-    return value;
+    reply.read(properties);
+    return properties;
 }
 
 void processFruPropChange(sdbusplus::message::message& msg)
@@ -136,15 +133,18 @@
     auto& instanceList = iter->second;
     for (auto& instance : instanceList)
     {
-        for (auto& interfaceList : instance.second)
+        for (auto& intf : instance.second)
         {
-            for (auto& properties : interfaceList.second)
+            ipmi::PropertyMap allProp = readAllProperties(
+                    intf.first, instance.first);
+            for (auto& properties : intf.second)
             {
-                decltype(auto) pdata = properties.second;
-                auto value = readProperty(
-                        interfaceList.first, properties.first,
-                        instance.first);
-                data[pdata.section].emplace(properties.first, value);
+                auto iter = allProp.find(properties.first);
+                if (iter != allProp.end())
+                {
+                    data[properties.second.section].emplace(properties.first,
+                        std::move(allProp[properties.first].get<std::string>()));
+                }
             }
         }
     }