blob: 41713cefa1942299af2ad531b1d7b472c8187672 [file] [log] [blame]
Jason M. Bills70304cb2019-03-27 12:03:59 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Jason M. Bills70304cb2019-03-27 12:03:59 -070018#include "registries.hpp"
19#include "registries/base_message_registry.hpp"
Jason M. Billsfbe83782019-03-27 14:14:53 -070020#include "registries/openbmc_message_registry.hpp"
Sunitha Harish74eec262020-06-25 10:00:01 -050021#include "registries/resource_event_message_registry.hpp"
James Feiste51c7102020-03-17 10:38:18 -070022#include "registries/task_event_message_registry.hpp"
Jason M. Bills70304cb2019-03-27 12:03:59 -070023
John Edward Broadbent7e860f12021-04-08 15:57:16 -070024#include <app.hpp>
25
Jason M. Bills70304cb2019-03-27 12:03:59 -070026namespace redfish
27{
28
John Edward Broadbent7e860f12021-04-08 15:57:16 -070029inline void requestRoutesMessageRegistryFileCollection(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070030{
Jason M. Bills70304cb2019-03-27 12:03:59 -070031 /**
32 * Functions triggers appropriate requests on DBus
33 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -070034 BMCWEB_ROUTE(app, "/redfish/v1/Registries/")
35 .privileges({"Login"})
36 .methods(boost::beast::http::verb::get)(
37 [](const crow::Request&,
38 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
39 // Collections don't include the static data added by SubRoute
40 // because it has a duplicate entry for members
Ed Tanous14c8aee2019-06-13 13:39:16 -070041
John Edward Broadbent7e860f12021-04-08 15:57:16 -070042 asyncResp->res.jsonValue = {
43 {"@odata.type", "#MessageRegistryFileCollection."
44 "MessageRegistryFileCollection"},
45 {"@odata.id", "/redfish/v1/Registries"},
46 {"Name", "MessageRegistryFile Collection"},
47 {"Description", "Collection of MessageRegistryFiles"},
48 {"Members@odata.count", 4},
49 {"Members",
50 {{{"@odata.id", "/redfish/v1/Registries/Base"}},
51 {{"@odata.id", "/redfish/v1/Registries/TaskEvent"}},
52 {{"@odata.id", "/redfish/v1/Registries/ResourceEvent"}},
53 {{"@odata.id", "/redfish/v1/Registries/OpenBMC"}}}}};
54 });
55}
Jason M. Bills70304cb2019-03-27 12:03:59 -070056
John Edward Broadbent7e860f12021-04-08 15:57:16 -070057inline void requestRoutesMessageRegistryFile(App& app)
Jason M. Bills70304cb2019-03-27 12:03:59 -070058{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070059 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/")
60 .privileges({"Login"})
61 .methods(boost::beast::http::verb::get)(
62 [](const crow::Request&,
63 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
64 const std::string& registry) {
65 const message_registries::Header* header;
66 std::string dmtf = "DMTF ";
67 const char* url = nullptr;
Jason M. Bills70304cb2019-03-27 12:03:59 -070068
John Edward Broadbent7e860f12021-04-08 15:57:16 -070069 if (registry == "Base")
Jason M. Bills70304cb2019-03-27 12:03:59 -070070 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -070071 header = &message_registries::base::header;
72 url = message_registries::base::url;
Jason M. Bills70304cb2019-03-27 12:03:59 -070073 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -070074 else if (registry == "TaskEvent")
75 {
76 header = &message_registries::task_event::header;
77 url = message_registries::task_event::url;
78 }
79 else if (registry == "OpenBMC")
80 {
81 header = &message_registries::openbmc::header;
82 dmtf.clear();
83 }
84 else if (registry == "ResourceEvent")
85 {
86 header = &message_registries::resource_event::header;
87 url = message_registries::resource_event::url;
88 }
89 else
90 {
91 messages::resourceNotFound(
92 asyncResp->res,
93 "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
94 registry);
95 return;
96 }
97
98 asyncResp->res.jsonValue = {
99 {"@odata.id", "/redfish/v1/Registries/" + registry},
100 {"@odata.type",
101 "#MessageRegistryFile.v1_1_0.MessageRegistryFile"},
102 {"Name", registry + " Message Registry File"},
103 {"Description",
104 dmtf + registry + " Message Registry File Location"},
105 {"Id", header->registryPrefix},
106 {"Registry", header->id},
107 {"Languages", {"en"}},
108 {"Languages@odata.count", 1},
109 {"Location",
110 {{{"Language", "en"},
111 {"Uri", "/redfish/v1/Registries/" + registry + "/" +
112 registry}}}},
113 {"Location@odata.count", 1}};
114
115 if (url != nullptr)
116 {
117 asyncResp->res.jsonValue["Location"][0]["PublicationUri"] =
118 url;
119 }
120 });
121}
122
123inline void requestRoutesMessageRegistry(App& app)
124{
125 BMCWEB_ROUTE(app, "/redfish/v1/Registries/<str>/<str>/")
126 .privileges({"Login"})
127 .methods(boost::beast::http::verb::get)(
128 [](const crow::Request&,
129 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
130 const std::string& registry, const std::string& registry1)
131
132 {
133 const message_registries::Header* header;
134 std::vector<const message_registries::MessageEntry*>
135 registryEntries;
136 if (registry == "Base")
137 {
138 header = &message_registries::base::header;
139 for (const message_registries::MessageEntry& entry :
140 message_registries::base::registry)
141 {
142 registryEntries.emplace_back(&entry);
143 }
144 }
145 else if (registry == "TaskEvent")
146 {
147 header = &message_registries::task_event::header;
148 for (const message_registries::MessageEntry& entry :
149 message_registries::task_event::registry)
150 {
151 registryEntries.emplace_back(&entry);
152 }
153 }
154 else if (registry == "OpenBMC")
155 {
156 header = &message_registries::openbmc::header;
157 for (const message_registries::MessageEntry& entry :
158 message_registries::openbmc::registry)
159 {
160 registryEntries.emplace_back(&entry);
161 }
162 }
163 else if (registry == "ResourceEvent")
164 {
165 header = &message_registries::resource_event::header;
166 for (const message_registries::MessageEntry& entry :
167 message_registries::resource_event::registry)
168 {
169 registryEntries.emplace_back(&entry);
170 }
171 }
172 else
173 {
174 messages::resourceNotFound(
175 asyncResp->res,
176 "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
177 registry);
178 return;
179 }
180
181 if (registry != registry1)
182 {
183 messages::resourceNotFound(asyncResp->res, header->type,
184 registry1);
185 return;
186 }
187
188 asyncResp->res.jsonValue = {
189 {"@Redfish.Copyright", header->copyright},
190 {"@odata.type", header->type},
191 {"Id", header->id},
192 {"Name", header->name},
193 {"Language", header->language},
194 {"Description", header->description},
195 {"RegistryPrefix", header->registryPrefix},
196 {"RegistryVersion", header->registryVersion},
197 {"OwningEntity", header->owningEntity}};
198
199 nlohmann::json& messageObj =
200 asyncResp->res.jsonValue["Messages"];
201
202 // Go through the Message Registry and populate each Message
203 for (const message_registries::MessageEntry* message :
204 registryEntries)
205 {
206 nlohmann::json& obj = messageObj[message->first];
207 obj = {{"Description", message->second.description},
208 {"Message", message->second.message},
209 {"Severity", message->second.severity},
210 {"MessageSeverity", message->second.messageSeverity},
211 {"NumberOfArgs", message->second.numberOfArgs},
212 {"Resolution", message->second.resolution}};
213 if (message->second.numberOfArgs > 0)
214 {
215 nlohmann::json& messageParamArray = obj["ParamTypes"];
Ed Tanous938f2562021-06-11 09:34:52 -0700216 messageParamArray = nlohmann::json::array();
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700217 for (const char* str : message->second.paramTypes)
218 {
219 if (str == nullptr)
220 {
221 break;
222 }
223 messageParamArray.push_back(str);
224 }
225 }
226 }
227 });
228}
Jason M. Bills70304cb2019-03-27 12:03:59 -0700229
Jason M. Bills70304cb2019-03-27 12:03:59 -0700230} // namespace redfish