1e3cb5a31SEd Tanous #pragma once 2e3cb5a31SEd Tanous 38d1b46d7Szhanghch05 #include "http_response.hpp" 48d1b46d7Szhanghch05 5c0a1c8a0SIwona Klimaszewska #include <functional> 6c0a1c8a0SIwona Klimaszewska 7e3cb5a31SEd Tanous namespace bmcweb 8e3cb5a31SEd Tanous { 9e3cb5a31SEd Tanous 10e3cb5a31SEd Tanous /** 11e3cb5a31SEd Tanous * AsyncResp 12e3cb5a31SEd Tanous * Gathers data needed for response processing after async calls are done 13e3cb5a31SEd Tanous */ 14c0a1c8a0SIwona Klimaszewska 15e3cb5a31SEd Tanous class AsyncResp 16e3cb5a31SEd Tanous { 17e3cb5a31SEd Tanous public: 189062d478SGunnar Mills AsyncResp(crow::Response& response) : res(response) 199062d478SGunnar Mills {} 209062d478SGunnar Mills 219062d478SGunnar Mills AsyncResp(crow::Response& response, std::function<void()>&& function) : 229062d478SGunnar Mills res(response), func(std::move(function)) 239062d478SGunnar Mills {} 24c0a1c8a0SIwona Klimaszewska 25dab0604aSKrzysztof Grobelny AsyncResp(const AsyncResp&) = delete; 26dab0604aSKrzysztof Grobelny AsyncResp(AsyncResp&&) = delete; 27*ecd6a3a2SEd Tanous AsyncResp& operator=(const AsyncResp&) = delete; 28*ecd6a3a2SEd Tanous AsyncResp& operator=(AsyncResp&&) = delete; 29dab0604aSKrzysztof Grobelny 30e3cb5a31SEd Tanous ~AsyncResp() 31e3cb5a31SEd Tanous { 329062d478SGunnar Mills if (func && res.result() == boost::beast::http::status::ok) 339062d478SGunnar Mills { 349062d478SGunnar Mills func(); 359062d478SGunnar Mills } 369062d478SGunnar Mills 37e3cb5a31SEd Tanous res.end(); 38e3cb5a31SEd Tanous } 39e3cb5a31SEd Tanous 409062d478SGunnar Mills crow::Response& res; 419062d478SGunnar Mills std::function<void()> func; 42e3cb5a31SEd Tanous }; 43e3cb5a31SEd Tanous 44e3cb5a31SEd Tanous } // namespace bmcweb 45