Implement host factory reset in item_updater

This commit implements a factory reset interface for the host.
This factory reset is accomplished by clearing all read/write
PNOR partitions.

Resolves openbmc/openbmc#1574

Change-Id: Ia2c9bd9cf829520bc724abb48aa2df3163f7d78a
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index 7a5629d..3f72aeb 100755
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -144,7 +144,35 @@
     }
 }
 
+void ItemUpdater::reset()
+{
+    for(const auto& it : activations)
+    {
+        auto serviceFile = "obmc-flash-bios-ubiumount-rw@" + it.first +
+                ".service";
+
+        // Remove the read-write partitions.
+        auto method = busItem.new_method_call(
+                SYSTEMD_BUSNAME,
+                SYSTEMD_PATH,
+                SYSTEMD_INTERFACE,
+                "StartUnit");
+        method.append(serviceFile, "replace");
+        busItem.call_noreply(method);
+    }
+
+    // Remove the preserved partition.
+    auto method = busItem.new_method_call(
+            SYSTEMD_BUSNAME,
+            SYSTEMD_PATH,
+            SYSTEMD_INTERFACE,
+            "StartUnit");
+    method.append("obmc-flash-bios-ubiumount-prsv.service", "replace");
+    busItem.call_noreply(method);
+
+    return;
+}
+
 } // namespace updater
 } // namespace software
 } // namespace openpower
-
diff --git a/item_updater.hpp b/item_updater.hpp
index 8e79d1d..0e8558a 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -2,6 +2,7 @@
 
 #include <sdbusplus/server.hpp>
 #include "activation.hpp"
+#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
 
 namespace openpower
 {
@@ -10,24 +11,22 @@
 namespace updater
 {
 
+using ItemUpdaterInherit = sdbusplus::server::object::object<
+    sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
+
 /** @class ItemUpdater
  *  @brief Manages the activation of the version items.
  */
-class ItemUpdater
+class ItemUpdater : public ItemUpdaterInherit
 {
     public:
-        ItemUpdater() = delete;
-        ~ItemUpdater() = default;
-        ItemUpdater(const ItemUpdater&) = delete;
-        ItemUpdater& operator=(const ItemUpdater&) = delete;
-        ItemUpdater(ItemUpdater&&) = delete;
-        ItemUpdater& operator=(ItemUpdater&&) = delete;
-
         /** @brief Constructs ItemUpdater
          *
          * @param[in] bus    - The Dbus bus object
+         * @param[in] path   - The Dbus path
          */
-        ItemUpdater(sdbusplus::bus::bus& bus) :
+        ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
+                    ItemUpdaterInherit(bus, path.c_str()),
                     busItem(bus),
                     versionMatch(
                             bus,
@@ -79,9 +78,12 @@
 
         /** @brief sdbusplus signal match for Software.Version */
         sdbusplus::server::match::match versionMatch;
+
+        /** @brief Host factory reset - clears PNOR partitions for each
+          * Activation dbus object */
+        void reset() override;
 };
 
 } // namespace updater
 } // namespace software
 } // namespace openpower
-
diff --git a/item_updater_main.cpp b/item_updater_main.cpp
index 0bf710b..c6f7dba 100755
--- a/item_updater_main.cpp
+++ b/item_updater_main.cpp
@@ -10,7 +10,7 @@
     // Add sdbusplus ObjectManager.
     sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
 
-    openpower::software::updater::ItemUpdater updater(bus);
+    openpower::software::updater::ItemUpdater updater(bus, SOFTWARE_OBJPATH);
 
     bus.request_name(BUSNAME_UPDATER);