Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 1 | ## This file is a template.The comment below is emitted |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 2 | ## into the rendered file; feel free to edit this file. |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 3 | // !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!! |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 4 | #include "dump_types.hpp" |
| 5 | |
| 6 | #include <phosphor-logging/elog-errors.hpp> |
| 7 | #include <phosphor-logging/elog.hpp> |
| 8 | #include <phosphor-logging/lg2.hpp> |
| 9 | #include <xyz/openbmc_project/Common/error.hpp> |
| 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace dump |
| 14 | { |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 15 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 16 | DUMP_TYPE_TABLE dumpTypeTable = { |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 17 | % for item in DUMP_TYPE_TABLE: |
| 18 | % for key, values in item.items(): |
| 19 | {"${key}", {DumpTypes::${values[0].upper()}, "${values[1]}"}}, |
| 20 | % endfor |
| 21 | % endfor |
| 22 | }; |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 23 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 24 | <% |
| 25 | map_keys = set() |
| 26 | %> |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 27 | DUMP_TYPE_TO_STRING_MAP dumpTypeToStringMap = { |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 28 | % for item in DUMP_TYPE_TABLE: |
| 29 | % for key, values in item.items(): |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 30 | % if values[0].upper() not in map_keys: |
| 31 | {DumpTypes::${values[0].upper()}, "${values[0]}"}, |
| 32 | <% map_keys.add(values[0].upper()) %> |
| 33 | % endif |
Dhruvaraj Subhashchandran | c1f5ed6 | 2023-07-09 04:31:28 -0500 | [diff] [blame] | 34 | % endfor |
| 35 | % endfor |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 36 | % for key, values in ERROR_TYPE_DICT.items(): |
| 37 | % if key.upper() not in map_keys: |
| 38 | {DumpTypes::${key.upper()}, "${key}"}, |
| 39 | <% map_keys.add(key.upper()) %> |
| 40 | % endif |
| 41 | % endfor |
| 42 | }; |
| 43 | |
| 44 | const ErrorMap errorMap = { |
| 45 | % for key, errors in ERROR_TYPE_DICT.items(): |
| 46 | {"${key}", { |
| 47 | % for error in errors: |
| 48 | "${error}", |
| 49 | % endfor |
| 50 | }}, |
| 51 | % endfor |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 52 | }; |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 53 | |
| 54 | std::optional<std::string> dumpTypeToString(const DumpTypes& dumpType) |
| 55 | { |
| 56 | auto it = dumpTypeToStringMap.find(dumpType); |
| 57 | if (it != dumpTypeToStringMap.end()) |
| 58 | { |
| 59 | return it->second; |
| 60 | } |
| 61 | return std::nullopt; |
| 62 | } |
| 63 | |
| 64 | std::optional<DumpTypes> stringToDumpType(const std::string& str) |
| 65 | { |
| 66 | auto it = std::ranges::find_if(dumpTypeToStringMap, |
| 67 | [&str](const auto& pair) { |
| 68 | return pair.second == str; |
| 69 | }); |
| 70 | |
| 71 | if (it != dumpTypeToStringMap.end()) |
| 72 | { |
| 73 | return it->first; |
| 74 | } |
| 75 | return std::nullopt; |
| 76 | } |
| 77 | |
| 78 | DumpTypes validateDumpType(const std::string& type, const std::string& category) |
| 79 | { |
| 80 | using namespace phosphor::logging; |
| 81 | using InvalidArgument = |
| 82 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 83 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 84 | // Dump type user will be return if type is empty |
| 85 | DumpTypes dumpType = DumpTypes::USER; |
| 86 | if (type.empty()) |
| 87 | { |
| 88 | return dumpType; |
| 89 | } |
| 90 | |
| 91 | // Find any matching dump collection type for the category |
| 92 | auto it = std::find_if(dumpTypeTable.begin(), dumpTypeTable.end(), |
| 93 | [&](const auto& pair) { |
| 94 | return pair.first == type && pair.second.second == category; |
| 95 | }); |
| 96 | |
| 97 | if (it != dumpTypeTable.end()) |
| 98 | { |
| 99 | dumpType = it->second.first; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | lg2::error("An invalid dump type: {TYPE} passed", "TYPE", type); |
| 104 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("BMC_DUMP_TYPE"), |
| 105 | Argument::ARGUMENT_VALUE(type.c_str())); |
| 106 | } |
| 107 | return dumpType; |
| 108 | } |
| 109 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame] | 110 | bool isErrorTypeValid(const std::string& errorType) |
| 111 | { |
| 112 | const auto it = errorMap.find(errorType); |
| 113 | return it != errorMap.end(); |
| 114 | } |
| 115 | |
| 116 | std::optional<ErrorType> findErrorType(const std::string& errString) |
| 117 | { |
| 118 | for (const auto& [type, errorList] : errorMap) |
| 119 | { |
| 120 | auto error = std::find(errorList.begin(), errorList.end(), errString); |
| 121 | if (error != errorList.end()) |
| 122 | { |
| 123 | return type; |
| 124 | } |
| 125 | } |
| 126 | return std::nullopt; |
| 127 | } |
| 128 | |
Dhruvaraj Subhashchandran | 3604710 | 2023-06-29 03:46:25 -0500 | [diff] [blame] | 129 | } // namespace dump |
| 130 | } // namespace phosphor |