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/activation.hpp b/activation.hpp
index 6c303db..d1d050a 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -19,14 +19,15 @@
      std::vector<std::tuple<std::string, std::string, std::string>>;
 using ActivationInherit = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Software::server::Activation,
-    sdbusplus::org::openbmc::server::Associations,
-    sdbusplus::xyz::openbmc_project::Object::server::Delete>;
+    sdbusplus::org::openbmc::server::Associations>;
 using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
  sdbusplus::xyz::openbmc_project::Software::server::ActivationBlocksTransition>;
 using RedundancyPriorityInherit = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
 using ActivationProgressInherit = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
+using DeleteInherit = sdbusplus::server::object::object<
+    sdbusplus::xyz::openbmc_project::Object::server::Delete>;
 
 namespace sdbusRule = sdbusplus::bus::match::rules;
 
@@ -166,8 +167,55 @@
         std::string path;
 };
 
-// TODO: openbmc/openbmc#2086 - Add removeActiveAssociation() after
-//       Delete() is implemented
+/** @class ActivationDelete
+ *  @brief OpenBMC Delete implementation.
+ *  @details A concrete implementation for xyz.openbmc_project.Object.Delete
+ *  DBus API.
+ */
+class Delete : public DeleteInherit
+{
+    public:
+        /** @brief Constructs Delete.
+          *
+          * @param[in] bus    - The Dbus bus object
+          * @param[in] path   - The Dbus object path
+          * @param[in] parent - Parent object.
+          */
+        // Delete(sdbusplus::bus::bus& bus, const std::string& path) :
+        Delete(sdbusplus::bus::bus& bus,
+               const std::string& path,
+               Activation& parent) :
+                DeleteInherit(bus, path.c_str(), true),
+                parent(parent),
+                bus(bus),
+                path(path)
+        {
+            std::vector<std::string> interfaces({interface});
+            bus.emit_interfaces_added(path.c_str(), interfaces);
+        }
+
+        ~Delete()
+        {
+            std::vector<std::string> interfaces({interface});
+            bus.emit_interfaces_removed(path.c_str(), interfaces);
+        }
+
+        /**
+         * @brief delete the d-bus object.
+         */
+        void delete_() override;
+
+        /** @brief Parent Object. */
+        Activation& parent;
+
+    private:
+        // TODO Remove once openbmc/openbmc#1975 is resolved
+        static constexpr auto interface =
+                "xyz.openbmc_project.Object.Delete";
+        sdbusplus::bus::bus& bus;
+        std::string path;
+};
+
 /** @class Activation
  *  @brief OpenBMC activation software management implementation.
  *  @details A concrete implementation for
@@ -272,11 +320,6 @@
          */
         void updateUbootEnvVars();
 
-        /**
-         * @brief delete the d-bus object.
-         */
-        void delete_() override;
-
         /** @brief Persistent sdbusplus DBus bus connection */
         sdbusplus::bus::bus& bus;
 
@@ -298,6 +341,9 @@
         /** @brief Persistent ActivationProgress dbus object */
         std::unique_ptr<ActivationProgress> activationProgress;
 
+        /** @brief Persistent Delete dbus object */
+        std::unique_ptr<Delete> deleteObject;
+
         /** @brief Used to subscribe to dbus systemd signals **/
         sdbusplus::bus::match_t systemdSignals;