1 #pragma once
2 
3 #include <analyzer/analyzer_main.hpp>
4 #include <analyzer/callout.hpp>
5 #include <hei_main.hpp>
6 #include <nlohmann/json.hpp>
7 #include <util/pdbg.hpp>
8 
9 namespace analyzer
10 {
11 
12 /**
13  * @brief Data regarding required service actions based on the hardware error
14  *        analysis.
15  */
16 class ServiceData
17 {
18   public:
19     /**
20      * @brief Constructor from components.
21      * @param i_rootCause    The signature of the root cause attention.
22      * @param i_analysisType The type of analysis to perform.
23      * @param i_isoData      The data found during isolation.
24      */
25     ServiceData(const libhei::Signature& i_rootCause,
26                 AnalysisType i_analysisType,
27                 const libhei::IsolationData& i_isoData) :
28         iv_rootCause(i_rootCause),
29         iv_analysisType(i_analysisType), iv_isoData(i_isoData)
30     {}
31 
32     /** @brief Destructor. */
33     ~ServiceData() = default;
34 
35     /** @brief Copy constructor. */
36     ServiceData(const ServiceData&) = default;
37 
38     /** @brief Assignment operator. */
39     ServiceData& operator=(const ServiceData&) = default;
40 
41   private:
42     /** The signature of the root cause attention. */
43     const libhei::Signature iv_rootCause;
44 
45     /** The type of analysis to perform. */
46     const AnalysisType iv_analysisType;
47 
48     /** The data found during isolation. */
49     const libhei::IsolationData iv_isoData;
50 
51     /** The list of callouts that will be added to a PEL. */
52     nlohmann::json iv_calloutList = nlohmann::json::array();
53 
54     /** FFDC for callouts that would otherwise not be available in the
55      *  callout list (unit paths, bus types, etc.). */
56     nlohmann::json iv_calloutFFDC = nlohmann::json::array();
57 
58   public:
59     /** @return The signature of the root cause attention. */
60     const libhei::Signature& getRootCause() const
61     {
62         return iv_rootCause;
63     }
64 
65     /** @return The type of analysis to perform. */
66     AnalysisType getAnalysisType() const
67     {
68         return iv_analysisType;
69     }
70 
71     /** @return The data found during isolation. */
72     const libhei::IsolationData& getIsolationData() const
73     {
74         return iv_isoData;
75     }
76 
77     /** @return Returns the guard type based on current analysis policies. */
78     callout::GuardType queryGuardPolicy() const
79     {
80         if (AnalysisType::SYSTEM_CHECKSTOP == iv_analysisType)
81         {
82             return callout::GuardType::UNRECOVERABLE;
83         }
84         else if (AnalysisType::TERMINATE_IMMEDIATE == iv_analysisType)
85         {
86             return callout::GuardType::PREDICTIVE;
87         }
88 
89         return callout::GuardType::NONE;
90     }
91 
92     /**
93      * @brief Add callout for a pdbg_target.
94      * @param i_target   The chip or unit target to add to the callout list.
95      * @param i_priority The callout priority.
96      * @param i_guard    True if guard is required. False, otherwise.
97      */
98     void calloutTarget(pdbg_target* i_target,
99                        const callout::Priority& i_priority, bool i_guard);
100 
101     /**
102      * @brief Add callout for a connected target on the other side of a bus.
103      * @param i_rxTarget The target on the receiving side (RX) of the bus.
104      * @param i_busType  The bus type.
105      * @param i_priority The callout priority.
106      * @param i_guard    True if guard is required. False, otherwise.
107      */
108     void calloutConnected(pdbg_target* i_rxTarget,
109                           const callout::BusType& i_busType,
110                           const callout::Priority& i_priority, bool i_guard);
111 
112     /**
113      * @brief Add callout for an entire bus.
114      * @param i_rxTarget The target on the receiving side (RX) of the bus.
115      * @param i_busType  The bus type.
116      * @param i_priority The callout priority.
117      * @param i_guard    True if guard is required. False, otherwise.
118      */
119     void calloutBus(pdbg_target* i_rxTarget, const callout::BusType& i_busType,
120                     const callout::Priority& i_priority, bool i_guard);
121 
122     /**
123      * @brief Add callout for a clock.
124      * @param i_clockType The clock type.
125      * @param i_priority  The callout priority.
126      * @param i_guard     True if guard is required. False, otherwise.
127      */
128     void calloutClock(const callout::ClockType& i_clockType,
129                       const callout::Priority& i_priority, bool i_guard);
130 
131     /**
132      * @brief Add callout for a service procedure.
133      * @param i_procedure The procedure type.
134      * @param i_priority  The callout priority.
135      */
136     void calloutProcedure(const callout::Procedure& i_procedure,
137                           const callout::Priority& i_priority);
138 
139     /**
140      * @brief Add callout for part type.
141      * @param i_part     The part type.
142      * @param i_priority The callout priority.
143      */
144     void calloutPart(const callout::PartType& i_part,
145                      const callout::Priority& i_priority);
146 
147     /** @brief Accessor to iv_calloutList. */
148     const nlohmann::json& getCalloutList() const
149     {
150         return iv_calloutList;
151     }
152 
153     /** @brief Accessor to iv_calloutFFDC. */
154     const nlohmann::json& getCalloutFFDC() const
155     {
156         return iv_calloutFFDC;
157     }
158 
159   private:
160     /**
161      * @brief Add callout information to the callout list.
162      * @param The JSON object for this callout.
163      */
164     void addCallout(const nlohmann::json& i_callout);
165 
166     /**
167      * @brief Add FFDC for a callout that would otherwise not be available in
168      *        the callout list (unit paths, bus types, etc.).
169      * @param The JSON object for this callout.
170      */
171     void addCalloutFFDC(const nlohmann::json& i_ffdc)
172     {
173         iv_calloutFFDC.push_back(i_ffdc);
174     }
175 
176     /**
177      * @brief A simple helper function for all the callout functions that need
178      *        to callout a target (callout only, no FFDC).
179      * @param i_target   The chip or unit target to add to the callout list.
180      * @param i_priority The callout priority.
181      * @param i_guard    True if guard is required. False, otherwise.
182      */
183     void addTargetCallout(pdbg_target* i_target,
184                           const callout::Priority& i_priority, bool i_guard);
185 
186     /**
187      * @brief A simple helper function for all the callout functions that need
188      *        to callout a the backplane (callout only, no FFDC).
189      * @param i_priority The callout priority.
190      */
191     void addBackplaneCallout(const callout::Priority& i_priority);
192 };
193 
194 } // namespace analyzer
195