Add a DBus property to specify the IERR timeout

IERR timeout can be short to get initial crash data or can be
much longer for more data as additional cores crash.  This
change adds a DBus property that allows configuring the IERR
timeout for the level of data desired.

The timeout can be configured up to 10 minutes.

Tested:
Modified the DBus property and confirmed that it was updated.
Attempted a timeout larger than 10 minutes and confirmed that it
was rejected.

Change-Id: I2c743e00c3a203a792d6d0e53c2e1b6126afcaf7
Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
diff --git a/src/host_error_monitor.cpp b/src/host_error_monitor.cpp
index a163f66..0172ca2 100644
--- a/src/host_error_monitor.cpp
+++ b/src/host_error_monitor.cpp
@@ -27,10 +27,12 @@
 {
 static boost::asio::io_service io;
 static std::shared_ptr<sdbusplus::asio::connection> conn;
+static std::shared_ptr<sdbusplus::asio::dbus_interface> hostErrorTimeoutIface;
 
 static bool hostOff = true;
 
-const static constexpr size_t caterrTimeoutMs = 2000;
+static size_t caterrTimeoutMs = 2000;
+const static constexpr size_t caterrTimeoutMsMax = 600000; // 10 minutes maximum
 const static constexpr size_t errTimeoutMs = 90000;
 const static constexpr size_t smiTimeoutMs = 90000;
 const static constexpr size_t crashdumpTimeoutS = 300;
@@ -1392,12 +1394,35 @@
     host_error_monitor::conn =
         std::make_shared<sdbusplus::asio::connection>(host_error_monitor::io);
 
-    // Host Error Monitor Object
+    // Host Error Monitor Service
     host_error_monitor::conn->request_name(
         "xyz.openbmc_project.HostErrorMonitor");
     sdbusplus::asio::object_server server =
         sdbusplus::asio::object_server(host_error_monitor::conn);
 
+    // Restart Cause Interface
+    host_error_monitor::hostErrorTimeoutIface =
+        server.add_interface("/xyz/openbmc_project/host_error_monitor",
+                             "xyz.openbmc_project.HostErrorMonitor.Timeout");
+
+    host_error_monitor::hostErrorTimeoutIface->register_property(
+        "IERRTimeoutMs", host_error_monitor::caterrTimeoutMs,
+        [](const std::size_t& requested, std::size_t& resp) {
+            if (requested > host_error_monitor::caterrTimeoutMsMax)
+            {
+                std::cerr << "IERRTimeoutMs update to " << requested
+                          << "ms rejected. Cannot be greater than "
+                          << host_error_monitor::caterrTimeoutMsMax << "ms.\n";
+                return 0;
+            }
+            std::cerr << "IERRTimeoutMs updated to " << requested << "ms\n";
+            host_error_monitor::caterrTimeoutMs = requested;
+            resp = requested;
+            return 1;
+        },
+        [](std::size_t& resp) { return host_error_monitor::caterrTimeoutMs; });
+    host_error_monitor::hostErrorTimeoutIface->initialize();
+
     // Start tracking host state
     std::shared_ptr<sdbusplus::bus::match::match> hostStateMonitor =
         host_error_monitor::startHostStateMonitor();