item_updater : Implementing Object.Delete for version

Change-Id: If962dec1da2d2fe925374bb37f89ed23f04c5ab6
Signed-off-by: Leonel Gonzalez <lgonzalez@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 7466d12..1c0a6b8 100755
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -121,7 +121,8 @@
                                 path,
                                 version,
                                 purpose,
-                                filePath)));
+                                filePath,
+                                *this)));
     }
     return;
 }
@@ -162,7 +163,8 @@
                              path,
                              version,
                              purpose,
-                             "")));
+                             "",
+                             *this)));
     return;
 }
 
@@ -183,11 +185,24 @@
     }
 }
 
-void ItemUpdater::reset()
+void ItemUpdater::removeReadOnlyPartition(std::string versionId)
 {
-    for(const auto& it : activations)
-    {
-        auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + it.first +
+        auto serviceFile = "obmc-flash-bios-ubiumount-ro@" + versionId +
+                ".service";
+
+        // Remove the read-only partitions.
+        auto method = bus.new_method_call(
+                SYSTEMD_BUSNAME,
+                SYSTEMD_PATH,
+                SYSTEMD_INTERFACE,
+                "StartUnit");
+        method.append(serviceFile, "replace");
+        bus.call_noreply(method);
+}
+
+void ItemUpdater::removeReadWritePartition(std::string versionId)
+{
+        auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + versionId +
                 ".service";
 
         // Remove the read-write partitions.
@@ -198,8 +213,10 @@
                 "StartUnit");
         method.append(serviceFile, "replace");
         bus.call_noreply(method);
-    }
+}
 
+void ItemUpdater::removePreservedPartition()
+{
     // Remove the preserved partition.
     auto method = bus.new_method_call(
             SYSTEMD_BUSNAME,
@@ -212,6 +229,16 @@
     return;
 }
 
+void ItemUpdater::reset()
+{
+    for(const auto& it : activations)
+    {
+        removeReadWritePartition(it.first);
+    }
+    removePreservedPartition();
+    return;
+}
+
 void ItemUpdater::freePriority(uint8_t value)
 {
     //TODO openbmc/openbmc#1896 Improve the performance of this function
@@ -242,6 +269,35 @@
     return true;
 }
 
+void ItemUpdater::erase(std::string entryId)
+{
+    // Removing partitions
+    removeReadWritePartition(entryId);
+    removeReadOnlyPartition(entryId);
+
+    // Removing entry in versions map
+    auto it = versions.find(entryId);
+    if (it == versions.end())
+    {
+        log<level::ERR>(("Error: Failed to find version " + entryId + \
+                        " in item updater versions map." \
+                        " Unable to remove.").c_str());
+        return;
+    }
+    versions.erase(entryId);
+
+    // Removing entry in activations map
+    auto ita = activations.find(entryId);
+    if (ita == activations.end())
+    {
+        log<level::ERR>(("Error: Failed to find version " + entryId + \
+                        " in item updater activations map." \
+                        " Unable to remove.").c_str());
+        return;
+    }
+    activations.erase(entryId);
+}
+
 } // namespace updater
 } // namespace software
 } // namespace openpower