blob: 78994cf77ee9ff90eb8c3867f21aebba8dee378a [file] [log] [blame]
Ed Tanouse3cb5a32018-08-08 14:16:49 -07001#pragma once
2
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +02003#include <functional>
4
Ed Tanouse3cb5a32018-08-08 14:16:49 -07005namespace bmcweb
6{
7
8/**
9 * AsyncResp
10 * Gathers data needed for response processing after async calls are done
11 */
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020012
Ed Tanouse3cb5a32018-08-08 14:16:49 -070013class AsyncResp
14{
15 public:
16 AsyncResp(crow::Response& response) : res(response)
17 {
18 }
19
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020020 AsyncResp(crow::Response& response, std::function<void()>&& function) :
21 res(response), func(std::move(function))
22 {
23 }
24
Ed Tanouse3cb5a32018-08-08 14:16:49 -070025 ~AsyncResp()
26 {
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020027 if (func && res.result() == boost::beast::http::status::ok)
28 {
29 func();
30 }
31
Ed Tanouse3cb5a32018-08-08 14:16:49 -070032 res.end();
33 }
34
35 crow::Response& res;
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020036 std::function<void()> func = 0;
Ed Tanouse3cb5a32018-08-08 14:16:49 -070037};
38
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020039} // namespace bmcweb