diff --git a/mongoose/Controller.h b/mongoose/Controller.h index 364c8a7f05..f7713b6231 100644 --- a/mongoose/Controller.h +++ b/mongoose/Controller.h @@ -11,12 +11,6 @@ using namespace std; -#define addRoute(httpMethod, url, controllerType, method) \ - registerRoute(httpMethod, url, new RequestHandler(this, &controllerType::method )); - -#define addRouteResponse(httpMethod, url, controllerType, method, responseType) \ - registerRoute(httpMethod, url, new RequestHandler(this, &controllerType::method )); - /** * A controller is a module that respond to requests * @@ -146,6 +140,16 @@ namespace Mongoose virtual bool handles(string method, string url); vector getUrls(); + template + void addRoute(const std::string& httpMethod, const std::string& url, void (C::*func)(Request&, StreamResponse&)){ + registerRoute(httpMethod, url, new RequestHandler(static_cast(this), func)); + } + + template + void addRouteResponse(const std::string& httpMethod, const std::string& url, void (C::*func)(Request&, R&)){ + registerRoute(httpMethod, url, new RequestHandler(static_cast(this), func)); + } + protected: Sessions *sessions; Server *server;