mainapp: Add an option for watching post codes

We have some machines that use an IPMI watchdog, but can sometimes take
so long to reboot that the watchdog ends up tripping during the boot
process. Unfortunately the boot firmware has no method of talking IPMI
to pet the watchdog, but does emit post codes during the boot up process
when it makes forward progress.

This change adds a flag to instruct the watchdog that it should reset
the TimeRemaining on the watchdog any time new post codes are seen from
the host.

Tested:
    Verified that post codes signals were received during
    the boot process and the watchdog TimeRemaining was updated
    accordingly.

Change-Id: Ie0616f0fe4ee6601f9afdc4eba71f34968780794
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/mainapp.cpp b/mainapp.cpp
index b8c84c9..35ef255 100644
--- a/mainapp.cpp
+++ b/mainapp.cpp
@@ -17,6 +17,7 @@
 #include "watchdog.hpp"
 
 #include <CLI/CLI.hpp>
+#include <functional>
 #include <iostream>
 #include <optional>
 #include <phosphor-logging/elog-errors.hpp>
@@ -123,6 +124,12 @@
         ->needs(fallbackActionOpt)
         ->needs(fallbackIntervalOpt);
 
+    // Should we watch for postcodes
+    bool watchPostcodes;
+    app.add_flag("-w,--watch_postcodes", watchPostcodes,
+                 "Should we reset the time remaining any time a postcode "
+                 "is signaled.");
+
     CLI11_PARSE(app, argc, argv);
 
     // Put together a list of actions and associated systemd targets
@@ -213,6 +220,18 @@
         Watchdog watchdog(bus, path.c_str(), event, std::move(actionTargetMap),
                           std::move(maybeFallback));
 
+        std::optional<sdbusplus::bus::match::match> watchPostcodeMatch;
+        if (watchPostcodes)
+        {
+            watchPostcodeMatch.emplace(
+                bus,
+                sdbusplus::bus::match::rules::propertiesChanged(
+                    "/xyz/openbmc_project/state/boot/raw",
+                    "xyz.openbmc_project.State.Boot.Raw"),
+                std::bind(&Watchdog::resetTimeRemaining, std::ref(watchdog),
+                          false));
+        }
+
         // Claim the bus
         bus.request_name(service.c_str());