xref: /openbmc/bmcweb/features/redfish/include/redfish.hpp (revision c1a75ebc267a78853fb26a3da8c6b3388e6ee07c)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #pragma once
4 
5 #include "app.hpp"
6 #include "async_resp.hpp"
7 #include "http_request.hpp"
8 #include "redfish_oem_routing.hpp"
9 #include "verb.hpp"
10 
11 #include <memory>
12 
13 namespace redfish
14 {
15 /*
16  * @brief Top level class installing and providing Redfish services
17  */
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      */
28     explicit RedfishService(App& app);
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;
57 };
58 
59 template <StringLiteral Path>
60 auto& REDFISH_SUB_ROUTE(RedfishService& service, HttpVerb method)
61 {
62     return service.newRoute<Path>(method);
63 }
64 
65 } // namespace redfish
66