Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <analyzer/service_data.hpp> |
| 4 | |
| 5 | namespace analyzer |
| 6 | { |
| 7 | |
| 8 | /** @brief An abstract class for service event resolutions. */ |
| 9 | class Resolution |
| 10 | { |
| 11 | public: |
| 12 | /** @brief Pure virtual destructor. */ |
| 13 | virtual ~Resolution() = 0; |
| 14 | |
| 15 | public: |
| 16 | /** |
| 17 | * @brief Resolves the service actions required by this resolution. |
| 18 | * @param io_sd An object containing the service data collected during |
| 19 | * hardware error analysis. |
| 20 | */ |
| 21 | virtual void resolve(ServiceData& io_sd) const = 0; |
| 22 | }; |
| 23 | |
| 24 | // Pure virtual destructor must be defined. |
| 25 | inline Resolution::~Resolution() {} |
| 26 | |
| 27 | /** @brief Resolves a hardware callout service event. */ |
| 28 | class HardwareCalloutResolution : public Resolution |
| 29 | { |
| 30 | public: |
| 31 | /** |
| 32 | * @brief Constructor from components. |
| 33 | * @param i_path The devtree path of a guardable unit relative to a |
| 34 | * chip. An empty string refers to the chip itself. |
| 35 | * @param i_priority The callout priority. |
| 36 | * @param i_guard The guard type for this callout. |
| 37 | */ |
| 38 | HardwareCalloutResolution(const std::string& i_path, |
| 39 | Callout::Priority i_priority, |
| 40 | Guard::Type i_guard) : |
| 41 | iv_path(i_path), |
| 42 | iv_priority(i_priority), iv_guard(i_guard) |
| 43 | {} |
| 44 | |
| 45 | private: |
| 46 | /** The devtree path of a guardable unit relative to a chip. An empty string |
| 47 | * refers to the chip itself. */ |
| 48 | const std::string iv_path; |
| 49 | |
| 50 | /** The callout priority. */ |
| 51 | const Callout::Priority iv_priority; |
| 52 | |
| 53 | /** The guard type for this callout. */ |
| 54 | const Guard::Type iv_guard; |
| 55 | |
| 56 | public: |
| 57 | void resolve(ServiceData& io_sd) const override; |
| 58 | }; |
| 59 | |
| 60 | /** @brief Resolves a procedure callout service event. */ |
| 61 | class ProcedureCalloutResolution : public Resolution |
| 62 | { |
| 63 | public: |
| 64 | /** |
| 65 | * @brief Constructor from components. |
| 66 | * @param i_procedure The procedure callout type. |
| 67 | * @param i_priority The callout priority. |
| 68 | */ |
| 69 | ProcedureCalloutResolution(ProcedureCallout::Type i_procedure, |
| 70 | Callout::Priority i_priority) : |
| 71 | iv_procedure(i_procedure), |
| 72 | iv_priority(i_priority) |
| 73 | {} |
| 74 | |
| 75 | private: |
| 76 | /** The procedure callout type. */ |
| 77 | const ProcedureCallout::Type iv_procedure; |
| 78 | |
| 79 | /** The callout priority. */ |
| 80 | const Callout::Priority iv_priority; |
| 81 | |
| 82 | public: |
| 83 | void resolve(ServiceData& io_sd) const override |
| 84 | { |
| 85 | // Simply add the procedure to the callout list. |
| 86 | io_sd.addCallout( |
| 87 | std::make_shared<ProcedureCallout>(iv_procedure, iv_priority)); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * @brief Links two resolutions into a single resolution. The resolutions will |
| 93 | * will be resolved in the order they are inputted into the constructor. |
| 94 | */ |
| 95 | class LinkResolution : public Resolution |
| 96 | { |
| 97 | public: |
| 98 | /** |
| 99 | * @brief Constructor from components. |
| 100 | * @param i_first The first resolution. |
| 101 | * @param i_second The second resolution. |
| 102 | */ |
| 103 | LinkResolution(const std::shared_ptr<Resolution>& i_first, |
| 104 | const std::shared_ptr<Resolution>& i_second) : |
| 105 | iv_first(i_first), |
| 106 | iv_second(i_second) |
| 107 | {} |
| 108 | |
| 109 | private: |
| 110 | /** The first resolution. */ |
| 111 | const std::shared_ptr<Resolution> iv_first; |
| 112 | |
| 113 | /** The second resolution. */ |
| 114 | const std::shared_ptr<Resolution> iv_second; |
| 115 | |
| 116 | public: |
| 117 | void resolve(ServiceData& io_sd) const override |
| 118 | { |
| 119 | iv_first->resolve(io_sd); |
| 120 | iv_second->resolve(io_sd); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | } // namespace analyzer |