Matt Spinler | 8c0a63f | 2018-03-27 12:27:23 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <vector> |
| 5 | #include "config.h" |
| 6 | |
| 7 | namespace ibm |
| 8 | { |
| 9 | namespace logging |
| 10 | { |
| 11 | namespace policy |
| 12 | { |
| 13 | |
| 14 | |
| 15 | /** |
| 16 | * The details of a policy table entry: |
| 17 | * - search modifier |
| 18 | * - error message |
| 19 | * - common error event ID |
| 20 | */ |
| 21 | struct Details |
| 22 | { |
| 23 | std::string modifier; |
| 24 | std::string msg; |
| 25 | std::string ceid; |
| 26 | }; |
| 27 | |
| 28 | using DetailsList = std::vector<Details>; |
| 29 | using PolicyMap = std::map<std::string, DetailsList>; |
| 30 | |
| 31 | /** |
| 32 | * @class Table |
| 33 | * |
| 34 | * This class wraps the error policy table data, and provides the |
| 35 | * ability to find a policy table entry based on the error and a |
| 36 | * search modifier. This data contains additional information |
| 37 | * about error logs and may be system specific. |
| 38 | */ |
| 39 | class Table |
| 40 | { |
| 41 | public: |
| 42 | |
| 43 | Table() = delete; |
| 44 | ~Table() = default; |
| 45 | Table(const Table&) = default; |
| 46 | Table& operator=(const Table&) = default; |
| 47 | Table(Table&&) = default; |
| 48 | Table& operator=(Table&&) = default; |
| 49 | |
| 50 | /** |
| 51 | * Constructor |
| 52 | * |
| 53 | * @param[in] jsonFile - the path to the policy JSON. |
| 54 | */ |
| 55 | explicit Table(const std::string& jsonFile); |
| 56 | |
| 57 | /** |
| 58 | * Says if the JSON has been loaded successfully. |
| 59 | * |
| 60 | * @return bool |
| 61 | */ |
| 62 | inline bool isLoaded() const |
| 63 | { |
| 64 | return loaded; |
| 65 | } |
| 66 | |
| 67 | private: |
| 68 | |
| 69 | /** |
| 70 | * Loads the JSON data into the PolicyMap map |
| 71 | * |
| 72 | * @param[in] jsonFile - the path to the .json file |
| 73 | */ |
| 74 | void load(const std::string& jsonFile); |
| 75 | |
| 76 | /** |
| 77 | * Reflects if the JSON was successfully loaded or not. |
| 78 | */ |
| 79 | bool loaded = false; |
| 80 | |
| 81 | /** |
| 82 | * The policy table |
| 83 | */ |
| 84 | PolicyMap policies; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | } |
| 89 | } |
| 90 | } |