1f685afd6SZane Shelley #pragma once 2f685afd6SZane Shelley 3*c85716caSZane Shelley #include <analyzer/callout.hpp> 48af9e46fSZane Shelley #include <hei_main.hpp> 5f685afd6SZane Shelley #include <nlohmann/json.hpp> 6f685afd6SZane Shelley 7f685afd6SZane Shelley namespace analyzer 8f685afd6SZane Shelley { 9f685afd6SZane Shelley 1064791cf7SZane Shelley /** 115f6e3debSZane Shelley * @brief A service event requiring hardware to be guarded. 125f6e3debSZane Shelley */ 135f6e3debSZane Shelley class Guard 145f6e3debSZane Shelley { 155f6e3debSZane Shelley public: 165f6e3debSZane Shelley /** Supported guard types. */ 175f6e3debSZane Shelley enum Type 185f6e3debSZane Shelley { 195f6e3debSZane Shelley NONE, ///< Do not guard 205f6e3debSZane Shelley FATAL, ///< Guard on fatal error (cannot recover resource) 215f6e3debSZane Shelley NON_FATAL, ///< Guard on non-fatal error (can recover resource) 225f6e3debSZane Shelley }; 235f6e3debSZane Shelley 245f6e3debSZane Shelley public: 255f6e3debSZane Shelley /** 265f6e3debSZane Shelley * @brief Constructor from components. 275f6e3debSZane Shelley * @param i_path The hardware path to guard. 285f6e3debSZane Shelley * @param i_type The guard type. 295f6e3debSZane Shelley */ 305f6e3debSZane Shelley Guard(const std::string& i_path, Type i_type) : 315f6e3debSZane Shelley iv_path(i_path), iv_type(i_type) 325f6e3debSZane Shelley {} 335f6e3debSZane Shelley 345f6e3debSZane Shelley private: 355f6e3debSZane Shelley /** The hardware path to guard. */ 365f6e3debSZane Shelley const std::string iv_path; 375f6e3debSZane Shelley 385f6e3debSZane Shelley /** The guard type. */ 395f6e3debSZane Shelley const Type iv_type; 405f6e3debSZane Shelley 415f6e3debSZane Shelley public: 425f6e3debSZane Shelley void getJson(nlohmann::json& j) const 435f6e3debSZane Shelley { 445f6e3debSZane Shelley // clang-format off 455f6e3debSZane Shelley static const std::map<Type, std::string> m = 465f6e3debSZane Shelley { 475f6e3debSZane Shelley {NONE, "NONE"}, 485f6e3debSZane Shelley {FATAL, "FATAL"}, 495f6e3debSZane Shelley {NON_FATAL, "NON_FATAL"}, 505f6e3debSZane Shelley }; 515f6e3debSZane Shelley // clang-format on 525f6e3debSZane Shelley 535f6e3debSZane Shelley nlohmann::json c = {{"Path", iv_path}, {"Type", m.at(iv_type)}}; 545f6e3debSZane Shelley j.emplace_back(c); 555f6e3debSZane Shelley } 565f6e3debSZane Shelley }; 575f6e3debSZane Shelley 585f6e3debSZane Shelley /** 5964791cf7SZane Shelley * @brief Data regarding required service actions based on the hardware error 6064791cf7SZane Shelley * analysis. 6164791cf7SZane Shelley */ 6264791cf7SZane Shelley class ServiceData 6364791cf7SZane Shelley { 6464791cf7SZane Shelley public: 658af9e46fSZane Shelley /** 668af9e46fSZane Shelley * @brief Constructor from components. 678af9e46fSZane Shelley * @param The signature of the root cause attention. 68ca496198SZane Shelley * @param True if the signature list contained a system checkstop attention. 69ca496198SZane Shelley * False, otherwise. 708af9e46fSZane Shelley */ 71ca496198SZane Shelley ServiceData(const libhei::Signature& i_rootCause, bool i_isCheckstop) : 72ca496198SZane Shelley iv_rootCause(i_rootCause), iv_isCheckstop(i_isCheckstop) 738af9e46fSZane Shelley {} 7464791cf7SZane Shelley 7564791cf7SZane Shelley /** @brief Destructor. */ 7664791cf7SZane Shelley ~ServiceData() = default; 7764791cf7SZane Shelley 7864791cf7SZane Shelley /** @brief Copy constructor. */ 7964791cf7SZane Shelley ServiceData(const ServiceData&) = default; 8064791cf7SZane Shelley 8164791cf7SZane Shelley /** @brief Assignment operator. */ 8264791cf7SZane Shelley ServiceData& operator=(const ServiceData&) = default; 8364791cf7SZane Shelley 8464791cf7SZane Shelley private: 858af9e46fSZane Shelley /** The signature of the root cause attention. */ 868af9e46fSZane Shelley const libhei::Signature iv_rootCause; 878af9e46fSZane Shelley 88ca496198SZane Shelley /** True if the signature list contained a system checkstop attention. 89ca496198SZane Shelley * False, otherwise. */ 90ca496198SZane Shelley const bool iv_isCheckstop; 91ca496198SZane Shelley 9264791cf7SZane Shelley /** The list of callouts that will be added to a PEL. */ 93*c85716caSZane Shelley nlohmann::json iv_calloutList = nlohmann::json::array(); 9464791cf7SZane Shelley 955f6e3debSZane Shelley /** The list of hardware guard requests. Some information will be added to 965f6e3debSZane Shelley * the PEL, but the actual guard record will be created after submitting the 975f6e3debSZane Shelley * PEL. */ 985f6e3debSZane Shelley std::vector<std::shared_ptr<Guard>> iv_guardList; 995f6e3debSZane Shelley 10064791cf7SZane Shelley public: 1018af9e46fSZane Shelley /** @return The signature of the root cause attention. */ 1028af9e46fSZane Shelley const libhei::Signature& getRootCause() const 1038af9e46fSZane Shelley { 1048af9e46fSZane Shelley return iv_rootCause; 1058af9e46fSZane Shelley } 1068af9e46fSZane Shelley 107ca496198SZane Shelley /** @return True if the signature list contained a system checkstop 108ca496198SZane Shelley * attention. False, otherwise. */ 109ca496198SZane Shelley bool queryCheckstop() const 110ca496198SZane Shelley { 111ca496198SZane Shelley return iv_isCheckstop; 112ca496198SZane Shelley } 113ca496198SZane Shelley 114*c85716caSZane Shelley /** 115*c85716caSZane Shelley * @brief Add callout information to the callout list. 116*c85716caSZane Shelley * @param The JSON object for this callout. 117*c85716caSZane Shelley */ 118*c85716caSZane Shelley void addCallout(const nlohmann::json& i_callout) 11964791cf7SZane Shelley { 12064791cf7SZane Shelley iv_calloutList.push_back(i_callout); 12164791cf7SZane Shelley } 12264791cf7SZane Shelley 1235f6e3debSZane Shelley /** Add a guard request to the list. */ 1245f6e3debSZane Shelley void addGuard(const std::shared_ptr<Guard>& i_guard) 1255f6e3debSZane Shelley { 1265f6e3debSZane Shelley iv_guardList.push_back(i_guard); 1275f6e3debSZane Shelley } 1285f6e3debSZane Shelley 129*c85716caSZane Shelley /** @brief Accessor to iv_calloutList. */ 130*c85716caSZane Shelley const nlohmann::json& getCalloutList() const 13164791cf7SZane Shelley { 132*c85716caSZane Shelley return iv_calloutList; 13364791cf7SZane Shelley } 1345f6e3debSZane Shelley 1355f6e3debSZane Shelley /** 1365f6e3debSZane Shelley * @brief Iterates the guard list and returns the json attached to each 1375f6e3debSZane Shelley * guard request in the list. 1385f6e3debSZane Shelley * @param o_json The returned json data. 1395f6e3debSZane Shelley */ 1405f6e3debSZane Shelley void getGuardList(nlohmann::json& o_json) const 1415f6e3debSZane Shelley { 1425f6e3debSZane Shelley o_json.clear(); // Ensure we are starting with a clean list. 1435f6e3debSZane Shelley 1445f6e3debSZane Shelley for (const auto& g : iv_guardList) 1455f6e3debSZane Shelley { 1465f6e3debSZane Shelley g->getJson(o_json); 1475f6e3debSZane Shelley } 1485f6e3debSZane Shelley } 14964791cf7SZane Shelley }; 15064791cf7SZane Shelley 151f685afd6SZane Shelley } // namespace analyzer 152