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.cpp b/policy_table.cpp
new file mode 100644
index 0000000..247ff4f
--- /dev/null
+++ b/policy_table.cpp
@@ -0,0 +1,81 @@
+/**
+ * Copyright © 2018 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <experimental/filesystem>
+#include <fstream>
+#include <nlohmann/json.hpp>
+#include <phosphor-logging/log.hpp>
+#include "policy_table.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+namespace policy
+{
+
+namespace fs = std::experimental::filesystem;
+using namespace phosphor::logging;
+
+Table::Table(const std::string& jsonFile)
+{
+    if (fs::exists(jsonFile))
+    {
+        load(jsonFile);
+    }
+    else
+    {
+        log<level::INFO>("Policy table JSON file does not exist",
+                entry("FILE=%s", jsonFile.c_str()));
+    }
+}
+
+void Table::load(const std::string& jsonFile)
+{
+    try
+    {
+        std::ifstream file{jsonFile};
+
+        auto json = nlohmann::json::parse(file, nullptr, true);
+
+        for (const auto& policy : json)
+        {
+            DetailsList detailsList;
+
+            for (const auto& details : policy["dtls"])
+            {
+                Details d;
+                d.modifier = details["mod"];
+                d.msg = details["msg"];
+                d.ceid = details["CEID"];
+                detailsList.emplace_back(std::move(d));
+            }
+            policies.emplace(policy["err"], std::move(detailsList));
+        }
+
+        loaded = true;
+    }
+    catch (std::exception& e)
+    {
+        log<level::ERR>("Failed loading policy table json file",
+                entry("FILE=%s", jsonFile.c_str()),
+                entry("ERROR=%s", e.what()));
+        loaded = false;
+    }
+}
+
+}
+}
+}