blob: c2e336e86114ccd89d7750eb094291635d9d00d3 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +01003#pragma once
4
Ed Tanous3cd70722024-04-06 09:24:01 -07005#include "app.hpp"
rohitpaic1a75eb2025-01-03 19:13:36 +05306#include "async_resp.hpp"
7#include "http_request.hpp"
8#include "redfish_oem_routing.hpp"
Rohit PAIfdf51f52025-04-04 11:12:12 +05309#include "sub_request.hpp"
rohitpaic1a75eb2025-01-03 19:13:36 +053010#include "verb.hpp"
11
12#include <memory>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010013
Ed Tanous1abe55e2018-09-05 08:30:59 -070014namespace redfish
15{
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010016/*
17 * @brief Top level class installing and providing Redfish services
18 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070019class RedfishService
20{
21 public:
22 /*
23 * @brief Redfish service constructor
24 *
25 * Loads Redfish configuration and installs schema resources
26 *
27 * @param[in] app Crow app on which Redfish will initialize
28 */
Ed Tanous3cd70722024-04-06 09:24:01 -070029 explicit RedfishService(App& app);
rohitpaic1a75eb2025-01-03 19:13:36 +053030
31 // Temporary change to make redfish instance available in other places
32 // like query delegation.
33 static RedfishService& getInstance(App& app)
34 {
35 static RedfishService redfish(app);
36 return redfish;
37 }
38
39 void validate()
40 {
41 oemRouter.validate();
42 }
43
44 template <StringLiteral Rule>
45 auto& newRoute(HttpVerb method)
46 {
47 return oemRouter.newRule<Rule>(method);
48 }
49
50 void handleSubRoute(
51 const crow::Request& req,
52 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) const
53 {
Rohit PAIfdf51f52025-04-04 11:12:12 +053054 auto subReq = std::make_shared<SubRequest>(req);
rohitpai84aad242025-01-28 09:23:53 +053055 if (!subReq->needHandling())
56 {
57 return;
58 }
Rohit PAIfdf51f52025-04-04 11:12:12 +053059 oemRouter.handle(subReq, asyncResp);
rohitpaic1a75eb2025-01-03 19:13:36 +053060 }
61
62 OemRouter oemRouter;
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010063};
64
rohitpaic1a75eb2025-01-03 19:13:36 +053065template <StringLiteral Path>
66auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method)
67{
68 return service.newRoute<Path>(method);
69}
70
Ed Tanous1abe55e2018-09-05 08:30:59 -070071} // namespace redfish