BMCDump: dump subtype input parameter support

The BMC dump is not accepting any parameters to specify the type of
dump or level of data to be collected. It was always creating a default
user-requested dump.

This commit allows for the specification of the dump type during the
dump creation process. A new table has been added in a new header file
which stores the valid dump types. When a new dump is requested, the
specified dump type is verified against this table. If no dump type is
mentioned, a user-requested BMC dump is created for backward
compatibility. If an invalid dump type is mentioned, an Invalid
Argument exception is thrown.

Tested:
- Create BMC dump with no arguments
- Create BMC dump with type as user
- Create a error log dump and make sure other types of dumps
  which is using internal interface is not impacted.
- Built with master and p10bmc

Change-Id: I79f68be6ac6892ac7754b7221db64c22330b1822
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/dump_utils.hpp b/dump_utils.hpp
index 6d39bef..01e4166 100644
--- a/dump_utils.hpp
+++ b/dump_utils.hpp
@@ -1,5 +1,6 @@
 #pragma once
 #include "dump_manager.hpp"
+#include "dump_types.hpp"
 
 #include <systemd/sd-event.h>
 #include <unistd.h>
@@ -300,5 +301,39 @@
     return (getHostState() == HostState::Quiesced);
 }
 
+/** @brief Extract the dump create parameters
+ *  @param[in] key - The name of the parameter
+ *  @param[in] params - The map of parameters passed as input
+ *
+ *  @return On success, a std::optional containing the value of the parameter
+ * (of type T). On failure (key not found in the map or the value is not of type
+ * T), returns an empty std::optional.
+ */
+template <typename T>
+T extractParameter(const std::string& key,
+                   phosphor::dump::DumpCreateParams& params)
+{
+    using InvalidArgument =
+        sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+    using Argument = xyz::openbmc_project::Common::InvalidArgument;
+
+    auto it = params.find(key);
+    if (it != params.end())
+    {
+        const auto& [foundKey, variantValue] = *it;
+        if (std::holds_alternative<T>(variantValue))
+        {
+            return std::get<T>(variantValue);
+        }
+        else
+        {
+            lg2::error("An invalid input passed for key: {KEY}", "KEY", key);
+            elog<InvalidArgument>(Argument::ARGUMENT_NAME(key.c_str()),
+                                  Argument::ARGUMENT_VALUE("INVALID INPUT"));
+        }
+    }
+    return T{};
+}
+
 } // namespace dump
 } // namespace phosphor