Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 1 | ## This file is a template. The comment below is emitted |
| 2 | ## into the rendered file; feel free to edit this file. |
| 3 | // !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!! |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 4 | #pragma once |
| 5 | |
| 6 | #include <optional> |
| 7 | #include <ranges> |
| 8 | #include <string> |
| 9 | #include <unordered_map> |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 10 | #include <vector> |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace dump |
| 15 | { |
| 16 | // Overall dump category for example BMC dump |
| 17 | using DUMP_CATEGORY = std::string; |
| 18 | |
| 19 | // Dump type |
| 20 | using DUMP_TYPE = std::string; |
| 21 | |
| 22 | // Dump collection indicator |
| 23 | using DUMP_COLLECTION_TYPE = std::string; |
| 24 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 25 | using ErrorType = std::string; |
| 26 | using Error = std::string; |
| 27 | using ErrorList = std::vector<Error>; |
| 28 | using ErrorMap = std::unordered_map<ErrorType, ErrorList>; |
| 29 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 30 | // Dump types |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 31 | <% enum_values = set() %> |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 32 | enum class DumpTypes { |
| 33 | % for item in DUMP_TYPE_TABLE: |
| 34 | % for key, values in item.items(): |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 35 | % if values[0].upper() not in enum_values: |
| 36 | ${values[0].upper()}, |
| 37 | <% enum_values.add(values[0].upper()) %> |
| 38 | % endif |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 39 | % endfor |
| 40 | % endfor |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 41 | % for key in ERROR_TYPE_DICT: |
| 42 | % if key.upper() not in enum_values: |
| 43 | ${key.upper()}, |
| 44 | <% enum_values.add(key.upper()) %> |
| 45 | % endif |
| 46 | % endfor |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | // A table of dump types |
| 50 | using DUMP_TYPE_TABLE = |
| 51 | std::unordered_map<DUMP_TYPE, std::pair<DumpTypes, DUMP_CATEGORY>>; |
| 52 | |
| 53 | // Mapping between dump type and dump collection type string |
| 54 | using DUMP_TYPE_TO_STRING_MAP = |
| 55 | std::unordered_map<DumpTypes, DUMP_COLLECTION_TYPE>; |
| 56 | |
| 57 | /** |
| 58 | * @brief Converts a DumpTypes enum value to dump name. |
| 59 | * |
| 60 | * @param[in] dumpType The DumpTypes value to be converted. |
| 61 | * @return Name of the dump as string, std::nullopt if not found. |
| 62 | */ |
| 63 | std::optional<std::string> dumpTypeToString(const DumpTypes& dumpType); |
| 64 | |
| 65 | /** |
| 66 | * @brief Converts dump name to its corresponding DumpTypes enum value. |
| 67 | * |
| 68 | * @param[in] str The string to be converted to a DumpTypes value. |
| 69 | * @return The DumpTypes value that corresponds to the name or std::nullopt if |
| 70 | * not found. |
| 71 | */ |
| 72 | std::optional<DumpTypes> stringToDumpType(const std::string& str); |
| 73 | |
| 74 | /** |
| 75 | * @brief Validates dump type and returns corresponding collection type |
| 76 | * |
| 77 | * This function checks the provided dump type against the specified category. |
| 78 | * If the dump type is empty, it defaults to "user". If the dump type does not |
| 79 | * exist or does not match with the specified category, it logs an error and |
| 80 | * throws an InvalidArgument exception. |
| 81 | * |
| 82 | * @param[in] type - The dump type to be validated. |
| 83 | * @param[in] category - The category to match against the dump type. |
| 84 | * |
| 85 | * @return The corresponding dump collection type if the dump type and category |
| 86 | * match an entry in the dumpTypeTable. If the type is empty or does not match |
| 87 | * any entry, it returns "user". |
| 88 | * |
| 89 | * @throws InvalidArgument - Thrown if the type does not match the specified |
| 90 | * category or does not exist in the table. |
| 91 | */ |
| 92 | DumpTypes validateDumpType(const std::string& type, |
| 93 | const std::string& category); |
| 94 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 95 | /** |
| 96 | * @brief Checks if the provided error type is valid. |
| 97 | * |
| 98 | * This function verifies the validity of the error type by checking if it |
| 99 | * exists in the error map. |
| 100 | * |
| 101 | * @param[in] errorType - The string representation of the error type to |
| 102 | * validate. |
| 103 | * |
| 104 | * @return True if the error type exists in the error map, False otherwise. |
| 105 | */ |
| 106 | bool isErrorTypeValid(const std::string& errorType); |
| 107 | |
| 108 | /** |
| 109 | * @brief Finds the error type based on the provided error string. |
| 110 | * |
| 111 | * This function searches the error map for the provided error string. |
| 112 | * If it finds the string in the list of errors for a specific error type, |
| 113 | * it returns that error type. |
| 114 | * |
| 115 | * @param[in] errString - The string representation of the error to search for. |
| 116 | * |
| 117 | * @return An optional containing the error type if found. If the error string |
| 118 | * is not found in the map, returns an empty optional. |
| 119 | */ |
| 120 | std::optional<ErrorType> findErrorType(const std::string& errString); |
| 121 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 122 | } // namespace dump |
| 123 | } // namespace phosphor |