Zane Shelley | 9513582 | 2021-08-23 09:00:05 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <string> |
| 5 | |
| 6 | namespace analyzer |
| 7 | { |
| 8 | |
| 9 | /** |
| 10 | * @brief A service event requiring hardware to be guarded. |
| 11 | */ |
| 12 | class Guard |
| 13 | { |
| 14 | public: |
| 15 | /** Supported guard types. */ |
| 16 | enum class Type |
| 17 | { |
| 18 | NONE, ///< Do not guard |
| 19 | FATAL, ///< Guard on fatal error (cannot recover resource) |
| 20 | NON_FATAL, ///< Guard on non-fatal error (can recover resource) |
| 21 | }; |
| 22 | |
| 23 | public: |
| 24 | /** |
| 25 | * @brief Constructor from components. |
| 26 | * @param i_path The hardware path to guard. |
| 27 | * @param i_type The guard type. |
| 28 | */ |
| 29 | Guard(const std::string& i_path, Type i_type) : |
| 30 | iv_path(i_path), iv_type(i_type) |
| 31 | {} |
| 32 | |
| 33 | private: |
| 34 | /** The hardware path to guard. */ |
| 35 | const std::string iv_path; |
| 36 | |
| 37 | /** The guard type. */ |
| 38 | const Type iv_type; |
| 39 | |
| 40 | public: |
| 41 | /** @brief Writes guard record to persistent storage. */ |
| 42 | void apply() const; |
| 43 | |
| 44 | /** @return A string representation of the guard type enum. */ |
| 45 | std::string getString() const |
| 46 | { |
| 47 | // clang-format off |
| 48 | static const std::map<Type, std::string> m = |
| 49 | { |
| 50 | {Type::NONE, "NONE"}, |
| 51 | {Type::FATAL, "FATAL"}, |
| 52 | {Type::NON_FATAL, "NON_FATAL"}, |
| 53 | }; |
| 54 | // clang-format on |
| 55 | |
| 56 | return m.at(iv_type); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | } // namespace analyzer |