IPMI changes to mark non present as non functional

When marking a unit as functional, both functional state
and presence need to be checked to avoid marking non-present
units as functional.

Change-Id: If7b710c39f1c2590b82378ebdb7014dc924599ff
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index c8d4fbf..8240108 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -132,7 +132,7 @@
                                                    interface.first,
                                                    property.first);
 
-            for (const auto& value : property.second)
+            for (const auto& value : std::get<OffsetValueMap>(property.second))
             {
                 if (propValue == value.second.assert)
                 {
@@ -176,7 +176,7 @@
                                                    interface.first,
                                                    property.first);
 
-            for (const auto& value : property.second)
+            for (const auto& value : std::get<OffsetValueMap>(property.second))
             {
                 if (propValue == value.second.assert)
                 {
@@ -230,8 +230,8 @@
     for (const auto& property : interface->second)
     {
         msg.append(property.first);
-        const auto& iter = property.second.find(data);
-        if (iter == property.second.end())
+        const auto& iter = std::get<OffsetValueMap>(property.second).find(data);
+        if (iter == std::get<OffsetValueMap>(property.second).end())
         {
             log<level::ERR>("Invalid event data");
             return IPMI_CC_PARM_OUT_OF_RANGE;
@@ -258,7 +258,7 @@
     for (const auto& property : interface->second)
     {
         msg.append(property.first);
-        for (const auto& value : property.second)
+        for (const auto& value : std::get<OffsetValueMap>(property.second))
         {
             if (assertionSet.test(value.first))
             {
@@ -310,11 +310,14 @@
     ipmi::sensor::InterfaceMap interfaces;
     for (const auto& interface : sensorInfo.propertyInterfaces)
     {
+        //For a property like functional state the result will be
+        //calculated based on the true value of all conditions.
         for (const auto& property : interface.second)
         {
             ipmi::sensor::PropertyMap props;
             bool valid = false;
-            for (const auto& value : property.second)
+            auto result = true;
+            for (const auto& value : std::get<OffsetValueMap>(property.second))
             {
                 if (assertionSet.test(value.first))
                 {
@@ -323,7 +326,7 @@
                     {
                         return IPMI_CC_OK;
                     }
-                    props.emplace(property.first, value.second.assert);
+                    result = result && value.second.assert.get<bool>();
                     valid = true;
                 }
                 else if (deassertionSet.test(value.first))
@@ -333,12 +336,25 @@
                     {
                         return IPMI_CC_OK;
                     }
-                    props.emplace(property.first, value.second.deassert);
+                    result = result && value.second.deassert.get<bool>();
                     valid = true;
                 }
             }
+            for (const auto& value :
+                    std::get<PreReqOffsetValueMap>(property.second))
+            {
+                if (assertionSet.test(value.first))
+                {
+                    result = result && value.second.assert.get<bool>();
+                }
+                else if (deassertionSet.test(value.first))
+                {
+                    result = result && value.second.deassert.get<bool>();
+                }
+            }
             if (valid)
             {
+                props.emplace(property.first, result);
                 interfaces.emplace(interface.first, std::move(props));
             }
         }