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/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