blob: f92e4ef8523b3b67a690a05615d9862297001bf4 [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"
9#include "verb.hpp"
10
11#include <memory>
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010012
Ed Tanous1abe55e2018-09-05 08:30:59 -070013namespace redfish
14{
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010015/*
16 * @brief Top level class installing and providing Redfish services
17 */
Ed Tanous1abe55e2018-09-05 08:30:59 -070018class RedfishService
19{
20 public:
21 /*
22 * @brief Redfish service constructor
23 *
24 * Loads Redfish configuration and installs schema resources
25 *
26 * @param[in] app Crow app on which Redfish will initialize
27 */
Ed Tanous3cd70722024-04-06 09:24:01 -070028 explicit RedfishService(App& app);
rohitpaic1a75eb2025-01-03 19:13:36 +053029
30 // Temporary change to make redfish instance available in other places
31 // like query delegation.
32 static RedfishService& getInstance(App& app)
33 {
34 static RedfishService redfish(app);
35 return redfish;
36 }
37
38 void validate()
39 {
40 oemRouter.validate();
41 }
42
43 template <StringLiteral Rule>
44 auto& newRoute(HttpVerb method)
45 {
46 return oemRouter.newRule<Rule>(method);
47 }
48
49 void handleSubRoute(
50 const crow::Request& req,
51 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) const
52 {
53 oemRouter.handle(req, asyncResp);
54 }
55
56 OemRouter oemRouter;
Borawski.Lukaszb6df6dc2018-01-24 10:20:45 +010057};
58
rohitpaic1a75eb2025-01-03 19:13:36 +053059template <StringLiteral Path>
60auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method)
61{
62 return service.newRoute<Path>(method);
63}
64
Ed Tanous1abe55e2018-09-05 08:30:59 -070065} // namespace redfish