/**
This file is a part of the rcw project
Copyright (C) 2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#ifndef RCW_ASYNC_HPP
#define RCW_ASYNC_HPP
#include
#include
#include //shared_ptr
#include "response.hpp"
#include "types.hpp"
#include "read_write_cback.hpp"
#include "sync.hpp"
namespace rcw{
//GET methods
std::future async_get(const url& u, std::initializer_list headers = {});
std::future async_get(const url& u, const curl_header_list& headers);
template
std::future async_get(Func&& func, const url& u, std::initializer_list headers = {});
template
std::future async_get(Func&& func, const url& u, const curl_header_list& headers);
//POST methods
std::future async_post(const url& u, std::initializer_list headers = {});
std::future async_post(const url& u, const curl_header_list& headers);
std::future async_post(const url& u, const body& b, std::initializer_list headers = {});
std::future async_post(const url& u, const body& b, const curl_header_list& headers);
template
std::future async_post(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers = {});
template
std::future async_post(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers);
//PUT methods
std::future async_put(const url& u, std::initializer_list headers = {});
std::future async_put(const url& u, const curl_header_list& headers);
std::future async_put(const url& u, const body& b, std::initializer_list headers = {});
std::future async_put(const url& u, const body& b, const curl_header_list& headers);
template
std::future async_put(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers = {});
template
std::future async_put(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers);
//DELETE methods
std::future async_del(const url& u, std::initializer_list headers = {});
std::future async_del(const url& u, const curl_header_list& headers);
std::future async_del(const url& u, const body& b, std::initializer_list headers = {});
std::future async_del(const url& u, const body& b, const curl_header_list& headers);
template
std::future async_del(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers = {});
template
std::future async_del(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers);
template
std::future async_del(WFunc&& wfunc, const url& u, std::initializer_list headers = {});
template
std::future async_del(WFunc&& wfunc, const url& u, const curl_header_list& headers);
//Implementation of templated GET
template
std::future async_get(Func&& func, const url& u, std::initializer_list headers){
return async_get(std::forward(func), u, curl_header_list(headers));
}
template
std::future async_get(Func&& func, const url& u, const curl_header_list& headers){
std::shared_ptr url_copy = std::make_shared(u.data);
std::shared_ptr cback(new detail::curl_cback_invoker_impl(std::forward(func)));
std::shared_ptr hlist(new curl_header_list(headers));
return std::async([=]() -> response
{
return get(*cback, rcw::url(*url_copy), *hlist);
});
}
//Implementation of templated POST
template
std::future async_post(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers){
return async_post(std::forward(rfunc), std::forward(wfunc), u, curl_header_list(headers));
}
template
std::future async_post(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers){
std::shared_ptr url_copy = std::make_shared(u.data);
std::shared_ptr rcback(new detail::curl_cback_invoker_impl(std::forward(rfunc)));
std::shared_ptr wcback(new detail::curl_cback_invoker_impl(std::forward(wfunc)));
std::shared_ptr hlist(new curl_header_list(headers));
return std::async([=]() -> response
{
return post(*rcback, *wcback, rcw::url(*url_copy), *hlist);
});
}
//Implementation of templated PUT
template
std::future async_put(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers){
return async_put(std::forward(rfunc), std::forward(wfunc), u, curl_header_list(headers));
}
template
std::future async_put(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers){
std::shared_ptr url_copy = std::make_shared(u.data);
std::shared_ptr rcback(new detail::curl_cback_invoker_impl(std::forward(rfunc)));
std::shared_ptr wcback(new detail::curl_cback_invoker_impl(std::forward(wfunc)));
std::shared_ptr hlist(new curl_header_list(headers));
return std::async([=]() -> response
{
return put(*rcback, *wcback, rcw::url(*url_copy), *hlist);
});
}
//Implementation of templated DELETE
template
std::future async_del(RFunc&& rfunc, WFunc&& wfunc, const url& u, std::initializer_list headers){
return async_del(std::forward(rfunc), std::forward(wfunc), u, curl_header_list(headers));
}
template
std::future async_del(RFunc&& rfunc, WFunc&& wfunc, const url& u, const curl_header_list& headers){
std::shared_ptr url_copy = std::make_shared(u.data);
std::shared_ptr rcback(new detail::curl_cback_invoker_impl(std::forward(rfunc)));
std::shared_ptr wcback(new detail::curl_cback_invoker_impl(std::forward(wfunc)));
std::shared_ptr hlist(new curl_header_list(headers));
return std::async([=]() -> response
{
return del(*rcback, *wcback, rcw::url(*url_copy), *hlist);
});
}
template
std::future async_del(WFunc&& wfunc, const url& u, std::initializer_list headers){
return async_del(std::forward(wfunc), u, curl_header_list(headers));
}
template
std::future async_del(WFunc&& wfunc, const url& u, const curl_header_list& headers){
std::shared_ptr url_copy = std::make_shared(u.data);
std::shared_ptr wcback(new detail::curl_cback_invoker_impl(std::forward(wfunc)));
std::shared_ptr hlist(new curl_header_list(headers));
return std::async([=]() -> response
{
return del(*wcback, rcw::url(*url_copy), *hlist);
});
}
}
#endif