Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 1 | #pragma once |
2 | |||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 3 | #include <functional> |
4 | |||||
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 5 | namespace bmcweb |
6 | { | ||||
7 | |||||
8 | /** | ||||
9 | * AsyncResp | ||||
10 | * Gathers data needed for response processing after async calls are done | ||||
11 | */ | ||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 12 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 13 | class AsyncResp |
14 | { | ||||
15 | public: | ||||
16 | AsyncResp(crow::Response& response) : res(response) | ||||
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 17 | {} |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 18 | |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 19 | AsyncResp(crow::Response& response, std::function<void()>&& function) : |
20 | res(response), func(std::move(function)) | ||||
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 21 | {} |
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 22 | |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 23 | ~AsyncResp() |
24 | { | ||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 25 | if (func && res.result() == boost::beast::http::status::ok) |
26 | { | ||||
27 | func(); | ||||
28 | } | ||||
29 | |||||
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 30 | res.end(); |
31 | } | ||||
32 | |||||
33 | crow::Response& res; | ||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 34 | std::function<void()> func = 0; |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 35 | }; |
36 | |||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 37 | } // namespace bmcweb |