Add policy::Table class
This class holds the error log policy data defined by
IBM's service people. The raw data is stored in a JSON
file on the BMC, and loaded into the class on construction.
The policy data is a map of error messages (i.e. the
xyz.openbmc_project.Foo.Error.Bar strings) to a list of
policy details structures.
Each details structure has:
* a search modifier - used to find the specific details
entry for a specific error log message.
* a message - a customer facing description of the error
* an event ID - an ID defined by IBM that can be used to
locate information about the error online.
An example of an entry of the JSON data it consumes is:
{
"dtls":[
{
"CEID":"ID 1",
"mod":"mod 1",
"msg":"Error 1"
},
{
"CEID":"ID 2",
"mod":"mod 2",
"msg":"Error 2 "
}
],
"err":"xyz.openbmc_project.Error.Test1"
}
A future commit will add the ability to find an entry.
Change-Id: I9869c15799914acf9cbc9d91ff714edb6e2512ef
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/policy_table.hpp b/policy_table.hpp
new file mode 100644
index 0000000..b6fade3
--- /dev/null
+++ b/policy_table.hpp
@@ -0,0 +1,90 @@
+#pragma once
+
+#include <map>
+#include <vector>
+#include "config.h"
+
+namespace ibm
+{
+namespace logging
+{
+namespace policy
+{
+
+
+/**
+ * The details of a policy table entry:
+ * - search modifier
+ * - error message
+ * - common error event ID
+ */
+struct Details
+{
+ std::string modifier;
+ std::string msg;
+ std::string ceid;
+};
+
+using DetailsList = std::vector<Details>;
+using PolicyMap = std::map<std::string, DetailsList>;
+
+/**
+ * @class Table
+ *
+ * This class wraps the error policy table data, and provides the
+ * ability to find a policy table entry based on the error and a
+ * search modifier. This data contains additional information
+ * about error logs and may be system specific.
+ */
+class Table
+{
+ public:
+
+ Table() = delete;
+ ~Table() = default;
+ Table(const Table&) = default;
+ Table& operator=(const Table&) = default;
+ Table(Table&&) = default;
+ Table& operator=(Table&&) = default;
+
+ /**
+ * Constructor
+ *
+ * @param[in] jsonFile - the path to the policy JSON.
+ */
+ explicit Table(const std::string& jsonFile);
+
+ /**
+ * Says if the JSON has been loaded successfully.
+ *
+ * @return bool
+ */
+ inline bool isLoaded() const
+ {
+ return loaded;
+ }
+
+ private:
+
+ /**
+ * Loads the JSON data into the PolicyMap map
+ *
+ * @param[in] jsonFile - the path to the .json file
+ */
+ void load(const std::string& jsonFile);
+
+ /**
+ * Reflects if the JSON was successfully loaded or not.
+ */
+ bool loaded = false;
+
+ /**
+ * The policy table
+ */
+ PolicyMap policies;
+};
+
+
+}
+}
+}