xref: /openbmc/bmcweb/features/redfish/include/redfish.hpp (revision 84aad24d55fb0e53128928961ac36242aabb799d)
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"
6c1a75ebcSrohitpai #include "async_resp.hpp"
7c1a75ebcSrohitpai #include "http_request.hpp"
8c1a75ebcSrohitpai #include "redfish_oem_routing.hpp"
9fdf51f5cSRohit PAI #include "sub_request.hpp"
10c1a75ebcSrohitpai #include "verb.hpp"
11c1a75ebcSrohitpai 
12c1a75ebcSrohitpai #include <memory>
13b6df6dc7SBorawski.Lukasz 
141abe55efSEd Tanous namespace redfish
151abe55efSEd Tanous {
16b6df6dc7SBorawski.Lukasz /*
17b6df6dc7SBorawski.Lukasz  * @brief Top level class installing and providing Redfish services
18b6df6dc7SBorawski.Lukasz  */
191abe55efSEd Tanous class RedfishService
201abe55efSEd Tanous {
21b6df6dc7SBorawski.Lukasz   public:
22b6df6dc7SBorawski.Lukasz     /*
23b6df6dc7SBorawski.Lukasz      * @brief Redfish service constructor
24b6df6dc7SBorawski.Lukasz      *
25b6df6dc7SBorawski.Lukasz      * Loads Redfish configuration and installs schema resources
26b6df6dc7SBorawski.Lukasz      *
27b6df6dc7SBorawski.Lukasz      * @param[in] app   Crow app on which Redfish will initialize
28b6df6dc7SBorawski.Lukasz      */
293cd7072bSEd Tanous     explicit RedfishService(App& app);
30c1a75ebcSrohitpai 
31c1a75ebcSrohitpai     // Temporary change to make redfish instance available in other places
32c1a75ebcSrohitpai     // like query delegation.
33c1a75ebcSrohitpai     static RedfishService& getInstance(App& app)
34c1a75ebcSrohitpai     {
35c1a75ebcSrohitpai         static RedfishService redfish(app);
36c1a75ebcSrohitpai         return redfish;
37c1a75ebcSrohitpai     }
38c1a75ebcSrohitpai 
39c1a75ebcSrohitpai     void validate()
40c1a75ebcSrohitpai     {
41c1a75ebcSrohitpai         oemRouter.validate();
42c1a75ebcSrohitpai     }
43c1a75ebcSrohitpai 
44c1a75ebcSrohitpai     template <StringLiteral Rule>
45c1a75ebcSrohitpai     auto& newRoute(HttpVerb method)
46c1a75ebcSrohitpai     {
47c1a75ebcSrohitpai         return oemRouter.newRule<Rule>(method);
48c1a75ebcSrohitpai     }
49c1a75ebcSrohitpai 
50c1a75ebcSrohitpai     void handleSubRoute(
51c1a75ebcSrohitpai         const crow::Request& req,
52c1a75ebcSrohitpai         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) const
53c1a75ebcSrohitpai     {
54fdf51f5cSRohit PAI         auto subReq = std::make_shared<SubRequest>(req);
55*84aad24dSrohitpai         if (!subReq->needHandling())
56*84aad24dSrohitpai         {
57*84aad24dSrohitpai             return;
58*84aad24dSrohitpai         }
59fdf51f5cSRohit PAI         oemRouter.handle(subReq, asyncResp);
60c1a75ebcSrohitpai     }
61c1a75ebcSrohitpai 
62c1a75ebcSrohitpai     OemRouter oemRouter;
63b6df6dc7SBorawski.Lukasz };
64b6df6dc7SBorawski.Lukasz 
65c1a75ebcSrohitpai template <StringLiteral Path>
66c1a75ebcSrohitpai auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method)
67c1a75ebcSrohitpai {
68c1a75ebcSrohitpai     return service.newRoute<Path>(method);
69c1a75ebcSrohitpai }
70c1a75ebcSrohitpai 
71b6df6dc7SBorawski.Lukasz } // namespace redfish
72