summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-08-30 21:49:39 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-08-30 21:49:39 +0100
commitab36ea7919cf2faa19c0fc9565a5a4c62b1ac835 (patch)
tree66f8d628d7c5ec6bd10a5cb7c75a38a447a07bef
parentUse compact json object for paramOverrides and mash up operations (diff)
downloadicespider-ab36ea7919cf2faa19c0fc9565a5a4c62b1ac835.tar.bz2
icespider-ab36ea7919cf2faa19c0fc9565a5a4c62b1ac835.tar.xz
icespider-ab36ea7919cf2faa19c0fc9565a5a4c62b1ac835.zip
Register route handler factories, not route handlers so we can construct them as needed, with arguments, after system start up (incl. config load)
-rw-r--r--icespider/compile/routeCompiler.cpp2
-rw-r--r--icespider/core/core.cpp11
-rw-r--r--icespider/core/irouteHandler.cpp4
-rw-r--r--icespider/core/irouteHandler.h6
-rw-r--r--icespider/unittests/testApp.cpp3
-rw-r--r--icespider/unittests/testCompile.cpp4
6 files changed, 18 insertions, 12 deletions
diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp
index e38f240..ae75bf2 100644
--- a/icespider/compile/routeCompiler.cpp
+++ b/icespider/compile/routeCompiler.cpp
@@ -398,7 +398,7 @@ namespace IceSpider {
fprintbf(output, "} // namespace %s\n\n", c->name);
fprintf(output, "// Register route handlers.\n");
for (const auto & r : c->routes) {
- fprintbf(output, "PLUGIN(%s::%s, IceSpider::IRouteHandler);\n", c->name, r->name);
+ fprintbf(output, "FACTORY(%s::%s, IceSpider::RouteHandlerFactory);\n", c->name, r->name);
}
fprintf(output, "\n// End generated code.\n");
}
diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp
index b21a805..cb0c671 100644
--- a/icespider/core/core.cpp
+++ b/icespider/core/core.cpp
@@ -10,8 +10,8 @@ namespace IceSpider {
// Big enough to map all the request methods (an empty of zero lenght routes as default)
routes.resize(HttpMethod::OPTIONS + 1, {{ }});
// Initialize routes
- for (const auto & rp : AdHoc::PluginManager::getDefault()->getAll<IRouteHandler>()) {
- auto r = rp->implementation();
+ for (const auto & rp : AdHoc::PluginManager::getDefault()->getAll<RouteHandlerFactory>()) {
+ auto r = rp->implementation()->create();
auto & mroutes = routes[r->method];
if (mroutes.size() <= r->pathElementCount()) {
mroutes.resize(r->pathElementCount() + 1);
@@ -30,6 +30,13 @@ namespace IceSpider {
Core::~Core()
{
if (communicator) communicator->destroy();
+ for (auto m : routes) {
+ for (auto l : m) {
+ for (auto r : l) {
+ delete r;
+ }
+ }
+ }
}
void
diff --git a/icespider/core/irouteHandler.cpp b/icespider/core/irouteHandler.cpp
index 82c6df1..172c77d 100644
--- a/icespider/core/irouteHandler.cpp
+++ b/icespider/core/irouteHandler.cpp
@@ -1,8 +1,8 @@
#include "irouteHandler.h"
#include "core.h"
-#include <plugins.impl.h>
+#include <factory.impl.h>
-INSTANTIATEPLUGINOF(IceSpider::IRouteHandler);
+INSTANTIATEVOIDFACTORY(IceSpider::IRouteHandler);
namespace IceSpider {
IRouteHandler::IRouteHandler(HttpMethod m, const std::string & p) :
diff --git a/icespider/core/irouteHandler.h b/icespider/core/irouteHandler.h
index bbd9ab3..4832bdb 100644
--- a/icespider/core/irouteHandler.h
+++ b/icespider/core/irouteHandler.h
@@ -5,12 +5,12 @@
#include "util.h"
#include <pathparts.h>
#include <routes.h>
-#include <plugins.h>
+#include <factory.h>
#include <visibility.h>
#include <boost/lexical_cast.hpp>
namespace IceSpider {
- class DLL_PUBLIC IRouteHandler : public AdHoc::AbstractPluginImplementation, public Path {
+ class DLL_PUBLIC IRouteHandler : public Path {
public:
IRouteHandler(HttpMethod, const std::string & path);
virtual ~IRouteHandler();
@@ -44,7 +44,7 @@ namespace IceSpider {
void addRouteSerializer(const MimeType &, StreamSerializerFactoryPtr);
void removeRouteSerializer(const MimeType &);
};
- typedef AdHoc::PluginOf<IRouteHandler> RouteHandlers;
+ typedef AdHoc::Factory<IRouteHandler> RouteHandlerFactory;
}
#endif
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index ef98e6a..0266226 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -1,7 +1,6 @@
#define BOOST_TEST_MODULE TestApp
#include <boost/test/unit_test.hpp>
-#include <plugins.h>
#include <safeMapFind.h>
#include <irouteHandler.h>
#include <core.h>
@@ -27,7 +26,7 @@ void forceEarlyChangeDir()
BOOST_AUTO_TEST_CASE( testLoadConfiguration )
{
- BOOST_REQUIRE_EQUAL(8, AdHoc::PluginManager::getDefault()->getAll<IRouteHandler>().size());
+ BOOST_REQUIRE_EQUAL(8, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
}
class TestRequest : public IHttpRequest {
diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp
index 6184a7e..130b762 100644
--- a/icespider/unittests/testCompile.cpp
+++ b/icespider/unittests/testCompile.cpp
@@ -132,10 +132,10 @@ BOOST_AUTO_TEST_CASE( testLoad )
BOOST_TEST_INFO(dlerror());
BOOST_REQUIRE(lib);
- BOOST_REQUIRE_EQUAL(8, AdHoc::PluginManager::getDefault()->getAll<IRouteHandler>().size());
+ BOOST_REQUIRE_EQUAL(8, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size());
// smoke test (block ensure dlclose dones't cause segfault)
{
- auto route = AdHoc::PluginManager::getDefault()->get<IRouteHandler>("common::index");
+ auto route = AdHoc::PluginManager::getDefault()->get<IceSpider::RouteHandlerFactory>("common::index");
BOOST_REQUIRE(route);
}