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