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.

Change-Id: I79f68be6ac6892ac7754b7221db64c22330b1822
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/dump_utils.hpp b/dump_utils.hpp
index 6d39bef..c3d9d36 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,60 @@
     return (getHostState() == HostState::Quiesced);
 }
 
+/**
+ * @brief Validates dump type and returns corresponding collection type
+ *
+ * This function checks the provided dump type against the specified category.
+ * If the dump type is empty, it defaults to "user". If the dump type does not
+ * exist or does not match with the specified category, it logs an error and
+ * throws an InvalidArgument exception.
+ *
+ * @param[in] type - The dump type to be validated.
+ * @param[in] category - The category to match against the dump type.
+ *
+ * @return The corresponding dump collection type if the dump type and category
+ * match an entry in the dumpTypeTable. If the type is empty or does not match
+ * any entry, it returns "user".
+ *
+ * @throws InvalidArgument - Thrown if the type does not match the specified
+ * category or does not exist in the table.
+ */
+DumpTypes validateDumpType(const std::string& type,
+                           const std::string& category);
+
+/** @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