Fix No Total Memory Size Issue

Total Memory in redfish is always 0, fix the problem.

Tested:
After DC cycle the system. TotalSystemMemoryGiB in Redfish system page should
not be zero.

"MemorySummary": {
    "Status": {
        "State": "Enabled"
    },
    "TotalSystemMemoryGiB": 16
},

Signed-off-by: Cheng C Yang <cheng.c.yang@linux.intel.com>
Change-Id: I89ad8ed1cf5f9ca9589db444740167645dab9a6e
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index d8bc8f5..84acc58 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -75,7 +75,7 @@
 // Note, this is not a very useful Variant, but because it isn't used to get
 // values, it should be as simple as possible
 // TODO(ed) invent a nullvariant type
-using VariantType = std::variant<bool, std::string, uint64_t>;
+using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>;
 using ManagedObjectsType = std::vector<std::pair<
     sdbusplus::message::object_path,
     std::vector<std::pair<std::string,
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 0e6cb09..ce12ed7 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -215,26 +215,45 @@
                                                              VariantType>
                                                  &property : properties)
                                         {
-                                            if (property.first ==
-                                                "MemorySizeInKb")
+                                            if (property.first !=
+                                                "MemorySizeInKB")
                                             {
-                                                const uint64_t *value =
-                                                    sdbusplus::message::
-                                                        variant_ns::get_if<
-                                                            uint64_t>(
-                                                            &property.second);
-                                                if (value != nullptr)
-                                                {
-                                                    aResp->res.jsonValue
-                                                        ["TotalSystemMemoryGi"
-                                                         "B"] +=
-                                                        *value / (1024 * 1024);
-                                                    aResp->res.jsonValue
-                                                        ["MemorySummary"]
-                                                        ["Status"]["State"] =
-                                                        "Enabled";
-                                                }
+                                                continue;
                                             }
+                                            const uint32_t *value =
+                                                sdbusplus::message::variant_ns::
+                                                    get_if<uint32_t>(
+                                                        &property.second);
+                                            if (value == nullptr)
+                                            {
+                                                BMCWEB_LOG_DEBUG
+                                                    << "Find incorrect type of "
+                                                       "MemorySize";
+                                                continue;
+                                            }
+                                            nlohmann::json &totalMemory =
+                                                aResp->res
+                                                    .jsonValue["MemorySummar"
+                                                               "y"]
+                                                              ["TotalSystemMe"
+                                                               "moryGiB"];
+                                            uint64_t *preValue =
+                                                totalMemory
+                                                    .get_ptr<uint64_t *>();
+                                            if (preValue == nullptr)
+                                            {
+                                                continue;
+                                            }
+                                            aResp->res
+                                                .jsonValue["MemorySummary"]
+                                                          ["TotalSystemMemoryGi"
+                                                           "B"] =
+                                                *value / (1024 * 1024) +
+                                                *preValue;
+                                            aResp->res
+                                                .jsonValue["MemorySummary"]
+                                                          ["Status"]["State"] =
+                                                "Enabled";
                                         }
                                     }
                                     else
@@ -1669,7 +1688,7 @@
         res.jsonValue["Description"] = "Computer System";
         res.jsonValue["ProcessorSummary"]["Count"] = 0;
         res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled";
-        res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = int(0);
+        res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0);
         res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled";
         res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";