Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 3 | #pragma once |
| 4 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 5 | #include "app.hpp" |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 6 | #include "async_resp.hpp" |
| 7 | #include "http_request.hpp" |
| 8 | #include "redfish_oem_routing.hpp" |
Rohit PAI | fdf51f5 | 2025-04-04 11:12:12 +0530 | [diff] [blame] | 9 | #include "sub_request.hpp" |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 10 | #include "verb.hpp" |
| 11 | |
| 12 | #include <memory> |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 13 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 14 | namespace redfish |
| 15 | { |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 16 | /* |
| 17 | * @brief Top level class installing and providing Redfish services |
| 18 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 19 | class 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 Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 29 | explicit RedfishService(App& app); |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 30 | |
| 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 PAI | fdf51f5 | 2025-04-04 11:12:12 +0530 | [diff] [blame] | 54 | auto subReq = std::make_shared<SubRequest>(req); |
rohitpai | 84aad24 | 2025-01-28 09:23:53 +0530 | [diff] [blame] | 55 | if (!subReq->needHandling()) |
| 56 | { |
| 57 | return; |
| 58 | } |
Rohit PAI | fdf51f5 | 2025-04-04 11:12:12 +0530 | [diff] [blame] | 59 | oemRouter.handle(subReq, asyncResp); |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | OemRouter oemRouter; |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 65 | template <StringLiteral Path> |
| 66 | auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method) |
| 67 | { |
| 68 | return service.newRoute<Path>(method); |
| 69 | } |
| 70 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 71 | } // namespace redfish |