Merge pull request #150 from an-tao/rreference_callback

Change the type of the callback in handlers to r-reference type
This commit is contained in:
An Tao 2019-05-09 11:48:47 +08:00 committed by GitHub
commit 971ff9c2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 69 additions and 69 deletions

View File

@ -125,7 +125,7 @@ using namespace drogon;
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definitions here;
PATH_ADD("/json", Get);
@ -135,7 +135,7 @@ class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
/// The source file
#include "JsonCtrl.h"
void JsonCtrl::asyncHandleHttpRequest(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
std::function<void(const HttpResponsePtr &)> &&callback)
{
Json::Value ret;
ret["message"] = "Hello, World!";
@ -165,9 +165,9 @@ class User : public drogon::HttpController<User>
METHOD_ADD(User::newUser, "/{1}", Post); //path is /api/v1/User/{arg1}
METHOD_LIST_END
//your declaration of processing function maybe like this:
void getInfo(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int userId) const;
void getDetailInfo(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int userId) const;
void newUser(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, std::string &&userName);
void getInfo(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int userId) const;
void getDetailInfo(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int userId) const;
void newUser(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, std::string &&userName);
public:
User()
{

View File

@ -77,7 +77,7 @@ void create_controller::newSimpleControllerHeaderFile(std::ofstream &file, const
file << indent << "class " << class_name << ":public drogon::HttpSimpleController<" << class_name << ">\n";
file << indent << "{\n";
file << indent << "public:\n";
file << indent << " virtual void asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)> & callback) override;\n";
file << indent << " virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;\n";
file << indent << " PATH_LIST_BEGIN\n";
file << indent << " //list path definitions here;\n";
@ -103,7 +103,7 @@ void create_controller::newSimpleControllerSourceFile(std::ofstream &file, const
file << "using namespace " << namespacename << ";\n";
class_name = className.substr(pos + 2);
}
file << "void " << class_name << "::asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)> & callback)\n";
file << "void " << class_name << "::asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback)\n";
file << "{\n";
file << " //write your application logic here\n";
file << "}";
@ -213,9 +213,9 @@ void create_controller::newHttpControllerHeaderFile(std::ofstream &file, const s
file << indent << "METHOD_LIST_END\n";
file << indent << "//your declaration of processing function maybe like this:\n";
file << indent << "//void get(const HttpRequestPtr& req,"
"const std::function<void (const HttpResponsePtr &)>&callback,int p1,std::string p2);\n";
"std::function<void (const HttpResponsePtr &)> &&callback,int p1,std::string p2);\n";
file << indent << "//void your_method_name(const HttpRequestPtr& req,"
"const std::function<void (const HttpResponsePtr &)>&callback,double p1,int p2) const;\n";
"std::function<void (const HttpResponsePtr &)> &&callback,double p1,int p2) const;\n";
indent.resize(indent.length() - 4);
file << indent << "};\n";
if (indent == "")

View File

@ -1,5 +1,5 @@
#include "BenchmarkCtrl.h"
void BenchmarkCtrl::asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)> & callback)
void BenchmarkCtrl::asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback)
{
//write your application logic here
auto resp = HttpResponse::newHttpResponse();

View File

@ -4,7 +4,7 @@ using namespace drogon;
class BenchmarkCtrl:public drogon::HttpSimpleController<BenchmarkCtrl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req,const std::function<void (const HttpResponsePtr &)> & callback)override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback)override;
PATH_LIST_BEGIN
PATH_ADD("/benchmark",Get);
PATH_LIST_END

View File

@ -1,5 +1,5 @@
#include "JsonCtrl.h"
void JsonCtrl::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void JsonCtrl::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
Json::Value ret;
ret["message"] = "Hello, World!";

View File

@ -4,7 +4,7 @@ using namespace drogon;
class JsonCtrl : public drogon::HttpSimpleController<JsonCtrl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definitions here;
PATH_ADD("/json", Get);

View File

