140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3b6df6dc7SBorawski.Lukasz #pragma once 4b6df6dc7SBorawski.Lukasz 53cd7072bSEd Tanous #include "app.hpp" 6*c1a75ebcSrohitpai #include "async_resp.hpp" 7*c1a75ebcSrohitpai #include "http_request.hpp" 8*c1a75ebcSrohitpai #include "redfish_oem_routing.hpp" 9*c1a75ebcSrohitpai #include "verb.hpp" 10*c1a75ebcSrohitpai 11*c1a75ebcSrohitpai #include <memory> 12b6df6dc7SBorawski.Lukasz 131abe55efSEd Tanous namespace redfish 141abe55efSEd Tanous { 15b6df6dc7SBorawski.Lukasz /* 16b6df6dc7SBorawski.Lukasz * @brief Top level class installing and providing Redfish services 17b6df6dc7SBorawski.Lukasz */ 181abe55efSEd Tanous class RedfishService 191abe55efSEd Tanous { 20b6df6dc7SBorawski.Lukasz public: 21b6df6dc7SBorawski.Lukasz /* 22b6df6dc7SBorawski.Lukasz * @brief Redfish service constructor 23b6df6dc7SBorawski.Lukasz * 24b6df6dc7SBorawski.Lukasz * Loads Redfish configuration and installs schema resources 25b6df6dc7SBorawski.Lukasz * 26b6df6dc7SBorawski.Lukasz * @param[in] app Crow app on which Redfish will initialize 27b6df6dc7SBorawski.Lukasz */ 283cd7072bSEd Tanous explicit RedfishService(App& app); 29*c1a75ebcSrohitpai 30*c1a75ebcSrohitpai // Temporary change to make redfish instance available in other places 31*c1a75ebcSrohitpai // like query delegation. 32*c1a75ebcSrohitpai static RedfishService& getInstance(App& app) 33*c1a75ebcSrohitpai { 34*c1a75ebcSrohitpai static RedfishService redfish(app); 35*c1a75ebcSrohitpai return redfish; 36*c1a75ebcSrohitpai } 37*c1a75ebcSrohitpai 38*c1a75ebcSrohitpai void validate() 39*c1a75ebcSrohitpai { 40*c1a75ebcSrohitpai oemRouter.validate(); 41*c1a75ebcSrohitpai } 42*c1a75ebcSrohitpai 43*c1a75ebcSrohitpai template <StringLiteral Rule> 44*c1a75ebcSrohitpai auto& newRoute(HttpVerb method) 45*c1a75ebcSrohitpai { 46*c1a75ebcSrohitpai return oemRouter.newRule<Rule>(method); 47*c1a75ebcSrohitpai } 48*c1a75ebcSrohitpai 49*c1a75ebcSrohitpai void handleSubRoute( 50*c1a75ebcSrohitpai const crow::Request& req, 51*c1a75ebcSrohitpai const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) const 52*c1a75ebcSrohitpai { 53*c1a75ebcSrohitpai oemRouter.handle(req, asyncResp); 54*c1a75ebcSrohitpai } 55*c1a75ebcSrohitpai 56*c1a75ebcSrohitpai OemRouter oemRouter; 57b6df6dc7SBorawski.Lukasz }; 58b6df6dc7SBorawski.Lukasz 59*c1a75ebcSrohitpai template <StringLiteral Path> 60*c1a75ebcSrohitpai auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method) 61*c1a75ebcSrohitpai { 62*c1a75ebcSrohitpai return service.newRoute<Path>(method); 63*c1a75ebcSrohitpai } 64*c1a75ebcSrohitpai 65b6df6dc7SBorawski.Lukasz } // namespace redfish 66