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) | ||||
17 | { | ||||
18 | } | ||||
19 | |||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 20 | AsyncResp(crow::Response& response, std::function<void()>&& function) : |
21 | res(response), func(std::move(function)) | ||||
22 | { | ||||
23 | } | ||||
24 | |||||
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 25 | ~AsyncResp() |
26 | { | ||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 27 | if (func && res.result() == boost::beast::http::status::ok) |
28 | { | ||||
29 | func(); | ||||
30 | } | ||||
31 | |||||
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 32 | res.end(); |
33 | } | ||||
34 | |||||
35 | crow::Response& res; | ||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 36 | std::function<void()> func = 0; |
Ed Tanous | e3cb5a3 | 2018-08-08 14:16:49 -0700 | [diff] [blame] | 37 | }; |
38 | |||||
Iwona Klimaszewska | c0a1c8a | 2019-07-12 18:26:38 +0200 | [diff] [blame] | 39 | } // namespace bmcweb |