@ -2,7 +2,7 @@
//add definition of your processing function here
void CustomCtrl::hello(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback,
std::function<void(const HttpResponsePtr &)> &&callback,
const std::string &userName) const
{
auto resp = HttpResponse::newHttpResponse();

View File

@ -11,7 +11,7 @@ class CustomCtrl : public drogon::HttpController<CustomCtrl, false>
explicit CustomCtrl(const std::string &greetings) : _greetings(greetings) {}
void hello(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, const std::string &userName) const;
void hello(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, const std::string &userName) const;
private:
std::string _greetings;

View File

@ -1,6 +1,6 @@
#include "JsonTestController.h"
#include <json/json.h>
void JsonTestController::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void JsonTestController::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
Json::Value json;
json["path"] = "json";

View File

@ -7,7 +7,7 @@ class JsonTestController : public drogon::HttpSimpleController<JsonTestControlle
{
public:
//TestController(){}
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
PATH_ADD("/json", Get, "drogon::LocalHostFilter");

View File

@ -1,5 +1,5 @@
#include "ListParaCtl.h"
void ListParaCtl::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ListParaCtl::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
//write your application logic here
HttpViewData data;

View File

@ -4,7 +4,7 @@ using namespace drogon;
class ListParaCtl : public drogon::HttpSimpleController<ListParaCtl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definations here;
//PATH_ADD("/path","filter1","filter2",...);

View File

@ -2,7 +2,7 @@
#include <trantor/net/EventLoop.h>
#include <atomic>
void PipeliningTest::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void PipeliningTest::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
static std::atomic<int> counter{0};
int c = counter.fetch_add(1);

View File

@ -4,7 +4,7 @@ using namespace drogon;
class PipeliningTest : public drogon::HttpSimpleController<PipeliningTest>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definitions here;
PATH_ADD("/pipe", Get);

View File

@ -1,6 +1,6 @@
#include "TestController.h"
using namespace example;
void TestController::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void TestController::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
//write your application logic here
LOG_WARN << req->matchedPathPattern();

View File

@ -6,7 +6,7 @@ namespace example
class TestController : public drogon::HttpSimpleController<TestController>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definations here;
//PATH_ADD("/path","filter1","filter2",...);

View File

@ -1,5 +1,5 @@
#include "TestViewCtl.h"
void TestViewCtl::asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void TestViewCtl::asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
//write your application logic here
drogon::HttpViewData data;

View File

@ -4,7 +4,7 @@ using namespace drogon;
class TestViewCtl : public drogon::HttpSimpleController<TestViewCtl>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) override;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
//list path definations here;
//PATH_ADD("/path","filter1","filter2",...);

View File

@ -4,14 +4,14 @@
using namespace api;
//add definition of your processing function here
void Attachment::get(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
std::function<void(const HttpResponsePtr &)> &&callback)
{
auto resp = HttpResponse::newHttpViewResponse("FileUpload", HttpViewData());
callback(resp);
}
void Attachment::upload(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
std::function<void(const HttpResponsePtr &)> &&callback)
{
MultiPartParser fileUpload;
if (fileUpload.parse(req) == 0)
@ -55,7 +55,7 @@ void Attachment::upload(const HttpRequestPtr &req,
}
void Attachment::download(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback)
std::function<void(const HttpResponsePtr &)> &&callback)
{
auto resp = HttpResponse::newFileResponse("./drogon.jpg", "", CT_IMAGE_JPG);
callback(resp);

View File

@ -14,10 +14,10 @@ class Attachment : public drogon::HttpController<Attachment>
METHOD_LIST_END
//your declaration of processing function maybe like this:
void get(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback);
std::function<void(const HttpResponsePtr &)> &&callback);
void upload(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback);
std::function<void(const HttpResponsePtr &)> &&callback);
void download(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback);
std::function<void(const HttpResponsePtr &)> &&callback);
};
} // namespace api

View File

