Redfish: Fix the health and state properties of processor

The processor resource needs to look at Present and Functional to determine state and health.
This is how other resources do it.
It should not look at totalCores to determine present / State.

HealthPopulate is not used. We use Functional to determine health status.
Functional is a bool that HealthPopulate cannot handle.

Signed-off-by: Chicago Duan <duanzhijia01@inspur.com>
Change-Id: Iff900061254fdd991b2dfa573b364a04decd8f98
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index efc6c32..bd18707 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -50,36 +50,51 @@
 {
     BMCWEB_LOG_DEBUG << "Get CPU resources by interface.";
 
-    // Added for future purpose. Once present and functional attributes added
-    // in busctl call, need to add actual logic to fetch original values.
-    bool present = false;
-    const bool functional = true;
-    auto health = std::make_shared<HealthPopulate>(aResp);
-    health->populate();
+    // Set the default value of state
+    aResp->res.jsonValue["Status"]["State"] = "Enabled";
+    aResp->res.jsonValue["Status"]["Health"] = "OK";
 
     for (const auto& interface : cpuInterfacesProperties)
     {
         for (const auto& property : interface.second)
         {
-            if (property.first == "CoreCount")
+            if (property.first == "Present")
             {
-                const uint16_t* coresCount =
-                    std::get_if<uint16_t>(&property.second);
-                if (coresCount == nullptr)
+                const bool* cpuPresent = std::get_if<bool>(&property.second);
+                if (cpuPresent == nullptr)
                 {
                     // Important property not in desired type
                     messages::internalError(aResp->res);
                     return;
                 }
-                if (*coresCount == 0)
+                if (*cpuPresent == false)
                 {
-                    // Slot is not populated, set status end return
+                    // Slot is not populated
                     aResp->res.jsonValue["Status"]["State"] = "Absent";
-                    // HTTP Code will be set up automatically, just return
+                }
+            }
+            else if (property.first == "Functional")
+            {
+                const bool* cpuFunctional = std::get_if<bool>(&property.second);
+                if (cpuFunctional == nullptr)
+                {
+                    messages::internalError(aResp->res);
                     return;
                 }
-                aResp->res.jsonValue["Status"]["State"] = "Enabled";
-                present = true;
+                if (*cpuFunctional == false)
+                {
+                    aResp->res.jsonValue["Status"]["Health"] = "Critical";
+                }
+            }
+            else if (property.first == "CoreCount")
+            {
+                const uint16_t* coresCount =
+                    std::get_if<uint16_t>(&property.second);
+                if (coresCount == nullptr)
+                {
+                    messages::internalError(aResp->res);
+                    return;
+                }
                 aResp->res.jsonValue["TotalCores"] = *coresCount;
             }
             else if (property.first == "MaxSpeedInMhz")
@@ -122,7 +137,6 @@
                 const uint64_t* value = std::get_if<uint64_t>(&property.second);
                 if (value != nullptr && *value != 0)
                 {
-                    present = true;
                     aResp->res
                         .jsonValue["ProcessorId"]["IdentificationRegisters"] =
                         boost::lexical_cast<std::string>(*value);
@@ -131,24 +145,6 @@
         }
     }
 
-    if (present == false)
-    {
-        aResp->res.jsonValue["Status"]["State"] = "Absent";
-        aResp->res.jsonValue["Status"]["Health"] = "OK";
-    }
-    else
-    {
-        aResp->res.jsonValue["Status"]["State"] = "Enabled";
-        if (functional)
-        {
-            aResp->res.jsonValue["Status"]["Health"] = "OK";
-        }
-        else
-        {
-            aResp->res.jsonValue["Status"]["Health"] = "Critical";
-        }
-    }
-
     return;
 }