Activation: Start service files and wait for completion

In this commit, the BMC activation flow is implemented. When the user
starts an activation, two service files are called to create read-only
and read-write volumes. Once these service files are finished running,
activation is marked as complete.

Resolves openbmc/openbmc#1756

Change-Id: I3874c2d04a1a2b07eea4e34789ba5ece0ff6979c
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/activation.hpp b/activation.hpp
index 1807134..f550e37 100644
--- a/activation.hpp
+++ b/activation.hpp
@@ -19,6 +19,8 @@
 using RedundancyPriorityInherit = sdbusplus::server::object::object<
     sdbusplus::xyz::openbmc_project::Software::server::RedundancyPriority>;
 
+namespace sdbusRule = sdbusplus::bus::match::rules;
+
 class ItemUpdater;
 class Activation;
 class RedundancyPriority;
@@ -113,8 +115,19 @@
                    bus(bus),
                    path(path),
                    parent(parent),
-                   versionId(versionId)
+                   versionId(versionId),
+                   systemdSignals(
+                       bus,
+                       sdbusRule::type::signal() +
+                       sdbusRule::member("JobRemoved") +
+                       sdbusRule::path("/org/freedesktop/systemd1") +
+                       sdbusRule::interface(
+                               "org.freedesktop.systemd1.Manager"),
+                       std::bind(std::mem_fn(&Activation::unitStateChange),
+                               this, std::placeholders::_1))
         {
+            // Enable systemd signals
+            subscribeToSystemdSignals();
             // Set Properties.
             activation(activationStatus);
             // Emit deferred signal.
@@ -138,6 +151,25 @@
         RequestedActivations requestedActivation(RequestedActivations value)
                 override;
 
+        /** @brief Check if systemd state change is relevant to this object
+         *
+         * Instance specific interface to handle the detected systemd state
+         * change
+         *
+         * @param[in]  msg       - Data associated with subscribed signal
+         *
+         */
+        void unitStateChange(sdbusplus::message::message& msg);
+
+        /**
+         * @brief subscribe to the systemd signals
+         *
+         * This object needs to capture when it's systemd targets complete
+         * so it can keep it's state updated
+         *
+         */
+        void subscribeToSystemdSignals();
+
         /** @brief Persistent sdbusplus DBus bus connection */
         sdbusplus::bus::bus& bus;
 
@@ -155,6 +187,17 @@
 
         /** @brief Persistent RedundancyPriority dbus object */
         std::unique_ptr<RedundancyPriority> redundancyPriority;
+
+        /** @brief Used to subscribe to dbus systemd signals **/
+        sdbusplus::bus::match_t systemdSignals;
+
+        /** @brief Tracks whether the read-write volume has been created as
+         * part of the activation process. **/
+        bool rwVolumeCreated = false;
+
+        /** @brief Tracks whether the read-only volume has been created as
+         * part of the activation process. **/
+        bool roVolumeCreated = false;
 };
 
 } // namespace updater