Zane Shelley | f685afd | 2021-02-15 15:39:44 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 3 | #include <analyzer/callout.hpp> |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 4 | #include <hei_main.hpp> |
Zane Shelley | f685afd | 2021-02-15 15:39:44 -0600 | [diff] [blame] | 5 | #include <nlohmann/json.hpp> |
| 6 | |
| 7 | namespace analyzer |
| 8 | { |
| 9 | |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 10 | /** |
Zane Shelley | 5f6e3de | 2021-02-23 13:57:37 -0600 | [diff] [blame] | 11 | * @brief A service event requiring hardware to be guarded. |
| 12 | */ |
| 13 | class 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 Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 59 | * @brief Data regarding required service actions based on the hardware error |
| 60 | * analysis. |
| 61 | */ |
| 62 | class ServiceData |
| 63 | { |
| 64 | public: |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 65 | /** |
| 66 | * @brief Constructor from components. |
| 67 | * @param The signature of the root cause attention. |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 68 | * @param True if the signature list contained a system checkstop attention. |
| 69 | * False, otherwise. |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 70 | */ |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 71 | ServiceData(const libhei::Signature& i_rootCause, bool i_isCheckstop) : |
| 72 | iv_rootCause(i_rootCause), iv_isCheckstop(i_isCheckstop) |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 73 | {} |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 74 | |
| 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 Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 85 | /** The signature of the root cause attention. */ |
| 86 | const libhei::Signature iv_rootCause; |
| 87 | |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 88 | /** True if the signature list contained a system checkstop attention. |
| 89 | * False, otherwise. */ |
| 90 | const bool iv_isCheckstop; |
| 91 | |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 92 | /** The list of callouts that will be added to a PEL. */ |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 93 | nlohmann::json iv_calloutList = nlohmann::json::array(); |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 94 | |
Zane Shelley | 5f6e3de | 2021-02-23 13:57:37 -0600 | [diff] [blame] | 95 | /** 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 Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 100 | public: |
Zane Shelley | 8af9e46 | 2021-03-11 10:44:28 -0600 | [diff] [blame] | 101 | /** @return The signature of the root cause attention. */ |
| 102 | const libhei::Signature& getRootCause() const |
| 103 | { |
| 104 | return iv_rootCause; |
| 105 | } |
| 106 | |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 107 | /** @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 Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 114 | /** |
| 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 Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 119 | { |
| 120 | iv_calloutList.push_back(i_callout); |
| 121 | } |
| 122 | |
Zane Shelley | 5f6e3de | 2021-02-23 13:57:37 -0600 | [diff] [blame] | 123 | /** 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 Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 129 | /** @brief Accessor to iv_calloutList. */ |
| 130 | const nlohmann::json& getCalloutList() const |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 131 | { |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 132 | return iv_calloutList; |
Zane Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 133 | } |
Zane Shelley | 5f6e3de | 2021-02-23 13:57:37 -0600 | [diff] [blame] | 134 | |
| 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 Shelley | 64791cf | 2021-02-15 17:02:37 -0600 | [diff] [blame] | 149 | }; |
| 150 | |
Zane Shelley | f685afd | 2021-02-15 15:39:44 -0600 | [diff] [blame] | 151 | } // namespace analyzer |