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/item_updater.hpp b/item_updater.hpp
index 1dc0868..96ef29c 100644
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -89,14 +89,10 @@
std::bind(std::mem_fn(&ItemUpdater::createActivation),
this, std::placeholders::_1))
{
- processPNORImage();
- gardReset = std::make_unique<GardReset>(bus, GARD_PATH);
- volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath);
-
- // Emit deferred signal.
- emit_object_added();
}
+ virtual ~ItemUpdater() = default;
+
/** @brief Sets the given priority free by incrementing
* any existing priority with the same value by 1
*
@@ -105,7 +101,7 @@
* are trying to free up the priority.
* @return None
*/
- void freePriority(uint8_t value, const std::string& versionId);
+ virtual void freePriority(uint8_t value, const std::string& versionId) = 0;
/** @brief Determine is the given priority is the lowest
*
@@ -114,25 +110,25 @@
* @return boolean corresponding to whether the given
* priority is lowest.
*/
- bool isLowestPriority(uint8_t value);
+ virtual bool isLowestPriority(uint8_t value) = 0;
/**
* @brief Create and populate the active PNOR Version.
*/
- void processPNORImage();
+ virtual void processPNORImage() = 0;
/** @brief Deletes version
*
* @param[in] entryId - Id of the version to delete
*
- * @return None
+ * @return - Returns true if the version is deleted.
*/
- void erase(std::string entryId);
+ virtual bool erase(std::string entryId);
/**
* @brief Erases any non-active pnor versions.
*/
- void deleteAll();
+ virtual void deleteAll() = 0;
/** @brief Brings the total number of active PNOR versions to
* ACTIVE_PNOR_MAX_ALLOWED -1. This function is intended to be
@@ -141,7 +137,7 @@
* version(s) with the highest priority, skipping the
* functional PNOR version.
*/
- void freeSpace();
+ virtual void freeSpace() = 0;
/** @brief Determine the software version id
* from the symlink target (e.g. /media/ro-2a1022fe).
@@ -156,20 +152,20 @@
*
* @param[in] path - The path to create the association to.
*/
- void createActiveAssociation(const std::string& path);
+ virtual void createActiveAssociation(const std::string& path);
/** @brief Updates the functional association to the
* new "running" PNOR image
*
- * @param[in] path - The path to update the association to.
+ * @param[in] versionId - The id of the image to update the association to.
*/
- void updateFunctionalAssociation(const std::string& path);
+ virtual void updateFunctionalAssociation(const std::string& versionId);
/** @brief Removes the associations from the provided software image path
*
* @param[in] path - The path to remove the association from.
*/
- void removeAssociation(const std::string& path);
+ virtual void removeAssociation(const std::string& path);
/** @brief Persistent GardReset dbus object */
std::unique_ptr<GardReset> gardReset;
@@ -180,27 +176,18 @@
*
* @return - Returns true if this version is currently functional.
*/
- static bool isVersionFunctional(const std::string& versionId);
+ virtual bool isVersionFunctional(const std::string& versionId) = 0;
/** @brief Persistent ObjectEnable D-Bus object */
std::unique_ptr<ObjectEnable> volatileEnable;
- private:
+ protected:
/** @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);
-
- /**
- * @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);
+ virtual void createActivation(sdbusplus::message::message& msg) = 0;
/** @brief Persistent sdbusplus D-Bus bus connection. */
sdbusplus::bus::bus& bus;
@@ -219,26 +206,9 @@
/** @brief This entry's associations */
AssociationList assocs = {};
- /** @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();
-
/** @brief Host factory reset - clears PNOR partitions for each
* Activation D-Bus object */
- void reset() override;
+ void reset() override = 0;
/** @brief Check whether the host is running
*