pfr-manager: move cpld_active version to settings service

Add Support to move the cpld_version object to settings service and
update the version in pfr-manager.

This is done to have the cpld_active version displayed in redfish if
pfr-manager stopped.

Tested:
Command: busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_
         project/software/cpld_active xyz.openbmc_project.Software.
         Version "Version"
Response:
s "0.7-1.0-8675b80f7c90e9163f19b6af2351e3c231f4d154b5f03
   1442b6c3d9777671694"
Command: GET: https://BMC_IP>/redfish/v1/UpdateService/FirmwareInventory
              /cpld_active
Response:
{
    "@odata.id": "/redfish/v1/UpdateService/FirmwareInventory/
                 cpld_active",
    "@odata.type": "#SoftwareInventory.v1_1_0.SoftwareInventory",
    "Description": "Other image",
    "Id": "cpld_active",
    "Name": "Software Inventory",
    "Status": {
        "Health": "OK",
        "HealthRollup": "OK",
        "State": "Enabled"
    },
    "Updateable": false,
    "Version": "0.7-1.0-8675b80f7c90e9163f19b6af2351e3c231f4d154b5f03
                1442b6c3d9777671694"
}

Signed-off-by: Chalapathi Venkataramashetty <chalapathix.venkataramashetty@intel.com>
Change-Id: I3772db318f25afff39c44692bea7c510b0070647
diff --git a/service/src/mainapp.cpp b/service/src/mainapp.cpp
index 316bdda..ba714fe 100644
--- a/service/src/mainapp.cpp
+++ b/service/src/mainapp.cpp
@@ -49,8 +49,6 @@
                         versionPurposeBMC),
         std::make_tuple("bios_recovery", ImageType::biosRecovery,
                         versionPurposeHost),
-        std::make_tuple("cpld_active", ImageType::cpldActive,
-                        versionPurposeOther),
         std::make_tuple("cpld_recovery", ImageType::cpldRecovery,
                         versionPurposeOther),
 };
@@ -456,6 +454,27 @@
     checkAndLogEvents();
 }
 
+static void updateCPLDversion(std::shared_ptr<sdbusplus::asio::connection> conn)
+{
+    std::string cpldVersion = pfr::readCPLDVersion();
+    conn->async_method_call(
+        [](const boost::system::error_code ec) {
+            if (ec)
+            {
+                phosphor::logging::log<phosphor::logging::level::ERR>(
+                    "Unable to update cpld_active version",
+                    phosphor::logging::entry("MSG=%s", ec.message().c_str()));
+                return;
+            }
+        },
+        "xyz.openbmc_project.Settings",
+        "/xyz/openbmc_project/software/cpld_active",
+        "org.freedesktop.DBus.Properties", "Set",
+        "xyz.openbmc_project.Software.Version", "Version",
+        std::variant<std::string>(cpldVersion));
+    return;
+}
+
 } // namespace pfr
 
 int main()
@@ -468,6 +487,9 @@
     auto server = sdbusplus::asio::object_server(conn, true);
     pfr::monitorSignals(server, conn);
 
+    // Update CPLD Version to cpld_active object in settings.
+    pfr::updateCPLDversion(conn);
+
     server.add_manager("/xyz/openbmc_project/pfr");
 
     // Create PFR attributes object and interface