Processor: Add UUID property

This commit adds the support for implementing the "UUID" property
as defined in the Redfish Processor schema.

UUID will enable further platform/board specific monitoring and control.

Redfish validator passed.

Tested:
$ curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/json"
-X GET https://${bmc}/redfish/v1/Systems/system/Processors/GPU1
{
  "@odata.id": "/redfish/v1/Systems/system/Processors/GPU1",
  "@odata.type": "#Processor.v1_11_0.Processor",
  "Id": "GPU1",
  "Name": "Processor",
  "UUID": "5429d122-cd8a-4ff3-9102-be794ecfb8a7"
}

Signed-off-by: Sharad Yadav <sharady@nvidia.com>
Change-Id: I23633728d965e26d7231dc3f2badc45de1fb268a
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index 8127510..a0b6a1f 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -44,6 +44,43 @@
     "xyz.openbmc_project.Inventory.Item.Cpu",
     "xyz.openbmc_project.Inventory.Item.Accelerator"};
 
+/**
+ * @brief Fill out uuid info of a processor by
+ * requesting data from the given D-Bus object.
+ *
+ * @param[in,out]   aResp       Async HTTP response.
+ * @param[in]       service     D-Bus service to query.
+ * @param[in]       objPath     D-Bus object to query.
+ */
+inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp,
+                             const std::string& service,
+                             const std::string& objPath)
+{
+    BMCWEB_LOG_DEBUG << "Get Processor UUID";
+    crow::connections::systemBus->async_method_call(
+        [objPath,
+         aResp{std::move(aResp)}](const boost::system::error_code ec,
+                                  const std::variant<std::string>& property) {
+            if (ec)
+            {
+                BMCWEB_LOG_DEBUG << "DBUS response error";
+                messages::internalError(aResp->res);
+                return;
+            }
+            const std::string* value = std::get_if<std::string>(&property);
+            if (value == nullptr)
+            {
+                BMCWEB_LOG_DEBUG << "Null value returned "
+                                    "for UUID";
+                messages::internalError(aResp->res);
+                return;
+            }
+            aResp->res.jsonValue["UUID"] = *value;
+        },
+        service, objPath, "org.freedesktop.DBus.Properties", "Get",
+        "xyz.openbmc_project.Common.UUID", "UUID");
+}
+
 inline void
     getCpuDataByInterface(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
                           const InterfacesProperties& cpuInterfacesProperties)
@@ -684,7 +721,8 @@
         "/xyz/openbmc_project/object_mapper",
         "xyz.openbmc_project.ObjectMapper", "GetSubTree",
         "/xyz/openbmc_project/inventory", 0,
-        std::array<const char*, 6>{
+        std::array<const char*, 7>{
+            "xyz.openbmc_project.Common.UUID",
             "xyz.openbmc_project.Inventory.Decorator.Asset",
             "xyz.openbmc_project.Inventory.Decorator.Revision",
             "xyz.openbmc_project.Inventory.Item.Cpu",
@@ -732,6 +770,10 @@
             {
                 getCpuLocationCode(aResp, serviceName, objectPath);
             }
+            else if (interface == "xyz.openbmc_project.Common.UUID")
+            {
+                getProcessorUUID(aResp, serviceName, objectPath);
+            }
         }
     }
 }