sensor: Add function to map dbus info to assertion status

Change-Id: I30aae9abd7905ae3299856d798d41e10859fed7f
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index b9ef5e2..231822b 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -1,9 +1,12 @@
 #include <bitset>
+#include <experimental/filesystem>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
 #include "xyz/openbmc_project/Common/error.hpp"
 #include "types.hpp"
+#include "sensorhandler.h"
 #include "sensordatahandler.hpp"
+#include "utils.hpp"
 
 namespace ipmi
 {
@@ -104,6 +107,55 @@
     return IPMI_CC_OK;
 }
 
+namespace get
+{
+
+GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
+                                     const InstancePath& path,
+                                     const DbusInterface& interface)
+{
+    sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+    GetSensorResponse response {};
+    auto responseData = reinterpret_cast<GetReadingResponse*>(response.data());
+
+    auto service = ipmi::getService(bus, interface, path);
+
+    const auto& interfaceList = sensorInfo.propertyInterfaces;
+
+    for (const auto& interface : interfaceList)
+    {
+        for (const auto& property : interface.second)
+        {
+            auto propValue = ipmi::getDbusProperty(bus,
+                                                   service,
+                                                   path,
+                                                   interface.first,
+                                                   property.first);
+
+            for (const auto& value : property.second)
+            {
+                if (propValue == value.second.assert)
+                {
+                    setOffset(value.first, responseData);
+                    break;
+                }
+
+            }
+        }
+    }
+
+    return response;
+}
+
+GetSensorResponse assertion(const Info& sensorInfo)
+{
+    return mapDbusToAssertion(sensorInfo,
+                              sensorInfo.sensorPath,
+                              sensorInfo.sensorInterface);
+}
+
+} //namespace get
+
 namespace set
 {
 
@@ -252,6 +304,30 @@
     msg.append(std::move(objects));
     return updateToDbus(msg);
 }
+
 }//namespace notify
+
+namespace inventory
+{
+
+namespace get
+{
+
+GetSensorResponse assertion(const Info& sensorInfo)
+{
+    namespace fs = std::experimental::filesystem;
+
+    fs::path path{ipmi::sensor::inventoryRoot};
+    path += sensorInfo.sensorPath;
+
+    return ipmi::sensor::get::mapDbusToAssertion(
+            sensorInfo,
+            path.string(),
+            sensorInfo.propertyInterfaces.begin()->first);
+}
+
+} //namespace get
+
+} // namespace inventory
 }//namespace sensor
 }//namespace ipmi