xref: /openbmc/openpower-hw-diags/analyzer/service_data.hpp (revision 64791cf708574e48182a69e35f39afb40351b1ba)
1f685afd6SZane Shelley #pragma once
2f685afd6SZane Shelley 
3f685afd6SZane Shelley #include <nlohmann/json.hpp>
4f685afd6SZane Shelley 
5f685afd6SZane Shelley namespace analyzer
6f685afd6SZane Shelley {
7f685afd6SZane Shelley 
8f685afd6SZane Shelley /** @brief An abstract class for service event, also known as a callout. */
9f685afd6SZane Shelley class Callout
10f685afd6SZane Shelley {
11f685afd6SZane Shelley   public:
12f685afd6SZane Shelley     /** Each callout will have a priority indicating when to issue the required
13f685afd6SZane Shelley      *  service action. Details below. */
14f685afd6SZane Shelley     enum Priority
15f685afd6SZane Shelley     {
16f685afd6SZane Shelley         /** Serivce is mandatory. */
17f685afd6SZane Shelley         HIGH,
18f685afd6SZane Shelley 
19f685afd6SZane Shelley         /** Serivce medium priority callouts one at a time, in order, until the
20f685afd6SZane Shelley          *  issue is resolved. */
21f685afd6SZane Shelley         MED,
22f685afd6SZane Shelley 
23f685afd6SZane Shelley         MED_A, ///< Same as PRI_MED, except replace all A's as a group.
24f685afd6SZane Shelley         MED_B, ///< Same as PRI_MED, except replace all B's as a group.
25f685afd6SZane Shelley         MED_C, ///< Same as PRI_MED, except replace all C's as a group.
26f685afd6SZane Shelley 
27f685afd6SZane Shelley         /** If servicing all high and medium priority callouts did not resolve
28f685afd6SZane Shelley          *  the issue, service low priority callouts one at a time, in order,
29f685afd6SZane Shelley          *  until the issue is resolved. */
30f685afd6SZane Shelley         LOW,
31f685afd6SZane Shelley     };
32f685afd6SZane Shelley 
33f685afd6SZane Shelley   public:
34f685afd6SZane Shelley     /** @brief Pure virtual destructor. */
35f685afd6SZane Shelley     virtual ~Callout() = 0;
36f685afd6SZane Shelley 
37f685afd6SZane Shelley   protected:
38f685afd6SZane Shelley     /**
39f685afd6SZane Shelley      * @brief Constructor from components.
40f685afd6SZane Shelley      * @param p The callout priority.
41f685afd6SZane Shelley      */
42f685afd6SZane Shelley     explicit Callout(Priority p) : iv_priority(p) {}
43f685afd6SZane Shelley 
44f685afd6SZane Shelley   private:
45f685afd6SZane Shelley     /** The callout priority. */
46f685afd6SZane Shelley     const Priority iv_priority;
47f685afd6SZane Shelley 
48f685afd6SZane Shelley   protected:
49f685afd6SZane Shelley     /**
50f685afd6SZane Shelley      * @brief Appends the callout priority to the end of the given json object.
51f685afd6SZane Shelley      * @param j The json object for a single callout.
52f685afd6SZane Shelley      */
53f685afd6SZane Shelley     void addPriority(nlohmann::json& j) const
54f685afd6SZane Shelley     {
55f685afd6SZane Shelley         // clang-format off
56f685afd6SZane Shelley         static const std::map<Priority, std::string> m =
57f685afd6SZane Shelley         {
58f685afd6SZane Shelley             {HIGH,  "H"},
59f685afd6SZane Shelley             {MED,   "M"},
60f685afd6SZane Shelley             {MED_A, "A"},
61f685afd6SZane Shelley             {MED_B, "B"},
62f685afd6SZane Shelley             {MED_C, "C"},
63f685afd6SZane Shelley             {LOW,   "L"},
64f685afd6SZane Shelley         };
65f685afd6SZane Shelley         // clang-format on
66f685afd6SZane Shelley 
67f685afd6SZane Shelley         j.emplace("Priority", m.at(iv_priority));
68f685afd6SZane Shelley     }
69f685afd6SZane Shelley 
70f685afd6SZane Shelley   public:
71f685afd6SZane Shelley     /**
72f685afd6SZane Shelley      * @brief Appends a json object representing this callout to the end of the
73f685afd6SZane Shelley      *        given json object.
74f685afd6SZane Shelley      * @param j The json object containing all current callouts for a PEL.
75f685afd6SZane Shelley      */
76f685afd6SZane Shelley     virtual void getJson(nlohmann::json&) const = 0;
77f685afd6SZane Shelley };
78f685afd6SZane Shelley 
79f685afd6SZane Shelley // Pure virtual destructor must be defined.
80f685afd6SZane Shelley inline Callout::~Callout() {}
81f685afd6SZane Shelley 
82f685afd6SZane Shelley /** @brief A service event requiring hardware replacement. */
83f685afd6SZane Shelley class HardwareCallout : public Callout
84f685afd6SZane Shelley {
85f685afd6SZane Shelley   public:
86f685afd6SZane Shelley     /**
87f685afd6SZane Shelley      * @brief Constructor from components.
88f685afd6SZane Shelley      * @param i_locationCode The location code of the hardware callout.
89f685afd6SZane Shelley      * @param i_priority     The callout priority.
90f685afd6SZane Shelley      */
91f685afd6SZane Shelley     HardwareCallout(const std::string& i_locationCode, Priority i_priority) :
92f685afd6SZane Shelley         Callout(i_priority), iv_locationCode(i_locationCode)
93f685afd6SZane Shelley     {}
94f685afd6SZane Shelley 
95f685afd6SZane Shelley   private:
96f685afd6SZane Shelley     /** The hardware location code. */
97f685afd6SZane Shelley     const std::string iv_locationCode;
98f685afd6SZane Shelley 
99f685afd6SZane Shelley   public:
100f685afd6SZane Shelley     void getJson(nlohmann::json& j) const override
101f685afd6SZane Shelley     {
102f685afd6SZane Shelley         nlohmann::json c = {{"LocationCode", iv_locationCode}};
103f685afd6SZane Shelley         addPriority(c);
104f685afd6SZane Shelley         j.emplace_back(c);
105f685afd6SZane Shelley     }
106f685afd6SZane Shelley };
107f685afd6SZane Shelley 
108f685afd6SZane Shelley /**
109f685afd6SZane Shelley  * @brief A service event requiring a special procedure to be handled by a
110f685afd6SZane Shelley  *        service engineer.
111f685afd6SZane Shelley  */
112f685afd6SZane Shelley class ProcedureCallout : public Callout
113f685afd6SZane Shelley {
114f685afd6SZane Shelley   public:
115f685afd6SZane Shelley     /** Supported service procedures. */
116f685afd6SZane Shelley     enum Procedure
117f685afd6SZane Shelley     {
118f685afd6SZane Shelley         NEXTLVL, ///< Contact next level support.
119f685afd6SZane Shelley     };
120f685afd6SZane Shelley 
121f685afd6SZane Shelley   public:
122f685afd6SZane Shelley     /**
123f685afd6SZane Shelley      * @brief Constructor from components.
124f685afd6SZane Shelley      * @param i_procedure The location code of the hardware callout.
125f685afd6SZane Shelley      * @param i_priority     The callout priority.
126f685afd6SZane Shelley      */
127f685afd6SZane Shelley     ProcedureCallout(Procedure i_procedure, Priority i_priority) :
128f685afd6SZane Shelley         Callout(i_priority), iv_procedure(i_procedure)
129f685afd6SZane Shelley     {}
130f685afd6SZane Shelley 
131f685afd6SZane Shelley   private:
132f685afd6SZane Shelley     /** The callout priority. */
133f685afd6SZane Shelley     const Procedure iv_procedure;
134f685afd6SZane Shelley 
135f685afd6SZane Shelley   public:
136f685afd6SZane Shelley     void getJson(nlohmann::json& j) const override
137f685afd6SZane Shelley     {
138f685afd6SZane Shelley         // clang-format off
139f685afd6SZane Shelley         static const std::map<Procedure, std::string> m =
140f685afd6SZane Shelley         {
141f685afd6SZane Shelley             {NEXTLVL, "NEXTLVL"},
142f685afd6SZane Shelley         };
143f685afd6SZane Shelley         // clang-format on
144f685afd6SZane Shelley 
145f685afd6SZane Shelley         nlohmann::json c = {{"Procedure", m.at(iv_procedure)}};
146f685afd6SZane Shelley         addPriority(c);
147f685afd6SZane Shelley         j.emplace_back(c);
148f685afd6SZane Shelley     }
149f685afd6SZane Shelley };
150f685afd6SZane Shelley 
151*64791cf7SZane Shelley /**
152*64791cf7SZane Shelley  * @brief Data regarding required service actions based on the hardware error
153*64791cf7SZane Shelley  *        analysis.
154*64791cf7SZane Shelley  */
155*64791cf7SZane Shelley class ServiceData
156*64791cf7SZane Shelley {
157*64791cf7SZane Shelley   public:
158*64791cf7SZane Shelley     /** @brief Default constructor. */
159*64791cf7SZane Shelley     ServiceData() = default;
160*64791cf7SZane Shelley 
161*64791cf7SZane Shelley     /** @brief Destructor. */
162*64791cf7SZane Shelley     ~ServiceData() = default;
163*64791cf7SZane Shelley 
164*64791cf7SZane Shelley     /** @brief Copy constructor. */
165*64791cf7SZane Shelley     ServiceData(const ServiceData&) = default;
166*64791cf7SZane Shelley 
167*64791cf7SZane Shelley     /** @brief Assignment operator. */
168*64791cf7SZane Shelley     ServiceData& operator=(const ServiceData&) = default;
169*64791cf7SZane Shelley 
170*64791cf7SZane Shelley   private:
171*64791cf7SZane Shelley     /** The list of callouts that will be added to a PEL. */
172*64791cf7SZane Shelley     std::vector<std::shared_ptr<Callout>> iv_calloutList;
173*64791cf7SZane Shelley 
174*64791cf7SZane Shelley   public:
175*64791cf7SZane Shelley     /** Add a callout to the callout list. */
176*64791cf7SZane Shelley     void addCallout(const std::shared_ptr<Callout>& i_callout)
177*64791cf7SZane Shelley     {
178*64791cf7SZane Shelley         iv_calloutList.push_back(i_callout);
179*64791cf7SZane Shelley     }
180*64791cf7SZane Shelley 
181*64791cf7SZane Shelley     /**
182*64791cf7SZane Shelley      * @brief Iterates the callout list and returns the json attached to each
183*64791cf7SZane Shelley      *        callout in the list.
184*64791cf7SZane Shelley      * @param o_json The returned json data.
185*64791cf7SZane Shelley      */
186*64791cf7SZane Shelley     void getCalloutList(nlohmann::json& o_json) const
187*64791cf7SZane Shelley     {
188*64791cf7SZane Shelley         o_json.clear(); // Ensure we are starting with a clean list.
189*64791cf7SZane Shelley 
190*64791cf7SZane Shelley         for (const auto& c : iv_calloutList)
191*64791cf7SZane Shelley         {
192*64791cf7SZane Shelley             c->getJson(o_json);
193*64791cf7SZane Shelley         }
194*64791cf7SZane Shelley     }
195*64791cf7SZane Shelley };
196*64791cf7SZane Shelley 
197f685afd6SZane Shelley } // namespace analyzer
198