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 !!!
4 #pragma once
5 
6 #include <optional>
7 #include <ranges>
8 #include <string>
9 #include <unordered_map>
10 #include <vector>
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 
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 
30 // Dump types
31 <% enum_values = set() %>
32 enum class DumpTypes {
33 % for item in DUMP_TYPE_TABLE:
34   % for key, values in item.items():
35     % if values[0].upper() not in enum_values:
36         ${values[0].upper()},
37         <% enum_values.add(values[0].upper()) %>
38     % endif
39   % endfor
40 % endfor
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
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 
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 
122 } // namespace dump
123 } // namespace phosphor
124