1f685afd6SZane Shelley #pragma once 2f685afd6SZane Shelley 3f685afd6SZane Shelley #include <nlohmann/json.hpp> 4f685afd6SZane Shelley 5f685afd6SZane Shelley namespace analyzer 6f685afd6SZane Shelley { 7f685afd6SZane Shelley 8f685afd6SZane Shelley /** @brief An abstract class for service event, also known as a callout. */ 9f685afd6SZane Shelley class Callout 10f685afd6SZane Shelley { 11f685afd6SZane Shelley public: 12f685afd6SZane Shelley /** Each callout will have a priority indicating when to issue the required 13f685afd6SZane Shelley * service action. Details below. */ 14f685afd6SZane Shelley enum Priority 15f685afd6SZane Shelley { 16f685afd6SZane Shelley /** Serivce is mandatory. */ 17f685afd6SZane Shelley HIGH, 18f685afd6SZane Shelley 19f685afd6SZane Shelley /** Serivce medium priority callouts one at a time, in order, until the 20f685afd6SZane Shelley * issue is resolved. */ 21f685afd6SZane Shelley MED, 22f685afd6SZane Shelley 23f685afd6SZane Shelley MED_A, ///< Same as PRI_MED, except replace all A's as a group. 24f685afd6SZane Shelley MED_B, ///< Same as PRI_MED, except replace all B's as a group. 25f685afd6SZane Shelley MED_C, ///< Same as PRI_MED, except replace all C's as a group. 26f685afd6SZane Shelley 27f685afd6SZane Shelley /** If servicing all high and medium priority callouts did not resolve 28f685afd6SZane Shelley * the issue, service low priority callouts one at a time, in order, 29f685afd6SZane Shelley * until the issue is resolved. */ 30f685afd6SZane Shelley LOW, 31f685afd6SZane Shelley }; 32f685afd6SZane Shelley 33f685afd6SZane Shelley public: 34f685afd6SZane Shelley /** @brief Pure virtual destructor. */ 35f685afd6SZane Shelley virtual ~Callout() = 0; 36f685afd6SZane Shelley 37f685afd6SZane Shelley protected: 38f685afd6SZane Shelley /** 39f685afd6SZane Shelley * @brief Constructor from components. 40f685afd6SZane Shelley * @param p The callout priority. 41f685afd6SZane Shelley */ 42f685afd6SZane Shelley explicit Callout(Priority p) : iv_priority(p) {} 43f685afd6SZane Shelley 44f685afd6SZane Shelley private: 45f685afd6SZane Shelley /** The callout priority. */ 46f685afd6SZane Shelley const Priority iv_priority; 47f685afd6SZane Shelley 48f685afd6SZane Shelley protected: 49f685afd6SZane Shelley /** 50f685afd6SZane Shelley * @brief Appends the callout priority to the end of the given json object. 51f685afd6SZane Shelley * @param j The json object for a single callout. 52f685afd6SZane Shelley */ 53f685afd6SZane Shelley void addPriority(nlohmann::json& j) const 54f685afd6SZane Shelley { 55f685afd6SZane Shelley // clang-format off 56f685afd6SZane Shelley static const std::map<Priority, std::string> m = 57f685afd6SZane Shelley { 58f685afd6SZane Shelley {HIGH, "H"}, 59f685afd6SZane Shelley {MED, "M"}, 60f685afd6SZane Shelley {MED_A, "A"}, 61f685afd6SZane Shelley {MED_B, "B"}, 62f685afd6SZane Shelley {MED_C, "C"}, 63f685afd6SZane Shelley {LOW, "L"}, 64f685afd6SZane Shelley }; 65f685afd6SZane Shelley // clang-format on 66f685afd6SZane Shelley 67f685afd6SZane Shelley j.emplace("Priority", m.at(iv_priority)); 68f685afd6SZane Shelley } 69f685afd6SZane Shelley 70f685afd6SZane Shelley public: 71f685afd6SZane Shelley /** 72f685afd6SZane Shelley * @brief Appends a json object representing this callout to the end of the 73f685afd6SZane Shelley * given json object. 74f685afd6SZane Shelley * @param j The json object containing all current callouts for a PEL. 75f685afd6SZane Shelley */ 76f685afd6SZane Shelley virtual void getJson(nlohmann::json&) const = 0; 77f685afd6SZane Shelley }; 78f685afd6SZane Shelley 79f685afd6SZane Shelley // Pure virtual destructor must be defined. 80f685afd6SZane Shelley inline Callout::~Callout() {} 81f685afd6SZane Shelley 82f685afd6SZane Shelley /** @brief A service event requiring hardware replacement. */ 83f685afd6SZane Shelley class HardwareCallout : public Callout 84f685afd6SZane Shelley { 85f685afd6SZane Shelley public: 86f685afd6SZane Shelley /** 87f685afd6SZane Shelley * @brief Constructor from components. 88f685afd6SZane Shelley * @param i_locationCode The location code of the hardware callout. 89f685afd6SZane Shelley * @param i_priority The callout priority. 90f685afd6SZane Shelley */ 91f685afd6SZane Shelley HardwareCallout(const std::string& i_locationCode, Priority i_priority) : 92f685afd6SZane Shelley Callout(i_priority), iv_locationCode(i_locationCode) 93f685afd6SZane Shelley {} 94f685afd6SZane Shelley 95f685afd6SZane Shelley private: 96f685afd6SZane Shelley /** The hardware location code. */ 97f685afd6SZane Shelley const std::string iv_locationCode; 98f685afd6SZane Shelley 99f685afd6SZane Shelley public: 100f685afd6SZane Shelley void getJson(nlohmann::json& j) const override 101f685afd6SZane Shelley { 102f685afd6SZane Shelley nlohmann::json c = {{"LocationCode", iv_locationCode}}; 103f685afd6SZane Shelley addPriority(c); 104f685afd6SZane Shelley j.emplace_back(c); 105f685afd6SZane Shelley } 106f685afd6SZane Shelley }; 107f685afd6SZane Shelley 108f685afd6SZane Shelley /** 109f685afd6SZane Shelley * @brief A service event requiring a special procedure to be handled by a 110f685afd6SZane Shelley * service engineer. 111f685afd6SZane Shelley */ 112f685afd6SZane Shelley class ProcedureCallout : public Callout 113f685afd6SZane Shelley { 114f685afd6SZane Shelley public: 115f685afd6SZane Shelley /** Supported service procedures. */ 116f685afd6SZane Shelley enum Procedure 117f685afd6SZane Shelley { 118f685afd6SZane Shelley NEXTLVL, ///< Contact next level support. 119f685afd6SZane Shelley }; 120f685afd6SZane Shelley 121f685afd6SZane Shelley public: 122f685afd6SZane Shelley /** 123f685afd6SZane Shelley * @brief Constructor from components. 124f685afd6SZane Shelley * @param i_procedure The location code of the hardware callout. 125f685afd6SZane Shelley * @param i_priority The callout priority. 126f685afd6SZane Shelley */ 127f685afd6SZane Shelley ProcedureCallout(Procedure i_procedure, Priority i_priority) : 128f685afd6SZane Shelley Callout(i_priority), iv_procedure(i_procedure) 129f685afd6SZane Shelley {} 130f685afd6SZane Shelley 131f685afd6SZane Shelley private: 132f685afd6SZane Shelley /** The callout priority. */ 133f685afd6SZane Shelley const Procedure iv_procedure; 134f685afd6SZane Shelley 135f685afd6SZane Shelley public: 136f685afd6SZane Shelley void getJson(nlohmann::json& j) const override 137f685afd6SZane Shelley { 138f685afd6SZane Shelley // clang-format off 139f685afd6SZane Shelley static const std::map<Procedure, std::string> m = 140f685afd6SZane Shelley { 141f685afd6SZane Shelley {NEXTLVL, "NEXTLVL"}, 142f685afd6SZane Shelley }; 143f685afd6SZane Shelley // clang-format on 144f685afd6SZane Shelley 145f685afd6SZane Shelley nlohmann::json c = {{"Procedure", m.at(iv_procedure)}}; 146f685afd6SZane Shelley addPriority(c); 147f685afd6SZane Shelley j.emplace_back(c); 148f685afd6SZane Shelley } 149f685afd6SZane Shelley }; 150f685afd6SZane Shelley 15164791cf7SZane Shelley /** 152*5f6e3debSZane Shelley * @brief A service event requiring hardware to be guarded. 153*5f6e3debSZane Shelley */ 154*5f6e3debSZane Shelley class Guard 155*5f6e3debSZane Shelley { 156*5f6e3debSZane Shelley public: 157*5f6e3debSZane Shelley /** Supported guard types. */ 158*5f6e3debSZane Shelley enum Type 159*5f6e3debSZane Shelley { 160*5f6e3debSZane Shelley NONE, ///< Do not guard 161*5f6e3debSZane Shelley FATAL, ///< Guard on fatal error (cannot recover resource) 162*5f6e3debSZane Shelley NON_FATAL, ///< Guard on non-fatal error (can recover resource) 163*5f6e3debSZane Shelley }; 164*5f6e3debSZane Shelley 165*5f6e3debSZane Shelley public: 166*5f6e3debSZane Shelley /** 167*5f6e3debSZane Shelley * @brief Constructor from components. 168*5f6e3debSZane Shelley * @param i_path The hardware path to guard. 169*5f6e3debSZane Shelley * @param i_type The guard type. 170*5f6e3debSZane Shelley */ 171*5f6e3debSZane Shelley Guard(const std::string& i_path, Type i_type) : 172*5f6e3debSZane Shelley iv_path(i_path), iv_type(i_type) 173*5f6e3debSZane Shelley {} 174*5f6e3debSZane Shelley 175*5f6e3debSZane Shelley private: 176*5f6e3debSZane Shelley /** The hardware path to guard. */ 177*5f6e3debSZane Shelley const std::string iv_path; 178*5f6e3debSZane Shelley 179*5f6e3debSZane Shelley /** The guard type. */ 180*5f6e3debSZane Shelley const Type iv_type; 181*5f6e3debSZane Shelley 182*5f6e3debSZane Shelley public: 183*5f6e3debSZane Shelley void getJson(nlohmann::json& j) const 184*5f6e3debSZane Shelley { 185*5f6e3debSZane Shelley // clang-format off 186*5f6e3debSZane Shelley static const std::map<Type, std::string> m = 187*5f6e3debSZane Shelley { 188*5f6e3debSZane Shelley {NONE, "NONE"}, 189*5f6e3debSZane Shelley {FATAL, "FATAL"}, 190*5f6e3debSZane Shelley {NON_FATAL, "NON_FATAL"}, 191*5f6e3debSZane Shelley }; 192*5f6e3debSZane Shelley // clang-format on 193*5f6e3debSZane Shelley 194*5f6e3debSZane Shelley nlohmann::json c = {{"Path", iv_path}, {"Type", m.at(iv_type)}}; 195*5f6e3debSZane Shelley j.emplace_back(c); 196*5f6e3debSZane Shelley } 197*5f6e3debSZane Shelley }; 198*5f6e3debSZane Shelley 199*5f6e3debSZane Shelley /** 20064791cf7SZane Shelley * @brief Data regarding required service actions based on the hardware error 20164791cf7SZane Shelley * analysis. 20264791cf7SZane Shelley */ 20364791cf7SZane Shelley class ServiceData 20464791cf7SZane Shelley { 20564791cf7SZane Shelley public: 20664791cf7SZane Shelley /** @brief Default constructor. */ 20764791cf7SZane Shelley ServiceData() = default; 20864791cf7SZane Shelley 20964791cf7SZane Shelley /** @brief Destructor. */ 21064791cf7SZane Shelley ~ServiceData() = default; 21164791cf7SZane Shelley 21264791cf7SZane Shelley /** @brief Copy constructor. */ 21364791cf7SZane Shelley ServiceData(const ServiceData&) = default; 21464791cf7SZane Shelley 21564791cf7SZane Shelley /** @brief Assignment operator. */ 21664791cf7SZane Shelley ServiceData& operator=(const ServiceData&) = default; 21764791cf7SZane Shelley 21864791cf7SZane Shelley private: 21964791cf7SZane Shelley /** The list of callouts that will be added to a PEL. */ 22064791cf7SZane Shelley std::vector<std::shared_ptr<Callout>> iv_calloutList; 22164791cf7SZane Shelley 222*5f6e3debSZane Shelley /** The list of hardware guard requests. Some information will be added to 223*5f6e3debSZane Shelley * the PEL, but the actual guard record will be created after submitting the 224*5f6e3debSZane Shelley * PEL. */ 225*5f6e3debSZane Shelley std::vector<std::shared_ptr<Guard>> iv_guardList; 226*5f6e3debSZane Shelley 22764791cf7SZane Shelley public: 228*5f6e3debSZane Shelley /** Add a callout to the list. */ 22964791cf7SZane Shelley void addCallout(const std::shared_ptr<Callout>& i_callout) 23064791cf7SZane Shelley { 23164791cf7SZane Shelley iv_calloutList.push_back(i_callout); 23264791cf7SZane Shelley } 23364791cf7SZane Shelley 234*5f6e3debSZane Shelley /** Add a guard request to the list. */ 235*5f6e3debSZane Shelley void addGuard(const std::shared_ptr<Guard>& i_guard) 236*5f6e3debSZane Shelley { 237*5f6e3debSZane Shelley iv_guardList.push_back(i_guard); 238*5f6e3debSZane Shelley } 239*5f6e3debSZane Shelley 24064791cf7SZane Shelley /** 24164791cf7SZane Shelley * @brief Iterates the callout list and returns the json attached to each 24264791cf7SZane Shelley * callout in the list. 24364791cf7SZane Shelley * @param o_json The returned json data. 24464791cf7SZane Shelley */ 24564791cf7SZane Shelley void getCalloutList(nlohmann::json& o_json) const 24664791cf7SZane Shelley { 24764791cf7SZane Shelley o_json.clear(); // Ensure we are starting with a clean list. 24864791cf7SZane Shelley 24964791cf7SZane Shelley for (const auto& c : iv_calloutList) 25064791cf7SZane Shelley { 25164791cf7SZane Shelley c->getJson(o_json); 25264791cf7SZane Shelley } 25364791cf7SZane Shelley } 254*5f6e3debSZane Shelley 255*5f6e3debSZane Shelley /** 256*5f6e3debSZane Shelley * @brief Iterates the guard list and returns the json attached to each 257*5f6e3debSZane Shelley * guard request in the list. 258*5f6e3debSZane Shelley * @param o_json The returned json data. 259*5f6e3debSZane Shelley */ 260*5f6e3debSZane Shelley void getGuardList(nlohmann::json& o_json) const 261*5f6e3debSZane Shelley { 262*5f6e3debSZane Shelley o_json.clear(); // Ensure we are starting with a clean list. 263*5f6e3debSZane Shelley 264*5f6e3debSZane Shelley for (const auto& g : iv_guardList) 265*5f6e3debSZane Shelley { 266*5f6e3debSZane Shelley g->getJson(o_json); 267*5f6e3debSZane Shelley } 268*5f6e3debSZane Shelley } 26964791cf7SZane Shelley }; 27064791cf7SZane Shelley 271f685afd6SZane Shelley } // namespace analyzer 272