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/error_monitors/err2_monitor.hpp b/include/error_monitors/err2_monitor.hpp
index 9477fa6..d6dd9a1 100644
--- a/include/error_monitors/err2_monitor.hpp
+++ b/include/error_monitors/err2_monitor.hpp
@@ -40,7 +40,7 @@
             [this](boost::system::error_code ec,
                    const std::variant<bool>& property) {
                 // Default to no reset after Crashdump
-                bool reset = false;
+                RecoveryType recovery = RecoveryType::noRecovery;
                 if (!ec)
                 {
                     const bool* resetPtr = std::get_if<bool>(&property);
@@ -48,12 +48,12 @@
                     {
                         std::cerr << "Unable to read reset on ERR2 value\n";
                     }
-                    else
+                    else if (*resetPtr)
                     {
-                        reset = *resetPtr;
+                        recovery = RecoveryType::warmReset;
                     }
                 }
-                startCrashdumpAndRecovery(conn, reset, "ERR2 Timeout");
+                startCrashdumpAndRecovery(conn, recovery, "ERR2 Timeout");
             },
             "xyz.openbmc_project.Settings",
             "/xyz/openbmc_project/control/processor_error_config",
diff --git a/include/error_monitors/ierr_monitor.hpp b/include/error_monitors/ierr_monitor.hpp
index 7fda1af..5babf50 100644
--- a/include/error_monitors/ierr_monitor.hpp
+++ b/include/error_monitors/ierr_monitor.hpp
@@ -368,7 +368,7 @@
             [this](boost::system::error_code ec,
                    const std::variant<bool>& property) {
                 // Default to no reset after Crashdump
-                bool reset = false;
+                RecoveryType recovery = RecoveryType::noRecovery;
                 if (!ec)
                 {
                     const bool* resetPtr = std::get_if<bool>(&property);
@@ -376,12 +376,12 @@
                     {
                         std::cerr << "Unable to read reset on CATERR value\n";
                     }
-                    else
+                    else if (*resetPtr)
                     {
-                        reset = *resetPtr;
+                        recovery = RecoveryType::warmReset;
                     }
                 }
-                startCrashdumpAndRecovery(conn, reset, "IERR");
+                startCrashdumpAndRecovery(conn, recovery, "IERR");
             },
             "xyz.openbmc_project.Settings",
             "/xyz/openbmc_project/control/processor_error_config",
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();
             });
     }