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  * @brief Manages the RAS data files and resolves service actions required for
13  *        error signatures.
14  */
15 class RasDataParser
16 {
17   public:
18     /** @brief Default constructor. */
RasDataParser()19     RasDataParser()
20     {
21         initDataFiles();
22     }
23 
24     /** Define all RAS data flags that may be associated with a signature */
25     enum RasDataFlags
26     {
27         SUE_SOURCE,
28         SUE_SEEN,
29         CS_POSSIBLE,
30         RECOVERED_ERROR,
31         INFORMATIONAL_ONLY,
32         MNFG_INFORMATIONAL_ONLY,
33         MASK_BUT_DONT_CLEAR,
34         CRC_RELATED_ERR,
35         CRC_ROOT_CAUSE,
36         ODP_DATA_CORRUPT_SIDE_EFFECT,
37         ODP_DATA_CORRUPT_ROOT_CAUSE,
38         ATTN_FROM_OCMB,
39     };
40 
41   private:
42     /** @brief The RAS data files. */
43     std::map<libhei::ChipType_t, nlohmann::json> iv_dataFiles;
44 
45   public:
46     /**
47      * @brief Returns a resolution for all the RAS actions needed for the given
48      *        signature.
49      * @param i_signature The target error signature.
50      */
51     std::shared_ptr<Resolution>
52         getResolution(const libhei::Signature& i_signature);
53 
54     /**
55      * @brief Initializes the signature list within the input isolation data
56      *        with their appropriate flags based on the RAS data files.
57      * @param i_signature The target error signature.
58      * @param i_flag      The flag to check for
59      * @return True if the flag is set for the given signature, else false.
60      */
61     bool isFlagSet(const libhei::Signature& i_signature,
62                    const RasDataFlags i_flag) const;
63 
64     /**
65      * @brief Returns of the version of the relevant RAS data file for the
66      *        input signature.
67      * @param i_signature The target error signature.
68      * @return The version of the RAS data file.
69      */
70     unsigned int getVersion(const libhei::Signature& i_signature) const;
71 
72   private:
73     /**
74      * @brief Parses all of the RAS data JSON files and validates them against
75      *        the associated schema.
76      */
77     void initDataFiles();
78 
79     /**
80      * @brief  Parses a signature in the given data file and returns a string
81      *         representing the target action for the signature.
82      * @param  i_data      The parsed RAS data file associated with the
83      *                     signature's chip type.
84      * @param  i_signature The target signature.
85      * @return A string representing the target action for the signature.
86      */
87     std::string parseSignature(const nlohmann::json& i_data,
88                                const libhei::Signature& i_signature) const;
89 
90     /**
91      * @brief  Parses a bus object in the given data file and returns the bus
92      *         type and unit path.
93      * @param  i_data The parsed RAS data file associated with the signature's
94      *                chip type.
95      * @param  i_name The name of the target bus.
96      * @return A tuple containing the bus type and unit path.
97      */
98     std::tuple<callout::BusType, std::string>
99         parseBus(const nlohmann::json& i_data, const std::string& i_name);
100 
101     /**
102      * @brief  Parses an action in the given data file and returns the
103      *         corresponding resolution.
104      * @param  i_data   The parsed RAS data file associated with the signature's
105      *                  chip type.
106      * @param  i_action The target action to parse from the given RAS data.
107      * @return A resolution (or nested resolutions) representing the given
108      *         action.
109      * @note   This function is called recursively because an action could
110      *         reference another action. This function will maintain a stack of
111      *         parsed actions and will assert that the same action cannot be
112      *         parsed more than once in the recursion stack.
113      */
114     std::shared_ptr<Resolution> parseAction(const nlohmann::json& i_data,
115                                             const std::string& i_action);
116 
117     /**
118      * @brief  Returns a callout priority enum value for the given string.
119      * @param  i_priority The priority string.
120      * @return A callout priority enum value.
121      */
122     callout::Priority getPriority(const std::string& i_priority);
123 };
124 
125 } // namespace analyzer
126