diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-30 23:48:05 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-30 23:48:05 +0100 |
commit | d10b8914aeb4f297d6b6deca2408cd81b1adad08 (patch) | |
tree | 25fb41739387671e8e7a183778686ffdc5a29b4c /project2/cgi | |
parent | Remove NoOutputExecute for not being a thing (diff) | |
download | project2-d10b8914aeb4f297d6b6deca2408cd81b1adad08.tar.bz2 project2-d10b8914aeb4f297d6b6deca2408cd81b1adad08.tar.xz project2-d10b8914aeb4f297d6b6deca2408cd81b1adad08.zip |
Use AdHoc plugins for scriptable things and remove legacy plugin support
Diffstat (limited to 'project2/cgi')
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 1 | ||||
-rw-r--r-- | project2/cgi/cgiContentNegotiate.cpp | 8 | ||||
-rw-r--r-- | project2/cgi/cgiOutputOptions.cpp | 15 | ||||
-rw-r--r-- | project2/cgi/cgiOutputOptions.h | 12 | ||||
-rw-r--r-- | project2/cgi/cgiProgRouter.cpp | 14 | ||||
-rw-r--r-- | project2/cgi/cgiStageDefaultError.cpp | 2 | ||||
-rw-r--r-- | project2/cgi/cgiStageFail.cpp | 3 | ||||
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 10 | ||||
-rw-r--r-- | project2/cgi/cgiStageRedirect.cpp | 4 | ||||
-rw-r--r-- | project2/cgi/p2webCgi.cpp | 1 | ||||
-rw-r--r-- | project2/cgi/p2webFCgi.cpp | 1 | ||||
-rw-r--r-- | project2/cgi/testCgi.cpp | 5 |
12 files changed, 37 insertions, 39 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 2b7b988..a263a38 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -15,6 +15,7 @@ #include <boost/lexical_cast.hpp> #include <glibmm/exception.h> #include <cxxabi.h> +#include <plugable.h> #include <glibmm/regex.h> typedef boost::uuids::uuid SIDKey; diff --git a/project2/cgi/cgiContentNegotiate.cpp b/project2/cgi/cgiContentNegotiate.cpp index 2494ba8..929159f 100644 --- a/project2/cgi/cgiContentNegotiate.cpp +++ b/project2/cgi/cgiContentNegotiate.cpp @@ -3,7 +3,7 @@ #include <boost/tokenizer.hpp> #include <boost/bind.hpp> -class ContentNegotiateLoader : public PresenterLoader { +class ContentNegotiateLoader : public PresenterFactory { public: MultiRowSetPresenter * create(const ScriptNodePtr & s, const ObjectSource & os, ExecContext * const & ec) const { @@ -14,11 +14,11 @@ class ContentNegotiateLoader : public PresenterLoader { if (mimetype == "*/*") break; for (const auto & t : mappedTypes) { if (t->Matches(mimetype)) { - return PresenterLoader::getFor(t->present)->create(s, os, ec); + return PresenterFactory::createNew(t->present, s, os, ec); } } } - return PresenterLoader::getFor((*mappedTypes.begin())->present)->create(s, os, ec); + return PresenterFactory::createNew((*mappedTypes.begin())->present, s, os, ec); } INITOPTIONS; @@ -46,7 +46,7 @@ class ContentNegotiateLoader : public PresenterLoader { }; ContentNegotiateLoader::MappedTypes ContentNegotiateLoader::mappedTypes; -DECLARE_CUSTOM_COMPONENT_LOADER("contentnegotiate", ContentNegotiateLoader, ContentNegotiateLoader, PresenterLoader); +NAMEDPLUGIN("contentnegotiate", ContentNegotiateLoader, PresenterFactory); DECLARE_OPTIONS(ContentNegotiateLoader, "Content negotiation options") ("cgi.contentnegotiation.mappedtype", Options::functions( diff --git a/project2/cgi/cgiOutputOptions.cpp b/project2/cgi/cgiOutputOptions.cpp index de3d291..07dbf79 100644 --- a/project2/cgi/cgiOutputOptions.cpp +++ b/project2/cgi/cgiOutputOptions.cpp @@ -1,6 +1,6 @@ #include "cgiOutputOptions.h" #include "scripts.h" -#include "instanceStore.impl.h" +#include <factory.impl.h> bool OutputOptions::core; bool OutputOptions::session; @@ -21,7 +21,7 @@ OutputOptions::OutputOptions(ScriptNodePtr p) : { } -DECLARE_OPTIONS(OutputOptionsLoader, "CGI default output options") +DECLARE_OPTIONS(OutputOptions, "CGI default output options") ("cgi.output.encoding", Options::value(&OutputOptions::encoding, "utf-8"), "Default out encoding") ("cgi.output.core", Options::value(&OutputOptions::core, true), "Core messages") ("cgi.output.session", Options::value(&OutputOptions::session, true), "Session values") @@ -29,13 +29,8 @@ DECLARE_OPTIONS(OutputOptionsLoader, "CGI default output options") ("cgi.output.environment", Options::value(&OutputOptions::environment, true), "Environment") ("cgi.output.url", Options::value(&OutputOptions::url, true), "URL breakdown") ("cgi.output.parameters", Options::value(&OutputOptions::parameters, true), "Parameters") -END_OPTIONS(OutputOptionsLoader) +END_OPTIONS(OutputOptions) -OutputOptionsPtr -OutputOptionsLoader::create(ScriptNodePtr e) const { - return new OutputOptions(e); -} - -DECLARE_CUSTOM_COMPONENT_LOADER("outputoptions", OutputOptions, OutputOptionsLoader, OutputOptionsLoader) -INSTANTIATESTORE(std::string, OutputOptionsLoader); +NAMEDFACTORY("outputoptions", OutputOptions, OutputOptionsFactory) +INSTANTIATEFACTORY(OutputOptions, ScriptNodePtr); diff --git a/project2/cgi/cgiOutputOptions.h b/project2/cgi/cgiOutputOptions.h index be2c452..6c40388 100644 --- a/project2/cgi/cgiOutputOptions.h +++ b/project2/cgi/cgiOutputOptions.h @@ -17,8 +17,9 @@ class OutputOptions : public IntrusivePtrBase { const Variable URL; const Variable Parameters; + INITOPTIONS; + // defaults - friend class OutputOptionsLoader; static std::string encoding; private: static bool core; @@ -29,13 +30,6 @@ class OutputOptions : public IntrusivePtrBase { static bool parameters; }; typedef boost::intrusive_ptr<OutputOptions> OutputOptionsPtr; - -class OutputOptionsLoader : public ComponentLoader { - public: - typedef std::string KeyType; - - OutputOptionsPtr create(ScriptNodePtr e) const; - INITOPTIONS; -}; +typedef AdHoc::Factory<OutputOptions, ScriptNodePtr> OutputOptionsFactory; #endif diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp index fef9ed8..da04be6 100644 --- a/project2/cgi/cgiProgRouter.cpp +++ b/project2/cgi/cgiProgRouter.cpp @@ -9,11 +9,15 @@ #include "scriptStorage.h" #include "rowSet.h" #include "exceptions.h" +#include <factory.impl.h> typedef std::map<std::string, std::string> VarMap; class RoutingTable { public: + class Route; + typedef AdHoc::Factory<RoutingTable::Route, ScriptNodePtr> RouteFactory; + void loadRoutesFromFile(const std::string & routeFile) { routeScriptPath = routeFile; if (routeFile.empty()) { @@ -38,7 +42,7 @@ class RoutingTable { void setRouteScript() { routeScript = ScriptReader::resolveScript(CommonObjects::datasourceRoot, routeScriptPath, true); - routeScript->loader.addLoadTarget(routeScript->root(), Storer::into<ElementLoader>(&routes)); + routeScript->loader.addLoadTarget(routeScript->root(), Storer::into<RouteFactory>(&routes)); routes.clear(); routeScript->load(NULL, true); } @@ -79,7 +83,7 @@ class RoutingTable { } const std::string variable; }; - + class Route : public SourceObject { public: Route(ScriptNodePtr s) : @@ -123,8 +127,7 @@ class RoutingTable { std::list<RoutePtr> routes; }; -typedef RoutingTable::Route Route; -DECLARE_LOADER("route", Route); +NAMEDFACTORY("route", RoutingTable::Route, RoutingTable::RouteFactory); class ProgRouter; class ProgRouterFactory : public RouterFactory::For<ProgRouter>, public ComponentLoader { @@ -219,5 +222,6 @@ class Routes : public RowSet { } }; -DECLARE_LOADER("routes", Routes); +NAMEDFACTORY("routes", Routes, RowSetFactory); +INSTANTIATEFACTORY(RoutingTable::Route, ScriptNodePtr); diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp index d230a21..e5d1b9f 100644 --- a/project2/cgi/cgiStageDefaultError.cpp +++ b/project2/cgi/cgiStageDefaultError.cpp @@ -16,7 +16,7 @@ CgiApplicationEngine::DefaultErrorStage::DefaultErrorStage(const std::exception auto xp = dynamic_cast<TransformSource *>(pres.get()); auto cp = dynamic_cast<ContentPresenter *>(pres.get()); if (xp && cp && cp->contentType == CgiApplicationEngine::transformContentType) { - auto h = TransformTargetLoader::getFor(CgiApplicationEngine::transformTargetType)->create(root, Default); + auto h = TransformTargetFactory::createNew(CgiApplicationEngine::transformTargetType, root, Default); xp->addTarget(h, crc, root); } } diff --git a/project2/cgi/cgiStageFail.cpp b/project2/cgi/cgiStageFail.cpp index 461c8a7..e96f14f 100644 --- a/project2/cgi/cgiStageFail.cpp +++ b/project2/cgi/cgiStageFail.cpp @@ -46,6 +46,5 @@ namespace CgiApplicationExtras { }; } -typedef CgiApplicationExtras::CgiFail cgif; -DECLARE_LOADER("cgifail", cgif); +NAMEDFACTORY("cgifail", CgiApplicationExtras::CgiFail, ViewFactory); diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 5e33df3..dffc98e 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -11,19 +11,19 @@ CgiApplicationEngine::PresentStage::PresentStage(ScriptReaderPtr s, CgiRequestCo CheckHost(s->root()), ViewHost(s->root()), presenter([this, crc] { - auto p = PresenterLoader::getFor(CgiApplicationEngine::defaultPresenter)->create(root, Default, crc); + auto p = PresenterFactory::createNew(CgiApplicationEngine::defaultPresenter, root, Default, crc); auto xp = dynamic_cast<TransformSource *>(p); auto cp = dynamic_cast<ContentPresenter *>(p); if (xp && cp && cp->contentType == CgiApplicationEngine::transformContentType) { - auto h = TransformTargetLoader::getFor(CgiApplicationEngine::transformTargetType)->create(root, Default); + auto h = TransformTargetFactory::createNew(CgiApplicationEngine::transformTargetType, root, Default); xp->addTarget(h, crc, root); } return p; }) { - s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsLoader>(&outputOptions)); - s->loader.addLoadTarget(s->root(), Storer::into<PresenterLoader>(&presenter, Scripted, crc)); - s->loader.addLoadTarget(s->root(), Storer::into<ElementLoader>(&caches)); + s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsFactory>(&outputOptions)); + s->loader.addLoadTarget(s->root(), Storer::into<PresenterFactory>(&presenter, Scripted, crc)); + s->loader.addLoadTarget(s->root(), Storer::into<PresenterCacheFactory>(&caches)); } CgiApplicationEngine::NextStage diff --git a/project2/cgi/cgiStageRedirect.cpp b/project2/cgi/cgiStageRedirect.cpp index d6fee08..18de9f9 100644 --- a/project2/cgi/cgiStageRedirect.cpp +++ b/project2/cgi/cgiStageRedirect.cpp @@ -42,5 +42,5 @@ namespace CgiApplicationExtras { }; } -typedef CgiApplicationExtras::CgiRedirect cgird; -DECLARE_LOADER("cgiredirect", cgird); +NAMEDFACTORY("cgiredirect", CgiApplicationExtras::CgiRedirect, ViewFactory); + diff --git a/project2/cgi/p2webCgi.cpp b/project2/cgi/p2webCgi.cpp index a4e2328..a59621d 100644 --- a/project2/cgi/p2webCgi.cpp +++ b/project2/cgi/p2webCgi.cpp @@ -1,5 +1,6 @@ #include "cgiAppEngine.h" #include <boost/bind.hpp> +#include <plugable.h> class GetEnv : public CgiEnvInput { public: diff --git a/project2/cgi/p2webFCgi.cpp b/project2/cgi/p2webFCgi.cpp index 42a99bc..e31986d 100644 --- a/project2/cgi/p2webFCgi.cpp +++ b/project2/cgi/p2webFCgi.cpp @@ -2,6 +2,7 @@ #include "cgiAppEngine.h" #include <boost/bind.hpp> #include <boost/filesystem/convenience.hpp> +#include <plugable.h> time_t lastPeriodic = 0; time_t periodicDelay = 600; diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index b61a475..3c79a77 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -8,6 +8,7 @@ #include "cgiRequestContext.h" #include "cgiAppEngine.h" #include <options/showHelp.h> +#include <plugable.h> #define TESTOPT(name, def, desc) \ (name, Options::value(optStore().insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc) @@ -16,7 +17,9 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput { class TestConfigConsumer : public ConfigConsumer { public: void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const { - InstanceSet<Options>::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) { + opts->implementation()->consume(n, p, v, cp); + } } const Options::Option * get(const Glib::ustring &) const { return NULL; |