Use an enum to specify the type of recovery to perform

Different error types may require a different type of recovery, so
rather than setting a single recovery type, this adds an enum to let
each error monitor specify the type of recovery to perform.

Tested:
Set a different type of recovery for the err2 and ierr monitors and
confirmed that the correct recovery was performed.

Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Change-Id: I831c70f71b9bbad4d99b6e5db31067e87e5711f8
diff --git a/include/host_error_monitor.hpp b/include/host_error_monitor.hpp
index eacb1cb..c4652d0 100644
--- a/include/host_error_monitor.hpp
+++ b/include/host_error_monitor.hpp
@@ -64,13 +64,41 @@
             "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"});
 }
 
+enum class RecoveryType
+{
+    noRecovery,
+    powerCycle,
+    warmReset,
+};
+
+static inline void
+    handleRecovery(RecoveryType recovery, boost::asio::io_context& io,
+                   std::shared_ptr<sdbusplus::asio::connection> conn)
+{
+    switch (recovery)
+    {
+        case RecoveryType::noRecovery:
+            std::cerr << "Recovery is disabled. Leaving the system "
+                         "in the failed state.\n";
+            break;
+        case RecoveryType::powerCycle:
+            std::cerr << "Recovering the system with a power cycle\n";
+            startPowerCycle(conn);
+            break;
+        case RecoveryType::warmReset:
+            std::cerr << "Recovering the system with a warm reset\n";
+            startWarmReset(conn);
+            break;
+    }
+}
+
 void startCrashdumpAndRecovery(
-    std::shared_ptr<sdbusplus::asio::connection> conn, bool recoverSystem,
-    const std::string& triggerType)
+    std::shared_ptr<sdbusplus::asio::connection> conn,
+    RecoveryType requestedRecovery, const std::string& triggerType)
 {
 #ifdef CRASHDUMP
-    static bool recover;
-    recover = recoverSystem;
+    static RecoveryType recovery;
+    recovery = requestedRecovery;
     std::cerr << "Starting crashdump\n";
     static std::shared_ptr<sdbusplus::bus::match::match> crashdumpCompleteMatch;
 
@@ -82,11 +110,7 @@
             "CrashdumpComplete'",
             [conn](sdbusplus::message::message& msg) {
                 std::cerr << "Crashdump completed\n";
-                if (recover)
-                {
-                    std::cerr << "Recovering the system\n";
-                    startWarmReset(conn);
-                }
+                handleRecovery(recovery, io, conn);
                 crashdumpCompleteMatch.reset();
             });
     }