1 #pragma once 2 3 #include "http_response.hpp" 4 5 #include <functional> 6 7 namespace bmcweb 8 { 9 10 /** 11 * AsyncResp 12 * Gathers data needed for response processing after async calls are done 13 */ 14 15 class AsyncResp 16 { 17 public: 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 {} 24 25 AsyncResp(const AsyncResp&) = delete; 26 AsyncResp(AsyncResp&&) = delete; 27 AsyncResp& operator=(const AsyncResp&) = delete; 28 AsyncResp& operator=(AsyncResp&&) = delete; 29 30 ~AsyncResp() 31 { 32 if (func && res.result() == boost::beast::http::status::ok) 33 { 34 func(); 35 } 36 37 res.end(); 38 } 39 40 crow::Response& res; 41 std::function<void()> func; 42 }; 43 44 } // namespace bmcweb 45