activation: Move out code that monitors for ubi services

Move the code that monitors for ubi services into the ubi
subdirectory. Other filesystem layouts can just ignore
the service monitoring by setting the *VolumeCreated
variables to true.

Tested: Verified code update on Witherspoon still worked.

Change-Id: I135e66225d0e8d692d430efd864252b822b069db
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index b81a7e2..b64f1be 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -209,51 +209,7 @@
         return;
     }
 
-    uint32_t newStateID{};
-    sdbusplus::message::object_path newStateObjPath;
-    std::string newStateUnit{};
-    std::string newStateResult{};
-
-    // Read the msg and populate each variable
-    msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
-
-    auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
-    auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
-    auto ubootVarsServiceFile =
-        "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
-
-    if (newStateUnit == rwServiceFile && newStateResult == "done")
-    {
-        rwVolumeCreated = true;
-        activationProgress->progress(activationProgress->progress() + 20);
-    }
-
-    if (newStateUnit == roServiceFile && newStateResult == "done")
-    {
-        roVolumeCreated = true;
-        activationProgress->progress(activationProgress->progress() + 50);
-    }
-
-    if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
-    {
-        ubootEnvVarsUpdated = true;
-    }
-
-    if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile ||
-        newStateUnit == ubootVarsServiceFile)
-    {
-        if (newStateResult == "failed" || newStateResult == "dependency")
-        {
-            Activation::activation(
-                softwareServer::Activation::Activations::Failed);
-        }
-        else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created
-                 (ubootEnvVarsUpdated)) // Environment variables were updated
-        {
-            Activation::activation(
-                softwareServer::Activation::Activations::Activating);
-        }
-    }
+    onStateChanges(msg);
 
     return;
 }
diff --git a/activation.hpp b/activation.hpp
index 55377b1..9315fc8 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -249,6 +249,9 @@
     /** @brief Overloaded write flash function */
     void flashWrite() override;
 
+    /** @brief Overloaded function that acts on service file state changes */
+    void onStateChanges(sdbusplus::message::message&) override;
+
     /** @brief Check if systemd state change is relevant to this object
      *
      * Instance specific interface to handle the detected systemd state
diff --git a/flash.hpp b/flash.hpp
index 470d99c..5069680 100644
--- a/flash.hpp
+++ b/flash.hpp
@@ -22,6 +22,11 @@
      * @brief Writes the image file(s) to flash
      */
     virtual void flashWrite() = 0;
+
+    /**
+     * @brief Takes action when the state of the activation service file changes
+     */
+    virtual void onStateChanges(sdbusplus::message::message& msg) = 0;
 };
 
 } // namespace updater
diff --git a/ubi/flash.cpp b/ubi/flash.cpp
index 39015bd..8986a07 100644
--- a/ubi/flash.cpp
+++ b/ubi/flash.cpp
@@ -8,6 +8,8 @@
 namespace updater
 {
 
+namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
+
 void Activation::flashWrite()
 {
     auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
@@ -24,6 +26,57 @@
     return;
 }
 
+void Activation::onStateChanges(sdbusplus::message::message& msg)
+{
+    uint32_t newStateID{};
+    sdbusplus::message::object_path newStateObjPath;
+    std::string newStateUnit{};
+    std::string newStateResult{};
+
+    // Read the msg and populate each variable
+    msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
+
+    auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
+    auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
+    auto ubootVarsServiceFile =
+        "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
+
+    if (newStateUnit == rwServiceFile && newStateResult == "done")
+    {
+        rwVolumeCreated = true;
+        activationProgress->progress(activationProgress->progress() + 20);
+    }
+
+    if (newStateUnit == roServiceFile && newStateResult == "done")
+    {
+        roVolumeCreated = true;
+        activationProgress->progress(activationProgress->progress() + 50);
+    }
+
+    if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
+    {
+        ubootEnvVarsUpdated = true;
+    }
+
+    if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile ||
+        newStateUnit == ubootVarsServiceFile)
+    {
+        if (newStateResult == "failed" || newStateResult == "dependency")
+        {
+            Activation::activation(
+                softwareServer::Activation::Activations::Failed);
+        }
+        else if ((rwVolumeCreated && roVolumeCreated) || // Volumes were created
+                 (ubootEnvVarsUpdated)) // Environment variables were updated
+        {
+            Activation::activation(
+                softwareServer::Activation::Activations::Activating);
+        }
+    }
+
+    return;
+}
+
 } // namespace updater
 } // namespace software
 } // namepsace phosphor