watchdog: Collect hostboot dump when watchdog times out

The hostboot dump collection to be initiated by watchdog_timeout
is disabled by default. When watchdog times out, only error
message corresponding to watchdog timeout is logged. To enable
hostboot dump collection whenever watchdog times out, the meson
option 'hostboot-dump-collection' must be enabled.

Testing - with meson option 'hostboot-dump-collection' enabled:
Ran watchdog_timeout:
case-1: CurrentHostState - off, AutoReboot - false
- Verified PEL object was not created
- Verified hostboot dump was not created
- Verified the Host State changed to Quiesce

case-2: CurrentHostState - off, AutoReboot - true
- Verified PEL object was created
- Verified hostboot dump was not created
- Verified the Host State changed to Running

case-3: CurrentHostState - Running, AutoBoot - false
- Verified PEL object was not created
- Verified hostboot dump was not created
- Verified the Host State changed to Quiesce

case-4: CurrentHostState - Running, AutoBoot - true, default timeout = 300s
- Verified PEL object was created
- Verified hostboot dump was created
- Observed Host state moving to either Running or Quiesce

case-5: CurrentHostState - Running, AutoBoot - true, specified timeout = 5s
- Verified PEL object was created
- Verified hostboot dump was created
- Observed Host state moving to either Running or Quiesce

Docker Unit test: passed

Signed-off-by: Shantappa Teekappanavar <sbteeks@yahoo.com>
Change-Id: Ib92d0c2f282816fb742cf07c1cb876b2cc093c12
diff --git a/watchdog/watchdog_logging.cpp b/watchdog/watchdog_logging.cpp
new file mode 100644
index 0000000..7d5bdd9
--- /dev/null
+++ b/watchdog/watchdog_logging.cpp
@@ -0,0 +1,44 @@
+#include <unistd.h>
+
+#include <watchdog_dbus.hpp>
+#include <watchdog_handler.hpp>
+#include <watchdog_logging.hpp>
+
+namespace watchdog
+{
+namespace dump
+{
+
+/**
+ * @brief Log an event handled by the dump handler
+ *
+ * @param additional - Additional PEL data
+ * @param timeout - timeout interval in seconds
+ */
+void event(std::map<std::string, std::string>& additional,
+           const uint32_t timeout)
+{
+
+    std::string eventName = "org.open_power.Host.Boot.Error.WatchdogTimeout";
+
+    // CreatePELWithFFDCFiles requires a vector of FFDCTuple.
+    auto emptyFfdc = std::vector<FFDCTuple>{};
+
+    // Create PEL with additional data.
+    auto pelId = createPel(eventName, additional, emptyFfdc);
+
+    requestDump(pelId, timeout); // will not return until dump is complete
+}
+
+void eventWatchdogTimeout(const uint32_t timeout)
+{
+    // Additional data to be added to PEL object
+    // Currently we don't have anything to add
+    // Keeping this for now in case if we have to add
+    // any data corresponding to watchdog timeout
+    std::map<std::string, std::string> additionalData;
+    event(additionalData, timeout);
+}
+
+} // namespace dump
+} // namespace watchdog