Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <optional> |
| 4 | #include <ranges> |
| 5 | #include <string> |
| 6 | #include <unordered_map> |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace dump |
| 11 | { |
| 12 | // Overall dump category for example BMC dump |
| 13 | using DUMP_CATEGORY = std::string; |
| 14 | |
| 15 | // Dump type |
| 16 | using DUMP_TYPE = std::string; |
| 17 | |
| 18 | // Dump collection indicator |
| 19 | using DUMP_COLLECTION_TYPE = std::string; |
| 20 | |
| 21 | // Dump types |
| 22 | enum class DumpTypes |
| 23 | { |
| 24 | USER, |
| 25 | }; |
| 26 | |
| 27 | // A table of dump types |
| 28 | using DUMP_TYPE_TABLE = |
| 29 | std::unordered_map<DUMP_TYPE, std::pair<DumpTypes, DUMP_CATEGORY>>; |
| 30 | |
| 31 | // Mapping between dump type and dump collection type string |
| 32 | using DUMP_TYPE_TO_STRING_MAP = |
| 33 | std::unordered_map<DumpTypes, DUMP_COLLECTION_TYPE>; |
| 34 | |
| 35 | /** |
| 36 | * @brief Converts a DumpTypes enum value to dump name. |
| 37 | * |
| 38 | * @param[in] dumpType The DumpTypes value to be converted. |
| 39 | * @return Name of the dump as string, std::nullopt if not found. |
| 40 | */ |
| 41 | std::optional<std::string> dumpTypeToString(const DumpTypes& dumpType); |
| 42 | |
| 43 | /** |
| 44 | * @brief Converts dump name to its corresponding DumpTypes enum value. |
| 45 | * |
| 46 | * @param[in] str The string to be converted to a DumpTypes value. |
| 47 | * @return The DumpTypes value that corresponds to the name or std::nullopt if |
| 48 | * not found. |
| 49 | */ |
| 50 | std::optional<DumpTypes> stringToDumpType(const std::string& str); |
| 51 | |
| 52 | /** |
| 53 | * @brief Validates dump type and returns corresponding collection type |
| 54 | * |
| 55 | * This function checks the provided dump type against the specified category. |
| 56 | * If the dump type is empty, it defaults to "user". If the dump type does not |
| 57 | * exist or does not match with the specified category, it logs an error and |
| 58 | * throws an InvalidArgument exception. |
| 59 | * |
| 60 | * @param[in] type - The dump type to be validated. |
| 61 | * @param[in] category - The category to match against the dump type. |
| 62 | * |
| 63 | * @return The corresponding dump collection type if the dump type and category |
| 64 | * match an entry in the dumpTypeTable. If the type is empty or does not match |
| 65 | * any entry, it returns "user". |
| 66 | * |
| 67 | * @throws InvalidArgument - Thrown if the type does not match the specified |
| 68 | * category or does not exist in the table. |
| 69 | */ |
| 70 | DumpTypes validateDumpType(const std::string& type, |
| 71 | const std::string& category); |
| 72 | |
| 73 | } // namespace dump |
| 74 | } // namespace phosphor |