blob: a44bf0b6f331d5b33c6f173b902908255c51f55a [file] [log] [blame]
Matt Spinler8c0a63f2018-03-27 12:27:23 -05001#pragma once
2
Matt Spinler3c9e3012018-03-27 12:36:53 -05003#include <experimental/optional>
Matt Spinler8c0a63f2018-03-27 12:27:23 -05004#include <map>
5#include <vector>
6#include "config.h"
7
8namespace ibm
9{
10namespace logging
11{
12namespace 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 */
22struct Details
23{
24 std::string modifier;
25 std::string msg;
26 std::string ceid;
27};
28
29using DetailsList = std::vector<Details>;
Matt Spinler3c9e3012018-03-27 12:36:53 -050030using DetailsReference = std::reference_wrapper<const Details>;
31
Matt Spinler8c0a63f2018-03-27 12:27:23 -050032using PolicyMap = std::map<std::string, DetailsList>;
33
Matt Spinler3c9e3012018-03-27 12:36:53 -050034namespace optional_ns = std::experimental;
35
Matt Spinler8c0a63f2018-03-27 12:27:23 -050036/**
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 */
44class 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 Spinler3c9e3012018-03-27 12:36:53 -050072 /**
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 Spinler8c0a63f2018-03-27 12:27:23 -050086 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}