PNOR: Fix the delete implementation

- In order to remove the delete object from functional
  image, the delete interface is moved inside the
  version class so that both item_updater and image_manager
  can make use of the same implementation.
- To avoid having two delete objects attached to the same
  HOST version (item_updater and image_manager), we are now
  deleting the image_manager object once the activation
  is complete.

Partially resolves openbmc/openbmc#2490

Change-Id: Ie515cc01d5f154e6e55b9a3fb71d831730cd46f6
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/activation.hpp b/activation.hpp
index 286c85d..ed077ae 100755
--- a/activation.hpp
+++ b/activation.hpp
@@ -6,9 +6,7 @@
 #include "xyz/openbmc_project/Software/ExtendedVersion/server.hpp"
 #include "xyz/openbmc_project/Software/RedundancyPriority/server.hpp"
 #include "xyz/openbmc_project/Software/ActivationProgress/server.hpp"
-#include "xyz/openbmc_project/Object/Delete/server.hpp"
 #include "org/openbmc/Associations/server.hpp"
-#include "config.h"
 
 namespace openpower
 {
@@ -29,8 +27,6 @@
     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;
 
@@ -170,53 +166,6 @@
         std::string path;
 };
 
-/** @class ActivationDelete
- *  @brief OpenBMC Delete implementation.
- *  @details A concrete implementation for xyz.openbmc_project.Object.Delete
- *  D-Bus API.
- */
-class Delete : public DeleteInherit
-{
-    public:
-        /** @brief Constructs Delete.
-          *
-          * @param[in] bus    - The D-Bus bus object
-          * @param[in] path   - The D-Bus object path
-          * @param[in] parent - Parent object.
-          */
-        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:
-        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
@@ -255,17 +204,7 @@
                            sdbusRule::interface(
                                    "org.freedesktop.systemd1.Manager"),
                            std::bind(std::mem_fn(&Activation::unitStateChange),
-                                  this, std::placeholders::_1)),
-                  chassisStateSignals(
-                          bus,
-                          sdbusRule::type::signal() +
-                          sdbusRule::member("PropertiesChanged") +
-                          sdbusRule::path(CHASSIS_STATE_PATH) +
-                          sdbusRule::argN(0, CHASSIS_STATE_OBJ) +
-                          sdbusRule::interface(SYSTEMD_PROPERTY_INTERFACE),
-                          std::bind(std::mem_fn(
-                                  &Activation::updateDeleteInterface), this,
-                                  std::placeholders::_1))
+                                  this, std::placeholders::_1))
         {
             // Enable systemd signals
             subscribeToSystemdSignals();
@@ -311,17 +250,6 @@
          */
         void unitStateChange(sdbusplus::message::message& msg);
 
-        /** @brief Update the Object.Delete interface for this activation
-         *
-         * Update the delete interface based on whether or not this activation
-         * is currently functional. A functional activation will have no
-         * Object.Delete, while a non-functional activation will have one.
-         *
-         * @param[in]  msg       - Data associated with subscribed signal
-         *
-         */
-        void updateDeleteInterface(sdbusplus::message::message& msg);
-
         /**
          * @brief subscribe to the systemd signals
          *
@@ -361,15 +289,9 @@
         /** @brief Persistent RedundancyPriority dbus object */
         std::unique_ptr<RedundancyPriority> redundancyPriority;
 
-        /** @brief Persistent Delete dbus object */
-        std::unique_ptr<Delete> deleteObject;
-
         /** @brief Used to subscribe to dbus systemd signals **/
         sdbusplus::bus::match_t systemdSignals;
 
-        /** @brief Used to subscribe to chassis power state changes **/
-        sdbusplus::bus::match_t chassisStateSignals;
-
         /** @brief Tracks whether the read-only & read-write volumes have been
          *created as part of the activation process. **/
         bool ubiVolumesCreated = false;
@@ -381,6 +303,13 @@
         using ActivationInherit::activation;
 
     private:
+
+        /**
+         * @brief Deletes the version from Image Manager and the
+         *        untar image from image upload dir.
+         */
+        void deleteImageManagerObject();
+
         /** @brief Member function for clarity & brevity at activation start */
         void startActivation();