Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 3 | #include "http_response.hpp" |
| 4 | |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 5 | #include <functional> |
| 6 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 7 | namespace bmcweb |
| 8 | { |
| 9 | |
| 10 | /** |
| 11 | * AsyncResp |
| 12 | * Gathers data needed for response processing after async calls are done |
| 13 | */ |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 14 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 15 | class AsyncResp |
| 16 | { |
| 17 | public: |
Gunnar Mills | 9062d47 | 2021-11-16 11:37:47 -0600 | [diff] [blame] | 18 | AsyncResp(crow::Response& response) : res(response) |
| 19 | {} |
| 20 | |
| 21 | AsyncResp(crow::Response& response, std::function<void()>&& function) : |
| 22 | res(response), func(std::move(function)) |
| 23 | {} |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 24 | |
Krzysztof Grobelny | dab0604 | 2021-04-02 13:28:14 +0000 | [diff] [blame] | 25 | AsyncResp(const AsyncResp&) = delete; |
| 26 | AsyncResp(AsyncResp&&) = delete; |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 27 | AsyncResp& operator=(const AsyncResp&) = delete; |
| 28 | AsyncResp& operator=(AsyncResp&&) = delete; |
Krzysztof Grobelny | dab0604 | 2021-04-02 13:28:14 +0000 | [diff] [blame] | 29 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 30 | ~AsyncResp() |
| 31 | { |
Gunnar Mills | 9062d47 | 2021-11-16 11:37:47 -0600 | [diff] [blame] | 32 | if (func && res.result() == boost::beast::http::status::ok) |
| 33 | { |
| 34 | func(); |
| 35 | } |
| 36 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 37 | res.end(); |
| 38 | } |
| 39 | |
Gunnar Mills | 9062d47 | 2021-11-16 11:37:47 -0600 | [diff] [blame] | 40 | crow::Response& res; |
| 41 | std::function<void()> func; |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 44 | } // namespace bmcweb |