Use systemd targets to track host states

Change-Id: I5ab174d945c1dfb265a02f9095d3eaeb0ba562db
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index 515409e..597efa5 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -36,11 +36,17 @@
                     sdbusplus::xyz::openbmc_project::State::server::Host>(
                             bus, objPath, true),
                 bus(bus),
-                stateSignal(bus,
-                            "type='signal',member='GotoSystemState'",
-                            handleSysStateChange,
-                            this)
+                systemdSignals(bus,
+                               "type='signal',"
+                               "member='JobRemoved',"
+                               "path='/org/freedesktop/systemd1',"
+                               "interface='org.freedesktop.systemd1.Manager'",
+                                sysStateChangeSignal,
+                                this)
         {
+            // Enable systemd signals
+            subscribeToSystemdSignals();
+
             // Will throw exception on fail
             determineInitialState();
 
@@ -48,13 +54,6 @@
             this->emit_object_added();
         }
 
-        /**
-         * @brief Determine initial host state and set internally
-         *
-         * @return Will throw exceptions on failure
-         **/
-        void determineInitialState();
-
         /** @brief Set value of HostTransition */
         Transition requestedHostTransition(Transition value) override;
 
@@ -62,6 +61,22 @@
         HostState currentHostState(HostState value) override;
 
     private:
+        /**
+         * @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 Determine initial host state and set internally
+         *
+         * @return Will throw exceptions on failure
+         **/
+        void determineInitialState();
+
         /** @brief Execute the transition request
          *
          * This function assumes the state has been validated and the host
@@ -71,25 +86,36 @@
          */
         void executeTransition(Transition tranReq);
 
-        /** @brief Callback function on system state changes
+        /** @brief Callback function on systemd state changes
          *
-         *  Check if the state is relevant to the Host and if so, update
-         *  corresponding host object's state
+         * Will just do a call into the appropriate object for processing
          *
-         * @param[in] msg        - Data associated with subscribed signal
-         * @param[in] userData   - Pointer to this object instance
-         * @param[in] retError   - Return error data
+         * @param[in]  msg       - Data associated with subscribed signal
+         * @param[in]  userData  - Pointer to this object instance
+         * @param[out] retError  - Not used but required with signal API
          *
          */
-        static int handleSysStateChange(sd_bus_message* msg,
+        static int sysStateChangeSignal(sd_bus_message* msg,
                                         void* userData,
                                         sd_bus_error* retError);
 
+        /** @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
+         * @param[out] retError  - Not used but required with signal API
+         *
+         */
+        int sysStateChange(sd_bus_message* msg,
+                           sd_bus_error* retError);
+
         /** @brief Persistent sdbusplus DBus bus connection. */
         sdbusplus::bus::bus& bus;
 
-        /** @brief Used to subscribe to dbus system state changes */
-        sdbusplus::server::match::match stateSignal;
+        /** @brief Used to subscribe to dbus systemd signals **/
+        sdbusplus::server::match::match systemdSignals;
 };
 
 } // namespace manager