blob: fe5e4a1ff170102e3cb90ebabb031224ce3bd7bd [file] [log] [blame]
Zane Shelleya9b44342021-08-08 17:15:52 -05001#pragma once
2
3#include <analyzer/resolution.hpp>
4#include <hei_main.hpp>
5#include <nlohmann/json.hpp>
6
7#include <map>
8
9namespace analyzer
10{
11
12/**
13 * @brief Manages the RAS data files and resolves service actions required for
14 * error signatures.
15 */
16class 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 Shelley7698b302021-08-09 16:00:03 -050044
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 /**
57 * @brief Parses an action in the given data file and returns the
58 * corresponding resolution.
59 * @param i_data The parsed RAS data file associated with the signature's
60 * chip type.
61 * @param i_action The target action to parse from the given RAS data.
62 * @return A resolution (or nested resolutions) representing the given
63 * action.
64 * @note This function is called recursively because an action could
65 * reference another action. This function will maintain a stack of
66 * parsed actions and will assert that the same action cannot be
67 * parsed more than once in the recursion stack.
68 */
69 std::shared_ptr<Resolution> parseAction(const nlohmann::json& i_data,
70 const std::string& i_action);
71
72 /**
73 * @brief Returns a callout priority enum value for the given string.
74 * @param i_priority The priority string.
75 * @return A callout priority enum value.
76 */
Zane Shelleyc85716c2021-08-17 10:54:06 -050077 callout::Priority getPriority(const std::string& i_priority);
Zane Shelleya9b44342021-08-08 17:15:52 -050078};
79
80} // namespace analyzer