From ec7e4590b01c7a28ecb8d0f3c98897b63841f4e5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Sep 2016 00:29:59 +0100 Subject: Pass current Core instance to route handlers --- icespider/compile/routeCompiler.cpp | 2 +- icespider/core/core.cpp | 2 +- icespider/core/irouteHandler.cpp | 2 +- icespider/core/irouteHandler.h | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index e2ab8a1..99771aa 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -294,7 +294,7 @@ namespace IceSpider { fprintbf(1, output, "// path: %s\n", r->path); fprintbf(1, output, "class %s : public IceSpider::IRouteHandler {\n", r->name); fprintbf(2, output, "public:\n"); - fprintbf(3, output, "%s() :\n", r->name); + fprintbf(3, output, "%s(const IceSpider::Core *) :\n", r->name); fprintbf(4, output, "IceSpider::IRouteHandler(IceSpider::HttpMethod::%s, \"%s\")", methodName, r->path); for (const auto & p : r->params) { if (p->hasUserSource) { diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp index cb0c671..6a44523 100644 --- a/icespider/core/core.cpp +++ b/icespider/core/core.cpp @@ -11,7 +11,7 @@ namespace IceSpider { routes.resize(HttpMethod::OPTIONS + 1, {{ }}); // Initialize routes for (const auto & rp : AdHoc::PluginManager::getDefault()->getAll()) { - auto r = rp->implementation()->create(); + auto r = rp->implementation()->create(this); auto & mroutes = routes[r->method]; if (mroutes.size() <= r->pathElementCount()) { mroutes.resize(r->pathElementCount() + 1); diff --git a/icespider/core/irouteHandler.cpp b/icespider/core/irouteHandler.cpp index 172c77d..ca9cb94 100644 --- a/icespider/core/irouteHandler.cpp +++ b/icespider/core/irouteHandler.cpp @@ -2,7 +2,7 @@ #include "core.h" #include -INSTANTIATEVOIDFACTORY(IceSpider::IRouteHandler); +INSTANTIATEFACTORY(IceSpider::IRouteHandler, const IceSpider::Core *); namespace IceSpider { IRouteHandler::IRouteHandler(HttpMethod m, const std::string & p) : diff --git a/icespider/core/irouteHandler.h b/icespider/core/irouteHandler.h index 4832bdb..ffbde36 100644 --- a/icespider/core/irouteHandler.h +++ b/icespider/core/irouteHandler.h @@ -10,6 +10,8 @@ #include namespace IceSpider { + class Core; + class DLL_PUBLIC IRouteHandler : public Path { public: IRouteHandler(HttpMethod, const std::string & path); @@ -44,7 +46,7 @@ namespace IceSpider { void addRouteSerializer(const MimeType &, StreamSerializerFactoryPtr); void removeRouteSerializer(const MimeType &); }; - typedef AdHoc::Factory RouteHandlerFactory; + typedef AdHoc::Factory RouteHandlerFactory; } #endif -- cgit v1.2.3