Refactor: Split item_updater to common and ubi

The existing item_updater is highly coupled with ubifs.
It will support static layout and ubi in future.
So split the functions in to common ones and ubi specific ones, and move
the ubi specific code in ubi dir.

1. Keep common functions and make them virtual for extension.
    createActiveAssociation()
    updateFunctionalAssociation()
    removeAssociation()
    erase()
2. Create ubi/item_updater_ubi and move other functions into it.
3. Change updateFunctionalAssociation() parameter for future use.

To support static layout, a new item_updater_static will be written.

Tested: On the last commit of the patch series, run code update and
        factory reset on Witherspoon and all work fine.

Change-Id: I4cc55b31ee3f37c5b27168611305dee8ce02880a
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/ubi/item_updater_ubi.hpp b/ubi/item_updater_ubi.hpp
new file mode 100644
index 0000000..af330a8
--- /dev/null
+++ b/ubi/item_updater_ubi.hpp
@@ -0,0 +1,85 @@
+#pragma once
+
+#include "item_updater.hpp"
+
+namespace openpower
+{
+namespace software
+{
+namespace updater
+{
+
+/** @class ItemUpdaterUbi
+ *  @brief Manages the activation of the host version items for ubi layout
+ */
+class ItemUpdaterUbi : public ItemUpdater
+{
+  public:
+    ItemUpdaterUbi(sdbusplus::bus::bus& bus, const std::string& path) :
+        ItemUpdater(bus, path)
+    {
+        processPNORImage();
+        gardReset = std::make_unique<GardReset>(bus, GARD_PATH);
+        volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath);
+
+        // Emit deferred signal.
+        emit_object_added();
+    }
+    virtual ~ItemUpdaterUbi() = default;
+
+    void freePriority(uint8_t value, const std::string& versionId) override;
+
+    bool isLowestPriority(uint8_t value) override;
+
+    void processPNORImage() override;
+
+    bool erase(std::string entryId) override;
+
+    void deleteAll() override;
+
+    void freeSpace() override;
+
+    bool isVersionFunctional(const std::string& versionId) override;
+
+  private:
+    /** @brief Callback function for Software.Version match.
+     *  @details Creates an Activation D-Bus object.
+     *
+     * @param[in]  msg       - Data associated with subscribed signal
+     */
+    void createActivation(sdbusplus::message::message& msg) override;
+
+    /** @brief Host factory reset - clears PNOR partitions for each
+     * Activation D-Bus object */
+    void reset() override;
+
+    /**
+     * @brief Validates the presence of SquashFS image in the image dir.
+     *
+     * @param[in]  filePath - The path to the SquashFS image.
+     * @param[out] result    - 0 --> if validation was successful
+     *                       - -1--> Otherwise
+     */
+    static int validateSquashFSImage(const std::string& filePath);
+
+    /** @brief Clears read only PNOR partition for
+     *  given Activation D-Bus object
+     *
+     * @param[in]  versionId - The id of the ro partition to remove.
+     */
+    void removeReadOnlyPartition(std::string versionId);
+
+    /** @brief Clears read write PNOR partition for
+     *  given Activation D-Bus object
+     *
+     *  @param[in]  versionId - The id of the rw partition to remove.
+     */
+    void removeReadWritePartition(std::string versionId);
+
+    /** @brief Clears preserved PNOR partition */
+    void removePreservedPartition();
+};
+
+} // namespace updater
+} // namespace software
+} // namespace openpower