blob: c9f9c41d3e292f2a9cbfbd425f6c36288d069a33 [file] [log] [blame]
Zane Shelleyf685afd2021-02-15 15:39:44 -06001#pragma once
2
Zane Shelleyc85716c2021-08-17 10:54:06 -05003#include <analyzer/callout.hpp>
Zane Shelley8af9e462021-03-11 10:44:28 -06004#include <hei_main.hpp>
Zane Shelleyf685afd2021-02-15 15:39:44 -06005#include <nlohmann/json.hpp>
6
7namespace analyzer
8{
9
Zane Shelley64791cf2021-02-15 17:02:37 -060010/**
Zane Shelley5f6e3de2021-02-23 13:57:37 -060011 * @brief A service event requiring hardware to be guarded.
12 */
13class Guard
14{
15 public:
16 /** Supported guard types. */
17 enum Type
18 {
19 NONE, ///< Do not guard
20 FATAL, ///< Guard on fatal error (cannot recover resource)
21 NON_FATAL, ///< Guard on non-fatal error (can recover resource)
22 };
23
24 public:
25 /**
26 * @brief Constructor from components.
27 * @param i_path The hardware path to guard.
28 * @param i_type The guard type.
29 */
30 Guard(const std::string& i_path, Type i_type) :
31 iv_path(i_path), iv_type(i_type)
32 {}
33
34 private:
35 /** The hardware path to guard. */
36 const std::string iv_path;
37
38 /** The guard type. */
39 const Type iv_type;
40
41 public:
42 void getJson(nlohmann::json& j) const
43 {
44 // clang-format off
45 static const std::map<Type, std::string> m =
46 {
47 {NONE, "NONE"},
48 {FATAL, "FATAL"},
49 {NON_FATAL, "NON_FATAL"},
50 };
51 // clang-format on
52
53 nlohmann::json c = {{"Path", iv_path}, {"Type", m.at(iv_type)}};
54 j.emplace_back(c);
55 }
56};
57
58/**
Zane Shelley64791cf2021-02-15 17:02:37 -060059 * @brief Data regarding required service actions based on the hardware error
60 * analysis.
61 */
62class ServiceData
63{
64 public:
Zane Shelley8af9e462021-03-11 10:44:28 -060065 /**
66 * @brief Constructor from components.
67 * @param The signature of the root cause attention.
Zane Shelleyca496192021-08-09 12:05:52 -050068 * @param True if the signature list contained a system checkstop attention.
69 * False, otherwise.
Zane Shelley8af9e462021-03-11 10:44:28 -060070 */
Zane Shelleyca496192021-08-09 12:05:52 -050071 ServiceData(const libhei::Signature& i_rootCause, bool i_isCheckstop) :
72 iv_rootCause(i_rootCause), iv_isCheckstop(i_isCheckstop)
Zane Shelley8af9e462021-03-11 10:44:28 -060073 {}
Zane Shelley64791cf2021-02-15 17:02:37 -060074
75 /** @brief Destructor. */
76 ~ServiceData() = default;
77
78 /** @brief Copy constructor. */
79 ServiceData(const ServiceData&) = default;
80
81 /** @brief Assignment operator. */
82 ServiceData& operator=(const ServiceData&) = default;
83
84 private:
Zane Shelley8af9e462021-03-11 10:44:28 -060085 /** The signature of the root cause attention. */
86 const libhei::Signature iv_rootCause;
87
Zane Shelleyca496192021-08-09 12:05:52 -050088 /** True if the signature list contained a system checkstop attention.
89 * False, otherwise. */
90 const bool iv_isCheckstop;
91
Zane Shelley64791cf2021-02-15 17:02:37 -060092 /** The list of callouts that will be added to a PEL. */
Zane Shelleyc85716c2021-08-17 10:54:06 -050093 nlohmann::json iv_calloutList = nlohmann::json::array();
Zane Shelley64791cf2021-02-15 17:02:37 -060094
Zane Shelley5f6e3de2021-02-23 13:57:37 -060095 /** The list of hardware guard requests. Some information will be added to
96 * the PEL, but the actual guard record will be created after submitting the
97 * PEL. */
98 std::vector<std::shared_ptr<Guard>> iv_guardList;
99
Zane Shelley64791cf2021-02-15 17:02:37 -0600100 public:
Zane Shelley8af9e462021-03-11 10:44:28 -0600101 /** @return The signature of the root cause attention. */
102 const libhei::Signature& getRootCause() const
103 {
104 return iv_rootCause;
105 }
106
Zane Shelleyca496192021-08-09 12:05:52 -0500107 /** @return True if the signature list contained a system checkstop
108 * attention. False, otherwise. */
109 bool queryCheckstop() const
110 {
111 return iv_isCheckstop;
112 }
113
Zane Shelleyc85716c2021-08-17 10:54:06 -0500114 /**
115 * @brief Add callout information to the callout list.
116 * @param The JSON object for this callout.
117 */
118 void addCallout(const nlohmann::json& i_callout)
Zane Shelley64791cf2021-02-15 17:02:37 -0600119 {
120 iv_calloutList.push_back(i_callout);
121 }
122
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600123 /** Add a guard request to the list. */
124 void addGuard(const std::shared_ptr<Guard>& i_guard)
125 {
126 iv_guardList.push_back(i_guard);
127 }
128
Zane Shelleyc85716c2021-08-17 10:54:06 -0500129 /** @brief Accessor to iv_calloutList. */
130 const nlohmann::json& getCalloutList() const
Zane Shelley64791cf2021-02-15 17:02:37 -0600131 {
Zane Shelleyc85716c2021-08-17 10:54:06 -0500132 return iv_calloutList;
Zane Shelley64791cf2021-02-15 17:02:37 -0600133 }
Zane Shelley5f6e3de2021-02-23 13:57:37 -0600134
135 /**
136 * @brief Iterates the guard list and returns the json attached to each
137 * guard request in the list.
138 * @param o_json The returned json data.
139 */
140 void getGuardList(nlohmann::json& o_json) const
141 {
142 o_json.clear(); // Ensure we are starting with a clean list.
143
144 for (const auto& g : iv_guardList)
145 {
146 g->getJson(o_json);
147 }
148 }
Zane Shelley64791cf2021-02-15 17:02:37 -0600149};
150
Zane Shelleyf685afd2021-02-15 15:39:44 -0600151} // namespace analyzer