1 #pragma once 2 3 #include <analyzer/callout.hpp> 4 #include <hei_main.hpp> 5 #include <nlohmann/json.hpp> 6 7 namespace analyzer 8 { 9 10 /** 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 /** 59 * @brief Data regarding required service actions based on the hardware error 60 * analysis. 61 */ 62 class ServiceData 63 { 64 public: 65 /** 66 * @brief Constructor from components. 67 * @param The signature of the root cause attention. 68 * @param True if the signature list contained a system checkstop attention. 69 * False, otherwise. 70 */ 71 ServiceData(const libhei::Signature& i_rootCause, bool i_isCheckstop) : 72 iv_rootCause(i_rootCause), iv_isCheckstop(i_isCheckstop) 73 {} 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: 85 /** The signature of the root cause attention. */ 86 const libhei::Signature iv_rootCause; 87 88 /** True if the signature list contained a system checkstop attention. 89 * False, otherwise. */ 90 const bool iv_isCheckstop; 91 92 /** The list of callouts that will be added to a PEL. */ 93 nlohmann::json iv_calloutList = nlohmann::json::array(); 94 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 100 public: 101 /** @return The signature of the root cause attention. */ 102 const libhei::Signature& getRootCause() const 103 { 104 return iv_rootCause; 105 } 106 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 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) 119 { 120 iv_calloutList.push_back(i_callout); 121 } 122 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 129 /** @brief Accessor to iv_calloutList. */ 130 const nlohmann::json& getCalloutList() const 131 { 132 return iv_calloutList; 133 } 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 } 149 }; 150 151 } // namespace analyzer 152