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 The signature of the root cause attention.
22      * @param The type of analysis to perform.
23      */
24     ServiceData(const libhei::Signature& i_rootCause,
25                 AnalysisType i_analysisType) :
26         iv_rootCause(i_rootCause),
27         iv_analysisType(i_analysisType)
28     {}
29 
30     /** @brief Destructor. */
31     ~ServiceData() = default;
32 
33     /** @brief Copy constructor. */
34     ServiceData(const ServiceData&) = default;
35 
36     /** @brief Assignment operator. */
37     ServiceData& operator=(const ServiceData&) = default;
38 
39   private:
40     /** The signature of the root cause attention. */
41     const libhei::Signature iv_rootCause;
42 
43     /** The type of analysis to perform. */
44     const AnalysisType iv_analysisType;
45 
46     /** The list of callouts that will be added to a PEL. */
47     nlohmann::json iv_calloutList = nlohmann::json::array();
48 
49     /** FFDC for callouts that would otherwise not be available in the
50      *  callout list (unit paths, bus types, etc.). */
51     nlohmann::json iv_calloutFFDC = nlohmann::json::array();
52 
53   public:
54     /** @return The signature of the root cause attention. */
55     const libhei::Signature& getRootCause() const
56     {
57         return iv_rootCause;
58     }
59 
60     /** @return The type of analysis to perform. */
61     AnalysisType getAnalysisType() const
62     {
63         return iv_analysisType;
64     }
65 
66     /** @return Returns the guard type based on current analysis policies. */
67     callout::GuardType queryGuardPolicy() const
68     {
69         if (AnalysisType::SYSTEM_CHECKSTOP == iv_analysisType)
70         {
71             return callout::GuardType::UNRECOVERABLE;
72         }
73         else if (AnalysisType::TERMINATE_IMMEDIATE == iv_analysisType)
74         {
75             return callout::GuardType::PREDICTIVE;
76         }
77 
78         return callout::GuardType::NONE;
79     }
80 
81     /**
82      * @brief Add callout for a pdbg_target.
83      * @param i_target   The chip or unit target to add to the callout list.
84      * @param i_priority The callout priority.
85      * @param i_guard    True if guard is required. False, otherwise.
86      */
87     void calloutTarget(pdbg_target* i_target,
88                        const callout::Priority& i_priority, bool i_guard);
89 
90     /**
91      * @brief Add callout for a connected target on the other side of a bus.
92      * @param i_rxTarget The target on the receiving side (RX) of the bus.
93      * @param i_busType  The bus type.
94      * @param i_priority The callout priority.
95      * @param i_guard    True if guard is required. False, otherwise.
96      */
97     void calloutConnected(pdbg_target* i_rxTarget,
98                           const callout::BusType& i_busType,
99                           const callout::Priority& i_priority, bool i_guard);
100 
101     /**
102      * @brief Add callout for an entire 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 calloutBus(pdbg_target* i_rxTarget, const callout::BusType& i_busType,
109                     const callout::Priority& i_priority, bool i_guard);
110 
111     /**
112      * @brief Add callout for a clock.
113      * @param i_clockType The clock type.
114      * @param i_priority  The callout priority.
115      * @param i_guard     True if guard is required. False, otherwise.
116      */
117     void calloutClock(const callout::ClockType& i_clockType,
118                       const callout::Priority& i_priority, bool i_guard);
119 
120     /**
121      * @brief Add callout for a service procedure.
122      * @param i_procedure The procedure type.
123      * @param i_priority  The callout priority.
124      */
125     void calloutProcedure(const callout::Procedure& i_procedure,
126                           const callout::Priority& i_priority);
127 
128     /** @brief Accessor to iv_calloutList. */
129     const nlohmann::json& getCalloutList() const
130     {
131         return iv_calloutList;
132     }
133 
134     /** @brief Accessor to iv_calloutFFDC. */
135     const nlohmann::json& getCalloutFFDC() const
136     {
137         return iv_calloutFFDC;
138     }
139 
140   private:
141     /**
142      * @brief Add callout information to the callout list.
143      * @param The JSON object for this callout.
144      */
145     void addCallout(const nlohmann::json& i_callout);
146 
147     /**
148      * @brief Add FFDC for a callout that would otherwise not be available in
149      *        the callout list (unit paths, bus types, etc.).
150      * @param The JSON object for this callout.
151      */
152     void addCalloutFFDC(const nlohmann::json& i_ffdc)
153     {
154         iv_calloutFFDC.push_back(i_ffdc);
155     }
156 
157     /**
158      * @brief A simple helper function for all the callout functions that need
159      *        to callout a target (callout only, no FFDC).
160      * @param i_target   The chip or unit target to add to the callout list.
161      * @param i_priority The callout priority.
162      * @param i_guard    True if guard is required. False, otherwise.
163      */
164     void addTargetCallout(pdbg_target* i_target,
165                           const callout::Priority& i_priority, bool i_guard);
166 
167     /**
168      * @brief A simple helper function for all the callout functions that need
169      *        to callout a the backplane (callout only, no FFDC).
170      * @param i_priority The callout priority.
171      */
172     void addBackplaneCallout(const callout::Priority& i_priority);
173 };
174 
175 } // namespace analyzer
176