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" |
| 9 | #include "verb.hpp" |
| 10 | |
| 11 | #include <memory> |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 12 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 13 | namespace redfish |
| 14 | { |
Borawski.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 15 | /* |
| 16 | * @brief Top level class installing and providing Redfish services |
| 17 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 18 | class 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 Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 28 | explicit RedfishService(App& app); |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame^] | 29 | |
| 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.Lukasz | b6df6dc | 2018-01-24 10:20:45 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame^] | 59 | template <StringLiteral Path> |
| 60 | auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method) |
| 61 | { |
| 62 | return service.newRoute<Path>(method); |
| 63 | } |
| 64 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 65 | } // namespace redfish |