@ -1,13 +1,13 @@
#include "api_v1_ApiTest.h"
using namespace api::v1;
//add definition of your processing function here
void ApiTest::rootGet(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ApiTest::rootGet(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
auto res = HttpResponse::newHttpResponse();
res->setBody("ROOT Get!!!");
callback(res);
}
void ApiTest::rootPost(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ApiTest::rootPost(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
std::thread([=]() {
auto res = HttpResponse::newHttpResponse();
@ -15,7 +15,7 @@ void ApiTest::rootPost(const HttpRequestPtr &req, const std::function<void(const
callback(res);
}).detach();
}
void ApiTest::get(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, std::string &&p2)
void ApiTest::get(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int p1, std::string &&p2)
{
HttpViewData data;
data.insert("title", std::string("ApiTest::get"));
@ -27,7 +27,7 @@ void ApiTest::get(const HttpRequestPtr &req, const std::function<void(const Http
callback(res);
}
void ApiTest::your_method_name(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, double p1, int p2) const
void ApiTest::your_method_name(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, double p1, int p2) const
{
LOG_WARN << req->matchedPathPattern();
HttpViewData data;
@ -40,7 +40,7 @@ void ApiTest::your_method_name(const HttpRequestPtr &req, const std::function<vo
auto res = HttpResponse::newHttpViewResponse("ListParaView", data);
callback(res);
}
void ApiTest::staticApi(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ApiTest::staticApi(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
auto resp = HttpResponse::newHttpResponse();
resp->setBody("staticApi,hello!!");
@ -48,7 +48,7 @@ void ApiTest::staticApi(const HttpRequestPtr &req, const std::function<void(cons
callback(resp);
}
void ApiTest::get2(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, std::string &&p1)
void ApiTest::get2(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, std::string &&p1)
{
//test gzip feature
auto res = HttpResponse::newHttpResponse();
@ -355,7 +355,7 @@ void ApiTest::get2(const HttpRequestPtr &req, const std::function<void(const Htt
callback(res);
}
void ApiTest::jsonTest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ApiTest::jsonTest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
auto json = req->getJsonObject();
Json::Value ret;
@ -371,7 +371,7 @@ void ApiTest::jsonTest(const HttpRequestPtr &req, const std::function<void(const
callback(resp);
}
void ApiTest::formTest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback)
void ApiTest::formTest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
{
auto parameters = req->getParameters();
Json::Value ret;

View File

@ -22,14 +22,14 @@ class ApiTest : public drogon::HttpController<ApiTest>
METHOD_ADD(ApiTest::formTest, "/form", Post);
METHOD_LIST_END
//your declaration of processing function maybe like this:
void get(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, std::string &&p2);
void your_method_name(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, double p1, int p2) const;
void staticApi(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
void get2(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, std::string &&p1);
void rootGet(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
void rootPost(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
void jsonTest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
void formTest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback);
void get(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int p1, std::string &&p2);
void your_method_name(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, double p1, int p2) const;
void staticApi(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
void get2(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, std::string &&p1);
void rootGet(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
void rootPost(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
void jsonTest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
void formTest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
public:
ApiTest()

View File

@ -11,7 +11,7 @@ class A : public DrObjectBase
{
public:
void handle(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback,
std::function<void(const HttpResponsePtr &)> &&callback,
int p1, const std::string &p2, const std::string &p3, int p4) const
{
HttpViewData data;
@ -27,7 +27,7 @@ public:
callback(res);
}
static void staticHandle(const HttpRequestPtr &req,
const std::function<void(const HttpResponsePtr &)> &callback,
std::function<void(const HttpResponsePtr &)> &&callback,
int p1, const std::string &p2, const std::string &p3, int p4)
{
HttpViewData data;
@ -46,7 +46,7 @@ public:
class B : public DrObjectBase
{
public:
void operator()(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, int p2)
void operator()(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int p1, int p2)
{
HttpViewData data;
data.insert("title", std::string("ApiTest::get"));
@ -69,7 +69,7 @@ public:
METHOD_ADD(Test::get, "get/{2}/{1}", Get); //path is /api/v1/test/get/{arg2}/{arg1}
METHOD_ADD(Test::list, "/{2}/info", Get); //path is /api/v1/test/{arg2}/info
METHOD_LIST_END
void get(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, int p2) const
void get(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int p1, int p2) const
{
HttpViewData data;
data.insert("title", std::string("ApiTest::get"));
@ -80,7 +80,7 @@ public:
auto res = HttpResponse::newHttpViewResponse("ListParaView", data);
callback(res);
}
void list(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int p1, int p2) const
void list(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int p1, int p2) const
{
HttpViewData data;
data.insert("title", std::string("ApiTest::get"));
@ -115,7 +115,7 @@ int main()
app().registerHandler("/api/v1/handle1/{1}/{2}/?p3={3}&p4={4}", &A::handle);
app().registerHandler("/api/v1/handle11/{1}/{2}/?p3={3}&p4={4}", &A::staticHandle);
//lambda example
app().registerHandler("/api/v1/handle2/{1}/{2}", [](const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, int a, float b) {
app().registerHandler("/api/v1/handle2/{1}/{2}", [](const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, int a, float b) {
// LOG_DEBUG << "int a=" << a;
// LOG_DEBUG << "float b=" << b;
HttpViewData data;
@ -133,7 +133,7 @@ int main()
app().registerHandler("/api/v1/handle3/{1}/{2}", b);
A tmp;
std::function<void(const HttpRequestPtr &, const std::function<void(const HttpResponsePtr &)> &, int, const std::string &, const std::string &, int)>
std::function<void(const HttpRequestPtr &, std::function<void(const HttpResponsePtr &)> &&, int, const std::string &, const std::string &, int)>
func = std::bind(&A::handle, &tmp, _1, _2, _3, _4, _5, _6);
//api example for std::function
app().registerHandler("/api/v1/handle4/{4}/{3}/{1}", func);

View File

@ -68,7 +68,7 @@ class HttpBinderBase
{
public:
virtual void handleHttpRequest(std::list<std::string> &pathParameter,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback) = 0;
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) = 0;
virtual size_t paramCount() = 0;
virtual const std::string &handlerName() const = 0;
virtual ~HttpBinderBase() {}
@ -90,9 +90,9 @@ class HttpBinder : public HttpBinderBase
public:
typedef FUNCTION FunctionType;
virtual void handleHttpRequest(std::list<std::string> &pathParameter,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback) override
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) override
{
run(pathParameter, req, callback);
run(pathParameter, req, std::move(callback));
}
virtual size_t paramCount() override
{
@ -125,7 +125,7 @@ private:
std::size_t Boundary = argument_count>
typename std::enable_if<(sizeof...(Values) < Boundary), void>::type run(
std::list<std::string> &pathParameter,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
Values &&... values)
{
//call this function recursively until parameter's count equals to the count of target function parameters
@ -144,45 +144,45 @@ private:
}
}
run(pathParameter, req, callback, std::forward<Values>(values)..., std::move(value));
run(pathParameter, req, std::move(callback), std::forward<Values>(values)..., std::move(value));
}
template <
typename... Values,
std::size_t Boundary = argument_count>
typename std::enable_if<(sizeof...(Values) == Boundary), void>::type run(
std::list<std::string> &pathParameter,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
Values &&... values)
{
callFunction(req, callback, std::move(values)...);
callFunction(req, std::move(callback), std::move(values)...);
}
template <typename... Values,
bool isClassFunction = traits::isClassFunction,
bool isDrObjectClass = traits::isDrObjectClass>
typename std::enable_if<isClassFunction && !isDrObjectClass, void>::type callFunction(
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
Values &&... values)
{
static auto &obj = getControllerObj<typename traits::class_type>();
(obj.*_func)(req, callback, std::move(values)...);
(obj.*_func)(req, std::move(callback), std::move(values)...);
};
template <typename... Values,
bool isClassFunction = traits::isClassFunction,
bool isDrObjectClass = traits::isDrObjectClass>
typename std::enable_if<isClassFunction && isDrObjectClass, void>::type callFunction(
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
Values &&... values)
{
static auto objPtr = DrClassMap::getSingleInstance<typename traits::class_type>();
(*objPtr.*_func)(req, callback, std::move(values)...);
(*objPtr.*_func)(req, std::move(callback), std::move(values)...);
};
template <typename... Values,
bool isClassFunction = traits::isClassFunction>
typename std::enable_if<!isClassFunction, void>::type callFunction(
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> callback,
const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback,
Values &&... values)
{
_func(req, callback, std::move(values)...);
_func(req, std::move(callback), std::move(values)...);
};
};

View File

@ -34,7 +34,7 @@ namespace drogon
class HttpSimpleControllerBase : public virtual DrObjectBase
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback) = 0;
virtual void asyncHandleHttpRequest(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) = 0;
virtual ~HttpSimpleControllerBase() {}
};

View File

@ -78,7 +78,7 @@ template <
typename ReturnType,
typename... Arguments>
struct FunctionTraits<
ReturnType (*)(const HttpRequestPtr &req, const std::function<void(const HttpResponsePtr &)> &callback, Arguments...)> : FunctionTraits<ReturnType (*)(Arguments...)>
ReturnType (*)(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback, Arguments...)> : FunctionTraits<ReturnType (*)(Arguments...)>
{
static const bool isHTTPFunction = true;
typedef void class_type;