blob: 66e0200fa6ea19da7d0d2797efdbb465208f482c [file] [log] [blame]
Zane Shelleyf685afd2021-02-15 15:39:44 -06001#pragma once
2
Zane Shelley8af9e462021-03-11 10:44:28 -06003#include <hei_main.hpp>
Zane Shelleyf685afd2021-02-15 15:39:44 -06004#include <nlohmann/json.hpp>
5
6namespace analyzer
7{
8
9/** @brief An abstract class for service event, also known as a callout. */
10class Callout
11{
12 public:
13 /** Each callout will have a priority indicating when to issue the required
14 * service action. Details below. */
15 enum Priority
16 {
17 /** Serivce is mandatory. */
18 HIGH,
19
20 /** Serivce medium priority callouts one at a time, in order, until the
21 * issue is resolved. */
22 MED,
23
24 MED_A, ///< Same as PRI_MED, except replace all A's as a group.
25 MED_B, ///< Same as PRI_MED, except replace all B's as a group.
26 MED_C, ///< Same as PRI_MED, except replace all C's as a group.
27
28 /** If servicing all high and medium priority callouts did not resolve
29 * the issue, service low priority callouts one at a time, in order,
30 * until the issue is resolved. */
31 LOW,
32 };
33
34 public:
35 /** @brief Pure virtual destructor. */
36 virtual ~Callout() = 0;
37
38 protected:
39 /**
40 * @brief Constructor from components.
41 * @param p The callout priority.
42 */
43 explicit Callout(Priority p) : iv_priority(p) {}
44
45 private:
46 /** The callout priority. */
47 const Priority iv_priority;
48
49 protected:
50 /**
51 * @brief Appends the callout priority to the end of the given json object.
52 * @param j The json object for a single callout.
53 */
54 void addPriority(nlohmann::json& j) const
55 {
56 // clang-format off
57 static const std::map<Priority, std::string> m =
58 {
59 {HIGH, "H"},
60 {MED, "M"},
61 {MED_A, "A"},
62 {MED_B, "B"},
63 {MED_C, "C"},
64 {LOW, "L"},
65 };
66 // clang-format on
67
68 j.emplace("Priority", m.at(iv_priority));
69 }
70
71 public:
72 /**
73 * @brief Appends a json object representing this callout to the end of the
74 * given json object.
75 * @param j The json object containing all current callouts for a PEL.
76 */
77 virtual void getJson(nlohmann::json&) const = 0;
78};
79
80// Pure virtual destructor must be defined.
81inline Callout::~Callout() {}
82
83/** @brief A service event requiring hardware replacement. */
84class HardwareCallout : public Callout
85{
86 public:
87 /**
88 * @brief Constructor from components.
89 * @param i_locationCode The location code of the hardware callout.
90 * @param i_priority The callout priority.
91 */
92 HardwareCallout(const std::string& i_locationCode, Priority i_priority) :
93 Callout(i_priority), iv_locationCode(i_locationCode)
94 {}
95
96 private:
97 /** The hardware location code. */
98 const std::string iv_locationCode;
99
100 public:
101 void getJson(nlohmann::json& j) const override
102 {
103 nlohmann::json c = {{"LocationCode", iv_locationCode}};
104 addPriority(c);
105 j.emplace_back(c);
106 }
107};
108
109/**
110 * @brief A service event requiring a special procedure to be handled by a
111 * service engineer.
112 */
113class ProcedureCallout : public Callout
114{
115 public:
116 /** Supported service procedures. */
Zane Shelley0b8368c2021-03-18 17:33:41 -0500117 enum Type
Zane Shelleyf685afd2021-02-15 15:39:44 -0600118 {
119 NEXTLVL, ///< Contact next level support.
120 };
121
122 public:
123 /**
124 * @brief Constructor from components.
125 * @param i_procedure The location code of the hardware callout.
126 * @param i_priority The callout priority.
127 */
Zane Shelley0b8368c2021-03-18 17:33:41 -0500128 ProcedureCallout(Type i_procedure, Priority i_priority) :
Zane Shelleyf685afd2021-02-15 15:39:44 -0600129 Callout(i_priority), iv_procedure(i_procedure)
130 {}
131
132 private:
133 /** The callout priority. */
Zane Shelley0b8368c2021-03-18 17:33:41 -0500134 const Type iv_procedure;
Zane Shelleyf685afd2021-02-15 15:39:44 -0600135
136 public:
137 void getJson(nlohmann::json& j) const override
138 {
139 // clang-format off
Zane Shelley0b8368c2021-03-18 17:33:41 -0500140 static const std::map<Type, std::string> m =
Zane Shelleyf685afd2021-02-15 15:39:44 -0600141 {
142 {NEXTLVL, "NEXTLVL"},
143 };
144 // clang-format on
145
146 nlohmann::json c = {{"Procedure", m.at(iv_procedure)}};
147 addPriority(c);
148 j.emplace_back(c);
149 }
150};
151
Zane Shelley64791cf2021-02-15 17:02:37 -0600152/**
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600153 * @brief A service event requiring hardware to be guarded.
154 */
155class Guard
156{
157 public:
158 /** Supported guard types. */
159 enum Type
160 {
161 NONE, ///< Do not guard
162 FATAL, ///< Guard on fatal error (cannot recover resource)
163 NON_FATAL, ///< Guard on non-fatal error (can recover resource)
164 };
165
166 public:
167 /**
168 * @brief Constructor from components.
169 * @param i_path The hardware path to guard.
170 * @param i_type The guard type.
171 */
172 Guard(const std::string& i_path, Type i_type) :
173 iv_path(i_path), iv_type(i_type)
174 {}
175
176 private:
177 /** The hardware path to guard. */
178 const std::string iv_path;
179
180 /** The guard type. */
181 const Type iv_type;
182
183 public:
184 void getJson(nlohmann::json& j) const
185 {
186 // clang-format off
187 static const std::map<Type, std::string> m =
188 {
189 {NONE, "NONE"},
190 {FATAL, "FATAL"},
191 {NON_FATAL, "NON_FATAL"},
192 };
193 // clang-format on
194
195 nlohmann::json c = {{"Path", iv_path}, {"Type", m.at(iv_type)}};
196 j.emplace_back(c);
197 }
198};
199
200/**
Zane Shelley64791cf2021-02-15 17:02:37 -0600201 * @brief Data regarding required service actions based on the hardware error
202 * analysis.
203 */
204class ServiceData
205{
206 public:
Zane Shelley8af9e462021-03-11 10:44:28 -0600207 /**
208 * @brief Constructor from components.
209 * @param The signature of the root cause attention.
Zane Shelleyca496192021-08-09 12:05:52 -0500210 * @param True if the signature list contained a system checkstop attention.
211 * False, otherwise.
Zane Shelley8af9e462021-03-11 10:44:28 -0600212 */
Zane Shelleyca496192021-08-09 12:05:52 -0500213 ServiceData(const libhei::Signature& i_rootCause, bool i_isCheckstop) :
214 iv_rootCause(i_rootCause), iv_isCheckstop(i_isCheckstop)
Zane Shelley8af9e462021-03-11 10:44:28 -0600215 {}
Zane Shelley64791cf2021-02-15 17:02:37 -0600216
217 /** @brief Destructor. */
218 ~ServiceData() = default;
219
220 /** @brief Copy constructor. */
221 ServiceData(const ServiceData&) = default;
222
223 /** @brief Assignment operator. */
224 ServiceData& operator=(const ServiceData&) = default;
225
226 private:
Zane Shelley8af9e462021-03-11 10:44:28 -0600227 /** The signature of the root cause attention. */
228 const libhei::Signature iv_rootCause;
229
Zane Shelleyca496192021-08-09 12:05:52 -0500230 /** True if the signature list contained a system checkstop attention.
231 * False, otherwise. */
232 const bool iv_isCheckstop;
233
Zane Shelley64791cf2021-02-15 17:02:37 -0600234 /** The list of callouts that will be added to a PEL. */
235 std::vector<std::shared_ptr<Callout>> iv_calloutList;
236
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600237 /** The list of hardware guard requests. Some information will be added to
238 * the PEL, but the actual guard record will be created after submitting the
239 * PEL. */
240 std::vector<std::shared_ptr<Guard>> iv_guardList;
241
Zane Shelley64791cf2021-02-15 17:02:37 -0600242 public:
Zane Shelley8af9e462021-03-11 10:44:28 -0600243 /** @return The signature of the root cause attention. */
244 const libhei::Signature& getRootCause() const
245 {
246 return iv_rootCause;
247 }
248
Zane Shelleyca496192021-08-09 12:05:52 -0500249 /** @return True if the signature list contained a system checkstop
250 * attention. False, otherwise. */
251 bool queryCheckstop() const
252 {
253 return iv_isCheckstop;
254 }
255
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600256 /** Add a callout to the list. */
Zane Shelley64791cf2021-02-15 17:02:37 -0600257 void addCallout(const std::shared_ptr<Callout>& i_callout)
258 {
259 iv_calloutList.push_back(i_callout);
260 }
261
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600262 /** Add a guard request to the list. */
263 void addGuard(const std::shared_ptr<Guard>& i_guard)
264 {
265 iv_guardList.push_back(i_guard);
266 }
267
Zane Shelley64791cf2021-02-15 17:02:37 -0600268 /**
269 * @brief Iterates the callout list and returns the json attached to each
270 * callout in the list.
271 * @param o_json The returned json data.
272 */
273 void getCalloutList(nlohmann::json& o_json) const
274 {
275 o_json.clear(); // Ensure we are starting with a clean list.
276
277 for (const auto& c : iv_calloutList)
278 {
279 c->getJson(o_json);
280 }
281 }
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600282
283 /**
284 * @brief Iterates the guard list and returns the json attached to each
285 * guard request in the list.
286 * @param o_json The returned json data.
287 */
288 void getGuardList(nlohmann::json& o_json) const
289 {
290 o_json.clear(); // Ensure we are starting with a clean list.
291
292 for (const auto& g : iv_guardList)
293 {
294 g->getJson(o_json);
295 }
296 }
Zane Shelley64791cf2021-02-15 17:02:37 -0600297};
298
Zane Shelleyf685afd2021-02-15 15:39:44 -0600299} // namespace analyzer