Zane Shelley | a9b4434 | 2021-08-08 17:15:52 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <analyzer/resolution.hpp> |
| 4 | #include <hei_main.hpp> |
| 5 | #include <nlohmann/json.hpp> |
| 6 | |
| 7 | #include <map> |
| 8 | |
| 9 | namespace analyzer |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @brief Manages the RAS data files and resolves service actions required for |
| 14 | * error signatures. |
| 15 | */ |
| 16 | class RasDataParser |
| 17 | { |
| 18 | public: |
| 19 | /** @brief Default constructor. */ |
| 20 | RasDataParser() |
| 21 | { |
| 22 | initDataFiles(); |
| 23 | } |
| 24 | |
| 25 | private: |
| 26 | /** @brief The RAS data files. */ |
| 27 | std::map<libhei::ChipType_t, nlohmann::json> iv_dataFiles; |
| 28 | |
| 29 | public: |
| 30 | /** |
| 31 | * @brief Returns a resolution for all the RAS actions needed for the given |
| 32 | * signature. |
| 33 | * @param i_signature The target error signature. |
| 34 | */ |
| 35 | std::shared_ptr<Resolution> |
| 36 | getResolution(const libhei::Signature& i_signature); |
| 37 | |
| 38 | private: |
| 39 | /** |
| 40 | * @brief Parses all of the RAS data JSON files and validates them against |
| 41 | * the associated schema. |
| 42 | */ |
| 43 | void initDataFiles(); |
Zane Shelley | 7698b30 | 2021-08-09 16:00:03 -0500 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * @brief Parses a signature in the given data file and returns a string |
| 47 | * representing the target action for the signature. |
| 48 | * @param i_data The parsed RAS data file associated with the |
| 49 | * signature's chip type. |
| 50 | * @param i_signature The target signature. |
| 51 | * @return A string representing the target action for the signature. |
| 52 | */ |
| 53 | std::string parseSignature(const nlohmann::json& i_data, |
| 54 | const libhei::Signature& i_signature); |
| 55 | |
| 56 | /** |
Zane Shelley | 5d63cef | 2021-09-17 18:10:17 -0500 | [diff] [blame] | 57 | * @brief Parses a bus object in the given data file and returns the bus |
| 58 | * type and unit path. |
| 59 | * @param i_data The parsed RAS data file associated with the signature's |
| 60 | * chip type. |
| 61 | * @param i_name The name of the target bus. |
| 62 | * @return A tuple containing the bus type and unit path. |
| 63 | */ |
| 64 | std::tuple<callout::BusType, std::string> |
| 65 | parseBus(const nlohmann::json& i_data, const std::string& i_name); |
| 66 | |
| 67 | /** |
Zane Shelley | 7698b30 | 2021-08-09 16:00:03 -0500 | [diff] [blame] | 68 | * @brief Parses an action in the given data file and returns the |
| 69 | * corresponding resolution. |
| 70 | * @param i_data The parsed RAS data file associated with the signature's |
| 71 | * chip type. |
| 72 | * @param i_action The target action to parse from the given RAS data. |
| 73 | * @return A resolution (or nested resolutions) representing the given |
| 74 | * action. |
| 75 | * @note This function is called recursively because an action could |
| 76 | * reference another action. This function will maintain a stack of |
| 77 | * parsed actions and will assert that the same action cannot be |
| 78 | * parsed more than once in the recursion stack. |
| 79 | */ |
| 80 | std::shared_ptr<Resolution> parseAction(const nlohmann::json& i_data, |
| 81 | const std::string& i_action); |
| 82 | |
| 83 | /** |
| 84 | * @brief Returns a callout priority enum value for the given string. |
| 85 | * @param i_priority The priority string. |
| 86 | * @return A callout priority enum value. |
| 87 | */ |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 88 | callout::Priority getPriority(const std::string& i_priority); |
Zane Shelley | a9b4434 | 2021-08-08 17:15:52 -0500 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace analyzer |