PEL: Fill in host state change callback

If the host is up, start sending PELs.

If the host is off, move all of the PELs that are sent but
not acked back to the queue to be sent again next time.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I66d382a85afc88f6b23367fb515df4dbe5326be1
diff --git a/extensions/openpower-pels/host_notifier.cpp b/extensions/openpower-pels/host_notifier.cpp
index b935f7e..f9e0418 100644
--- a/extensions/openpower-pels/host_notifier.cpp
+++ b/extensions/openpower-pels/host_notifier.cpp
@@ -128,6 +128,26 @@
 
 void HostNotifier::hostStateChange(bool hostUp)
 {
+    _retryCount = 0;
+
+    if (hostUp && !_pelQueue.empty())
+    {
+        doNewLogNotify();
+    }
+    else if (!hostUp)
+    {
+        stopCommand();
+
+        // Reset the state on any PELs that were sent but not acked back
+        // to new so they'll get sent again.
+        for (auto id : _sentPELs)
+        {
+            _pelQueue.push_back(id);
+            _repo.setPELHostTransState(id, TransmissionState::newPEL);
+        }
+
+        _sentPELs.clear();
+    }
 }
 
 void HostNotifier::commandResponse(ResponseStatus status)
@@ -169,4 +189,25 @@
     }
 }
 
+void HostNotifier::stopCommand()
+{
+    _retryCount = 0;
+
+    if (_inProgressPEL != 0)
+    {
+        _pelQueue.push_front(_inProgressPEL);
+        _inProgressPEL = 0;
+    }
+
+    if (_retryTimer.isEnabled())
+    {
+        _retryTimer.setEnabled(false);
+    }
+
+    if (_hostIface->cmdInProgress())
+    {
+        _hostIface->cancelCmd();
+    }
+}
+
 } // namespace openpower::pels
diff --git a/extensions/openpower-pels/host_notifier.hpp b/extensions/openpower-pels/host_notifier.hpp
index 8436e06..1bb7538 100644
--- a/extensions/openpower-pels/host_notifier.hpp
+++ b/extensions/openpower-pels/host_notifier.hpp
@@ -96,6 +96,11 @@
     /**
      * @brief Called when the host changes state.
      *
+     * If the new state is host up and there are PELs to send, it
+     * will trigger the first command.  If the new state is off, then
+     * it will transfer any PELs that were sent but not acked yet back
+     * to the queue to be sent again.
+     *
      * @param[in] hostUp - The new host state
      */
     void hostStateChange(bool hostUp);
@@ -124,6 +129,13 @@
     void retryTimerExpired();
 
     /**
+     * @brief Stops an in progress command
+     *
+     * In progress meaning after the send but before the response.
+     */
+    void stopCommand();
+
+    /**
      * @brief The PEL repository object
      */
     Repository& _repo;