summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-28 19:59:31 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-28 19:59:31 +0100
commitaea0cfc52472af5c6e848617507db2744a28d570 (patch)
treee8ed41f2eefe531556a2638d9801c9f8a4e58783
parentUse AdHoc plugins for ICE daemon modules (diff)
downloadproject2-aea0cfc52472af5c6e848617507db2744a28d570.tar.bz2
project2-aea0cfc52472af5c6e848617507db2744a28d570.tar.xz
project2-aea0cfc52472af5c6e848617507db2744a28d570.zip
Use AdHoc plugins for CGI routers
-rw-r--r--project2/cgi/cgiAppEngine.cpp4
-rw-r--r--project2/cgi/cgiAppEngine.h2
-rw-r--r--project2/cgi/cgiProgRouter.cpp16
-rw-r--r--project2/cgi/cgiRequestContext.cpp2
-rw-r--r--project2/cgi/cgiRouter.cpp4
-rw-r--r--project2/cgi/cgiRouter.h3
-rw-r--r--project2/cgi/cgiSimpleRouter.cpp2
7 files changed, 17 insertions, 16 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index 229926c..2b7b988 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -36,7 +36,7 @@ std::string CgiApplicationEngine::onErrorPresent;
std::string CgiApplicationEngine::defaultPresenter;
SessionContainerPtr CgiApplicationEngine::sessionsContainer;
std::string CgiApplicationEngine::sessionCookie;
-boost::shared_ptr<RouterLoader> CgiApplicationEngine::router;
+const RouterFactory * CgiApplicationEngine::router;
CgiApplicationEngine::PlatformHostnameList CgiApplicationEngine::platHosts;
class PlatformHostnameTarget : public Options::Target {
@@ -92,7 +92,7 @@ DECLARE_OPTIONS(CgiApplicationEngine, "Project2 CGI options")
"The name of the cookie for storing session IDs")
("cgi.hostRegex", new PlatformHostnameTarget(),
"Regular expression used to define a hostname -> platform association")
-("cgi.router", Options::function([](const VariableType & r) { router = RouterLoader::getFor(r); }, "simple"),
+("cgi.router", Options::function([](const VariableType & r) { router = RouterFactory::get(r); }, "simple"),
"Implemenation of router model to map request paths to scripts")
END_OPTIONS(CgiApplicationEngine);
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index d964d07..d8271b5 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -161,7 +161,7 @@ class CgiApplicationEngine : AppInstance {
INITOPTIONS;
static PlatformHostnameList platHosts;
- static boost::shared_ptr<RouterLoader> router;
+ static const RouterFactory * router;
static SessionContainerPtr sessionsContainer;
static std::string sessionCookie;
private:
diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp
index 3e84637..fef9ed8 100644
--- a/project2/cgi/cgiProgRouter.cpp
+++ b/project2/cgi/cgiProgRouter.cpp
@@ -127,9 +127,9 @@ typedef RoutingTable::Route Route;
DECLARE_LOADER("route", Route);
class ProgRouter;
-class ProgRouterLoader : public RouterLoader::For<ProgRouter> {
+class ProgRouterFactory : public RouterFactory::For<ProgRouter>, public ComponentLoader {
public:
- void onBefore()
+ void onBefore() override
{
routingTable.onBefore();
}
@@ -139,14 +139,14 @@ class ProgRouterLoader : public RouterLoader::For<ProgRouter> {
INITOPTIONS;
};
-RoutingTable ProgRouterLoader::routingTable;
+RoutingTable ProgRouterFactory::routingTable;
-DECLARE_OPTIONS(ProgRouterLoader, "CGI Programmable Router options")
+DECLARE_OPTIONS(ProgRouterFactory, "CGI Programmable Router options")
("cgi.progRouter.routes", Options::functions(
boost::bind(&RoutingTable::loadRoutesFromFile, &routingTable, _1),
boost::bind(&RoutingTable::clearRoutes, &routingTable)),
"Script file defining web service routes")
-END_OPTIONS(ProgRouterLoader);
+END_OPTIONS(ProgRouterFactory);
SimpleMessageException(UriElementNotFound);
@@ -156,7 +156,7 @@ class ProgRouter : public Router {
path(p) {
}
std::string route() const {
- return ProgRouterLoader::routingTable.present(path, vars);
+ return ProgRouterFactory::routingTable.present(path, vars);
}
bool isDefault() const {
return false;
@@ -189,7 +189,7 @@ class ProgRouter : public Router {
mutable VarMap vars;
};
-DECLARE_CUSTOM_COMPONENT_LOADER("progRouter", ProgRouter, ProgRouterLoader, RouterLoader);
+NAMEDPLUGIN("progRouter", ProgRouterFactory, RouterFactory);
class Routes : public RowSet {
public:
@@ -209,7 +209,7 @@ class Routes : public RowSet {
void execute(const Glib::ustring & filter, const RowProcessorCallback & rp, ExecContext *) const
{
RouteRowState rs;
- for (const auto & r : ProgRouterLoader::routingTable.routes) {
+ for (const auto & r : ProgRouterFactory::routingTable.routes) {
if (boost::algorithm::starts_with(r->path, filter)) {
rs.fields[0] = VariableType(r->present);
rs.fields[1] = VariableType(r->path);
diff --git a/project2/cgi/cgiRequestContext.cpp b/project2/cgi/cgiRequestContext.cpp
index 636d2f6..24de206 100644
--- a/project2/cgi/cgiRequestContext.cpp
+++ b/project2/cgi/cgiRequestContext.cpp
@@ -13,7 +13,7 @@
CgiRequestContext::CgiRequestContext(cgicc::CgiInput * i, const CgiEnvInput & e) :
cgi(i),
- router(boost::bind(&RouterLoader::create, boost::cref(CgiApplicationEngine::router), getRedirectURL())),
+ router(boost::bind(&RouterFactory::create, boost::cref(CgiApplicationEngine::router), getRedirectURL())),
cgienv(e),
session(boost::bind(&CgiRequestContext::getSessionInternal, this))
{
diff --git a/project2/cgi/cgiRouter.cpp b/project2/cgi/cgiRouter.cpp
index dc77c40..ebf8eb0 100644
--- a/project2/cgi/cgiRouter.cpp
+++ b/project2/cgi/cgiRouter.cpp
@@ -1,5 +1,5 @@
#include "cgiRouter.h"
-#include "instanceStore.impl.h"
+#include <factory.impl.h>
-INSTANTIATESTORE(std::string, RouterLoader);
+INSTANTIATEFACTORY(Router, const std::string &);
diff --git a/project2/cgi/cgiRouter.h b/project2/cgi/cgiRouter.h
index 9e9c621..bc4ce44 100644
--- a/project2/cgi/cgiRouter.h
+++ b/project2/cgi/cgiRouter.h
@@ -3,6 +3,7 @@
#include <variables.h>
#include <scriptLoader.h>
+#include <factory.h>
class MultiRowSetPresenter;
@@ -15,7 +16,7 @@ class Router : public IntrusivePtrBase {
virtual void present(const MultiRowSetPresenter * p) const = 0;
};
typedef boost::intrusive_ptr<Router> RouterPtr;
-typedef GenLoader<Router, std::string, const std::string &> RouterLoader;
+typedef AdHoc::Factory<Router, const std::string &> RouterFactory;
#endif
diff --git a/project2/cgi/cgiSimpleRouter.cpp b/project2/cgi/cgiSimpleRouter.cpp
index b67848e..bc8c544 100644
--- a/project2/cgi/cgiSimpleRouter.cpp
+++ b/project2/cgi/cgiSimpleRouter.cpp
@@ -54,5 +54,5 @@ class SimpleRouter : public Router {
std::vector<std::string> elems;
};
-DECLARE_GENERIC_LOADER("simple", RouterLoader, SimpleRouter);
+NAMEDFACTORY("simple", SimpleRouter, RouterFactory);