BMC Updater: Remove the Object.Delete interface from functional version

This commit enhances the functionality of the BMC software updater.
Previously, each BMC version uploaded to the system would implement the
Object.Delete D-Bus interface, including the version currently running
on the BMC. In principle, this is a pretty major issue - at best, the
Delete would do nothing to the current version but throw an error, and
at worst, it could partially remove it and cause problems.

This commit fixes that problem by moving the Delete implementation into
a separate object for each activation and removing that interface for
the current version.

Resolves openbmc/openbmc#2335

Change-Id: I721b7455c9fb309ecbb50f807aaa44a16d51ba5a
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 2282c28..33f4096 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -119,15 +119,19 @@
                                               bmcInventoryPath));
         }
 
-        activations.insert(std::make_pair(
-                               versionId,
-                               std::make_unique<Activation>(
-                                        bus,
-                                        path,
-                                        *this,
-                                        versionId,
-                                        activationState,
-                                        associations)));
+        auto activationPtr = std::make_unique<Activation>(
+                bus,
+                path,
+                *this,
+                versionId,
+                activationState,
+                associations);
+
+        activationPtr->deleteObject =
+                std::make_unique<Delete>(bus, path, *activationPtr);
+
+        activations.insert(std::make_pair(versionId, std::move(activationPtr)));
+
         versions.insert(std::make_pair(
                             versionId,
                             std::make_unique<VersionClass>(
@@ -212,15 +216,22 @@
                                 std::move(versionPtr)));
 
             // Create Activation instance for this version.
-            activations.insert(std::make_pair(
-                                   id,
-                                   std::make_unique<Activation>(
-                                       bus,
-                                       path,
-                                       *this,
-                                       id,
-                                       server::Activation::Activations::Active,
-                                       associations)));
+            auto activationPtr = std::make_unique<Activation>(
+                    bus,
+                    path,
+                    *this,
+                    id,
+                    activationState,
+                    associations);
+
+            // Add Delete() if this isn't the functional version
+            if (!isVersionFunctional)
+            {
+                activationPtr->deleteObject =
+                        std::make_unique<Delete>(bus, path, *activationPtr);
+            }
+
+            activations.insert(std::make_pair(id, std::move(activationPtr)));
 
             // If Active, create RedundancyPriority instance for this version.
             if (activationState == server::Activation::Activations::Active)