Remove the static OpenBMC Message Registry file

This change removes the static OpenBMC Message Registry file and
replaces it with a compile-time structure.

Tested:
Verified the OpenBMC Message registry is correctly returned from
the existing endpoints without using the static files.

Change-Id: I60ab3ce0d23c9ac7e91ebb85f445fb9ca731983d
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/redfish-core/lib/message_registries.hpp b/redfish-core/lib/message_registries.hpp
index e44e97d..31412f3 100644
--- a/redfish-core/lib/message_registries.hpp
+++ b/redfish-core/lib/message_registries.hpp
@@ -18,6 +18,7 @@
 #include "node.hpp"
 #include "registries.hpp"
 #include "registries/base_message_registry.hpp"
+#include "registries/openbmc_message_registry.hpp"
 
 namespace redfish
 {
@@ -193,4 +194,122 @@
     }
 };
 
+class OpenBMCMessageRegistryFile : public Node
+{
+  public:
+    template <typename CrowApp>
+    OpenBMCMessageRegistryFile(CrowApp &app) :
+        Node(app, "/redfish/v1/Registries/OpenBMC/")
+    {
+        entityPrivileges = {
+            {boost::beast::http::verb::get, {{"Login"}}},
+            {boost::beast::http::verb::head, {{"Login"}}},
+            {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::put, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
+    }
+
+  private:
+    void doGet(crow::Response &res, const crow::Request &req,
+               const std::vector<std::string> &params) override
+    {
+        std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
+        asyncResp->res.jsonValue["@odata.id"] =
+            "/redfish/v1/Registries/OpenBMC";
+        asyncResp->res.jsonValue["@odata.type"] =
+            "#MessageRegistryFile.v1_1_0.MessageRegistryFile";
+        asyncResp->res.jsonValue["@odata.context"] =
+            "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile";
+        asyncResp->res.jsonValue["Name"] = "Open BMC Message Registry File";
+        asyncResp->res.jsonValue["Description"] =
+            "Open BMC Message Registry File Location";
+        asyncResp->res.jsonValue["Id"] =
+            message_registries::openbmc::header.registryPrefix;
+        asyncResp->res.jsonValue["Registry"] =
+            message_registries::openbmc::header.id;
+        nlohmann::json &messageRegistryLanguageArray =
+            asyncResp->res.jsonValue["Languages"];
+        messageRegistryLanguageArray = nlohmann::json::array();
+        messageRegistryLanguageArray.push_back({"en"});
+        asyncResp->res.jsonValue["Languages@odata.count"] =
+            messageRegistryLanguageArray.size();
+        nlohmann::json &messageRegistryLocationArray =
+            asyncResp->res.jsonValue["Location"];
+        messageRegistryLocationArray = nlohmann::json::array();
+        messageRegistryLocationArray.push_back(
+            {{"Language", "en"},
+             {"Uri", "/redfish/v1/Registries/OpenBMC/OpenBMC"}});
+        asyncResp->res.jsonValue["Location@odata.count"] =
+            messageRegistryLocationArray.size();
+    }
+};
+
+class OpenBMCMessageRegistry : public Node
+{
+  public:
+    template <typename CrowApp>
+    OpenBMCMessageRegistry(CrowApp &app) :
+        Node(app, "/redfish/v1/Registries/OpenBMC/OpenBMC/")
+    {
+        entityPrivileges = {
+            {boost::beast::http::verb::get, {{"Login"}}},
+            {boost::beast::http::verb::head, {{"Login"}}},
+            {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::put, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
+    }
+
+  private:
+    void doGet(crow::Response &res, const crow::Request &req,
+               const std::vector<std::string> &params) override
+    {
+        std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
+        asyncResp->res.jsonValue["@Redfish.Copyright"] =
+            message_registries::openbmc::header.copyright;
+        asyncResp->res.jsonValue["@odata.type"] =
+            message_registries::openbmc::header.type;
+        asyncResp->res.jsonValue["Id"] = message_registries::openbmc::header.id;
+        asyncResp->res.jsonValue["Name"] =
+            message_registries::openbmc::header.name;
+        asyncResp->res.jsonValue["Language"] =
+            message_registries::openbmc::header.language;
+        asyncResp->res.jsonValue["Description"] =
+            message_registries::openbmc::header.description;
+        asyncResp->res.jsonValue["RegistryPrefix"] =
+            message_registries::openbmc::header.registryPrefix;
+        asyncResp->res.jsonValue["RegistryVersion"] =
+            message_registries::openbmc::header.registryVersion;
+        asyncResp->res.jsonValue["OwningEntity"] =
+            message_registries::openbmc::header.owningEntity;
+        nlohmann::json &messageArray = asyncResp->res.jsonValue["Messages"];
+        messageArray = nlohmann::json::array();
+
+        // Go through the Message Registry and populate each Message
+        for (const message_registries::MessageEntry &message :
+             message_registries::openbmc::registry)
+        {
+            messageArray.push_back(
+                {{message.first,
+                  {{"Description", message.second.description},
+                   {"Message", message.second.message},
+                   {"Severity", message.second.severity},
+                   {"NumberOfArgs", message.second.numberOfArgs},
+                   {"Resolution", message.second.resolution}}}});
+            if (message.second.numberOfArgs > 0)
+            {
+                nlohmann::json &messageParamArray =
+                    messageArray.back()[message.first]["ParamTypes"];
+                for (int i = 0; i < message.second.numberOfArgs; i++)
+                {
+                    messageParamArray.push_back(message.second.paramTypes[i]);
+                }
+            }
+        }
+    }
+};
+
 } // namespace redfish