From 890cfb275d440ce52757ca887ad1a819f4ee1433 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 26 Sep 2015 03:02:38 +0100 Subject: Use AdHoc plugins for session containers --- project2/cgi/cgiAppEngine.cpp | 2 +- project2/common/sessionContainer.cpp | 4 ++-- project2/common/sessionContainer.h | 3 ++- project2/xml/sessionXml.cpp | 4 ++-- project2/xml/sessionXml.h | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index c569617..229926c 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -86,7 +86,7 @@ DECLARE_OPTIONS(CgiApplicationEngine, "Project2 CGI options") "The present script to use when the requested script (or child) fails") ("cgi.dumpDataDoc", Options::value(&dumpdatadoc), "Write a copy of the data document before sending it to the web server") -("cgi.sessionModule", Options::function([](const VariableType & m) { sessionsContainer = SessionContainerLoader::createNew(m); }, "xml"), +("cgi.sessionModule", Options::function([](const VariableType & m) { sessionsContainer = SessionContainerFactory::createNew(m); }, "xml"), "The module with which to implement session management") ("cgi.sessionCookie", Options::value(&sessionCookie, "sessionID"), "The name of the cookie for storing session IDs") diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp index ae82dd9..1db2d36 100644 --- a/project2/common/sessionContainer.cpp +++ b/project2/common/sessionContainer.cpp @@ -1,6 +1,6 @@ #include #include "sessionContainer.h" -#include "instanceStore.impl.h" +#include SessionContainer::SessionContainer() { @@ -28,5 +28,5 @@ SessionContainer::GetSession(const boost::uuids::uuid & id) const return s; } -INSTANTIATESTORE(std::string, SessionContainerLoader); +INSTANTIATEVOIDFACTORY(SessionContainer); diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h index b842457..4f62e96 100644 --- a/project2/common/sessionContainer.h +++ b/project2/common/sessionContainer.h @@ -5,6 +5,7 @@ #include #include "session.h" #include "options.h" +#include class SessionContainer : public IntrusivePtrBase { public: @@ -21,7 +22,7 @@ class SessionContainer : public IntrusivePtrBase { virtual SessionPtr getSession(const boost::uuids::uuid & sid) const = 0; }; typedef boost::intrusive_ptr SessionContainerPtr; -typedef GenLoader SessionContainerLoader; +typedef AdHoc::Factory SessionContainerFactory; #endif diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index 866d5b2..c92fe85 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -10,7 +10,7 @@ #include "options.h" #include "logger.h" -class CustomSessionContainerLoaderXml : public SessionContainerLoader::For { +class CustomSessionContainerFactoryXml : public SessionContainerFactory::For, public ComponentLoader { public: void onPeriodic() override { @@ -38,7 +38,7 @@ DECLARE_OPTIONS(SessionContainerXml, "Session XML options") END_OPTIONS(SessionContainerXml) boost::filesystem::path SessionContainerXml::xmlDir; -DECLARE_CUSTOM_COMPONENT_LOADER("xml", SessionContainerXml, CustomSessionContainerLoaderXml, SessionContainerLoader); +NAMEDPLUGIN("xml", CustomSessionContainerFactoryXml, SessionContainerFactory); SessionContainerXml::SessionContainerXml() { diff --git a/project2/xml/sessionXml.h b/project2/xml/sessionXml.h index 4288d9e..d3300bd 100644 --- a/project2/xml/sessionXml.h +++ b/project2/xml/sessionXml.h @@ -18,7 +18,7 @@ class SessionContainerXml : public SessionContainer { private: // Configurables static boost::filesystem::path xmlDir; - friend class CustomSessionContainerLoaderXml; + friend class CustomSessionContainerFactoryXml; }; #endif -- cgit v1.2.3 From 5af1b24c2874f129902f94c6e8da0e05a6008ea2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 26 Sep 2015 20:02:51 +0100 Subject: Compat fix --- project2/sql/rdbmsDataSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 1e2778b..e1091a3 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -251,7 +251,7 @@ RdbmsDataSource::ConnectionInfo::ConnectionInfo(ScriptNodePtr node) : DB::Connection * RdbmsDataSource::ConnectionInfo::connect() const { - return DB::ConnectionFactory::create(typeId, dsn); + return DB::ConnectionFactory::createNew(typeId, dsn); } bool -- cgit v1.2.3 From 6132135ec1e9a9f22df426f9362371ff9dcf43e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 26 Sep 2015 19:18:26 +0100 Subject: Use AdHoc plugins for variable implementations --- project2/basics/functions/dates.cpp | 8 ++++---- project2/basics/functions/strings.cpp | 2 +- project2/cgi/cgiRequestID.cpp | 3 +-- project2/cgi/cgiUriParam.cpp | 2 +- project2/common/unittests/testConfig.cpp | 2 +- project2/common/variables.cpp | 5 +++-- project2/common/variables.h | 6 ++---- project2/common/variables/config.cpp | 4 ++-- project2/common/variables/literal.cpp | 5 ++--- project2/common/variables/localparam.cpp | 2 +- project2/common/variables/lookup.cpp | 2 +- project2/common/variables/param.cpp | 2 +- project2/common/variables/session.cpp | 2 +- project2/files/functions/pwd.cpp | 2 +- project2/files/presenterCache.cpp | 2 +- project2/xml/xmlScriptParser.cpp | 8 ++++---- 16 files changed, 27 insertions(+), 30 deletions(-) diff --git a/project2/basics/functions/dates.cpp b/project2/basics/functions/dates.cpp index b19b921..91a7077 100644 --- a/project2/basics/functions/dates.cpp +++ b/project2/basics/functions/dates.cpp @@ -35,7 +35,7 @@ class ParseDate : public VariableImpl { Variable string; Variable format; }; -DECLARE_COMPONENT_LOADER("parsedate", ParseDate, VariableLoader); +NAMEDFACTORY("parsedate", ParseDate, VariableFactory); class FormatDate : public VariableImpl { public: @@ -57,7 +57,7 @@ class FormatDate : public VariableImpl { Variable date; Variable format; }; -DECLARE_COMPONENT_LOADER("formatdate", FormatDate, VariableLoader); +NAMEDFACTORY("formatdate", FormatDate, VariableFactory); class AdjustDate : public VariableImpl { public: @@ -74,7 +74,7 @@ class AdjustDate : public VariableImpl { Variable date; Variable offset; }; -DECLARE_COMPONENT_LOADER("adjustdate", AdjustDate, VariableLoader); +NAMEDFACTORY("adjustdate", AdjustDate, VariableFactory); class CurrentDate : public VariableImpl { public: @@ -86,5 +86,5 @@ class CurrentDate : public VariableImpl { return boost::posix_time::microsec_clock::universal_time(); } }; -DECLARE_COMPONENT_LOADER("currentdate", CurrentDate, VariableLoader); +NAMEDFACTORY("currentdate", CurrentDate, VariableFactory); diff --git a/project2/basics/functions/strings.cpp b/project2/basics/functions/strings.cpp index 735a781..640cfb3 100644 --- a/project2/basics/functions/strings.cpp +++ b/project2/basics/functions/strings.cpp @@ -23,6 +23,6 @@ class Trim : public VariableImpl { private: Variable string; }; -DECLARE_COMPONENT_LOADER("trim", Trim, VariableLoader); +NAMEDFACTORY("trim", Trim, VariableFactory); diff --git a/project2/cgi/cgiRequestID.cpp b/project2/cgi/cgiRequestID.cpp index 038fff5..88c212c 100644 --- a/project2/cgi/cgiRequestID.cpp +++ b/project2/cgi/cgiRequestID.cpp @@ -50,6 +50,5 @@ class CgiRequestID : public VariableImplDyn { return hashstr.str(); } }; -DECLARE_COMPONENT_LOADER("requestid", CgiRequestID, VariableLoader); - +NAMEDFACTORY("requestid", CgiRequestID, VariableFactory); diff --git a/project2/cgi/cgiUriParam.cpp b/project2/cgi/cgiUriParam.cpp index 985048d..edce6f8 100644 --- a/project2/cgi/cgiUriParam.cpp +++ b/project2/cgi/cgiUriParam.cpp @@ -27,5 +27,5 @@ class VariableUri : public VariableImplDyn { private: Variable index; }; -DECLARE_COMPONENT_LOADER("uri", VariableUri, VariableLoader); +NAMEDFACTORY("uri", VariableUri, VariableFactory); diff --git a/project2/common/unittests/testConfig.cpp b/project2/common/unittests/testConfig.cpp index 8c25394..10e2a04 100644 --- a/project2/common/unittests/testConfig.cpp +++ b/project2/common/unittests/testConfig.cpp @@ -9,7 +9,7 @@ BOOST_AUTO_TEST_CASE( config_application_value ) TestOptionsSource::LoadTestOptions({ { "application.data", "testvalue" } }); - Variable::VariableImplPtr c = VariableLoader::createNew("config", new TestScriptNode({ + Variable::VariableImplPtr c = VariableFactory::createNew("config", new TestScriptNode({ { "name", VariableType("data") } })); BOOST_REQUIRE(c); diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp index 87673a7..71cc36b 100644 --- a/project2/common/variables.cpp +++ b/project2/common/variables.cpp @@ -14,6 +14,7 @@ #include #include "instanceStore.impl.h" #include "execContext.h" +#include VariableImplDyn::VariableImplDyn(ScriptNodePtr e) { @@ -72,7 +73,7 @@ class VariableParent : public VariableImplDyn { const bool attr; const Glib::ustring name; }; -DECLARE_COMPONENT_LOADER("parent", VariableParent, VariableLoader); +NAMEDFACTORY("parent", VariableParent, VariableFactory); Variable::Variable(VariableType def) : @@ -116,5 +117,5 @@ Variable::fromScriptNode(ScriptNodePtr p) return p->variable(); } -INSTANTIATESTORE(std::string, VariableLoader); +INSTANTIATEFACTORY(VariableImpl, ScriptNodePtr); diff --git a/project2/common/variables.h b/project2/common/variables.h index cee9037..89aeeaf 100644 --- a/project2/common/variables.h +++ b/project2/common/variables.h @@ -5,15 +5,13 @@ #include #include #include "intrusivePtrBase.h" -#include "genLoader.h" +#include #include "scripts.h" #include "variableType.h" #include class ExecContext; -SimpleMessageException(UnknownVariableSource); - /// Base class for Project2 variable accessors class VariableImpl : public IntrusivePtrBase { public: @@ -55,7 +53,7 @@ class VariableImplDyn : public VariableImpl { }; /// Base class to create variables -typedef GenLoader VariableLoader; +typedef AdHoc::Factory VariableFactory; #endif diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index e134d07..273b5aa 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -32,7 +32,7 @@ class VariableConfig : public VariableImplDyn { const Glib::ustring name; }; -class VariableConfigLoader : public VariableLoader::For { +class VariableConfigLoader : public VariableFactory::For { public: class AppSettings : public Options::Option { public: @@ -88,5 +88,5 @@ class VariableConfigLoader : public VariableLoader::For { Options * opts; }; -DECLARE_CUSTOM_COMPONENT_LOADER("config", VariableConfigLoader, VariableConfigLoader, VariableLoader); +NAMEDPLUGIN("config", VariableConfigLoader, VariableFactory); diff --git a/project2/common/variables/literal.cpp b/project2/common/variables/literal.cpp index 529be6e..4f8e029 100644 --- a/project2/common/variables/literal.cpp +++ b/project2/common/variables/literal.cpp @@ -72,8 +72,7 @@ VariableLiteral::VarPart::value(ExecContext * ec) const return (*this)(ec); } -DECLARE_COMPONENT_LOADER("literal", VariableLiteral, VariableLoader); -DECLARE_CUSTOM_COMPONENT_LOADER("", VariableLiteralDef, VariableLoader::For, VariableLoader); - +NAMEDFACTORY("literal", VariableLiteral, VariableFactory); +NAMEDFACTORY("", VariableLiteral, VariableFactory); diff --git a/project2/common/variables/localparam.cpp b/project2/common/variables/localparam.cpp index cf2f165..63d6f55 100644 --- a/project2/common/variables/localparam.cpp +++ b/project2/common/variables/localparam.cpp @@ -28,5 +28,5 @@ class VariableLocalParam : public VariableImplDyn { private: const Glib::ustring name; }; -DECLARE_COMPONENT_LOADER("local", VariableLocalParam, VariableLoader); +NAMEDFACTORY("local", VariableLocalParam, VariableFactory); diff --git a/project2/common/variables/lookup.cpp b/project2/common/variables/lookup.cpp index 42ddff2..eac3317 100644 --- a/project2/common/variables/lookup.cpp +++ b/project2/common/variables/lookup.cpp @@ -70,4 +70,4 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { RowSets rowSets; const Glib::ustring name; }; -DECLARE_COMPONENT_LOADER("lookup", VariableLookup, VariableLoader); +NAMEDFACTORY("lookup", VariableLookup, VariableFactory); diff --git a/project2/common/variables/param.cpp b/project2/common/variables/param.cpp index a1ef9b7..8e4125a 100644 --- a/project2/common/variables/param.cpp +++ b/project2/common/variables/param.cpp @@ -27,5 +27,5 @@ class VariableParam : public VariableImplDyn { private: const VariableType name; }; -DECLARE_COMPONENT_LOADER("param", VariableParam, VariableLoader); +NAMEDFACTORY("param", VariableParam, VariableFactory); diff --git a/project2/common/variables/session.cpp b/project2/common/variables/session.cpp index ed2077d..d3331c0 100644 --- a/project2/common/variables/session.cpp +++ b/project2/common/variables/session.cpp @@ -27,5 +27,5 @@ class VariableSession : public VariableImplDyn { private: const Glib::ustring name; }; -DECLARE_COMPONENT_LOADER("session", VariableSession, VariableLoader); +NAMEDFACTORY("session", VariableSession, VariableFactory); diff --git a/project2/files/functions/pwd.cpp b/project2/files/functions/pwd.cpp index 644c934..af06fe7 100644 --- a/project2/files/functions/pwd.cpp +++ b/project2/files/functions/pwd.cpp @@ -16,6 +16,6 @@ class Pwd : public VariableImplDyn { return boost::filesystem::current_path().string(); } }; -DECLARE_COMPONENT_LOADER("pwd", Pwd, VariableLoader); +NAMEDFACTORY("pwd", Pwd, VariableFactory); diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 1c6cae6..9e3c8ad 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -87,7 +87,7 @@ class FilePresenterCache : public PresenterCache { FilePresenterCache(ScriptNodePtr s) : PresenterCache(s), - idProvider(VariableLoader::createNew(Provider, s)) { + idProvider(VariableFactory::createNew(Provider, s)) { } ~FilePresenterCache() { diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index 1c4c798..66b6b0b 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -187,7 +187,7 @@ XmlScriptNode::variable(const Glib::ustring & n) const if (cs.size() == 1) { if (const xmlpp::Element * c = dynamic_cast(cs.front())) { if (const xmlpp::Attribute * source = c->get_attribute("source")) { - return InstanceMap::Get(source->get_value())->create(new XmlScriptNode(c, script)); + return VariableFactory::createNew(source->get_value(), new XmlScriptNode(c, script)); } else { return new VariableLiteral(new XmlScriptNode(c, script)); @@ -201,10 +201,10 @@ VariableImpl * XmlScriptNode::variable(const boost::optional & defaultSource) const { if (const xmlpp::Attribute * source = element->get_attribute("source")) { - return InstanceMap::Get(source->get_value())->create(new XmlScriptNode(element, script)); + return VariableFactory::createNew(source->get_value(), new XmlScriptNode(element, script)); } else if (defaultSource) { - return InstanceMap::Get(defaultSource.get())->create(new XmlScriptNode(element, script)); + return VariableFactory::createNew(defaultSource.get(), new XmlScriptNode(element, script)); } else { return new VariableLiteral(new XmlScriptNode(element, script)); @@ -223,7 +223,7 @@ XmlScriptNode::applyValue(const Glib::ustring & n, VariableType & val, ExecConte if (const xmlpp::Element * c = dynamic_cast(cs.front())) { boost::intrusive_ptr v; if (const xmlpp::Attribute * source = c->get_attribute("source")) { - v = InstanceMap::Get(source->get_value())->create(new XmlScriptNode(c, script)); + v = VariableFactory::createNew(source->get_value(), new XmlScriptNode(c, script)); } else { v = new VariableLiteral(new XmlScriptNode(c, script)); -- cgit v1.2.3 From f8d4460cd0f998f6edf37c0933c5a3438ac452b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 26 Sep 2015 19:27:50 +0100 Subject: Use AdHoc plugins for decompressors --- project2/compression/decompressStream.cpp | 3 +-- project2/compression/decompressor.cpp | 7 +++++++ project2/compression/decompressor.h | 8 ++++---- project2/compression/gzip.cpp | 2 +- project2/compression/nocomp.cpp | 3 +-- 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 project2/compression/decompressor.cpp diff --git a/project2/compression/decompressStream.cpp b/project2/compression/decompressStream.cpp index c1d52ab..b986a0a 100644 --- a/project2/compression/decompressStream.cpp +++ b/project2/compression/decompressStream.cpp @@ -17,7 +17,7 @@ class DecompressStream : public Stream { void runStream(const Sink & sink, ExecContext * ec) const { - DecompressorPtr decomp = DecompressorLoader::getFor(method(ec))->create(); + DecompressorPtr decomp = DecompressorFactory::createNew(method(ec)); stream->runStream([&](const char * data, size_t len) -> size_t { decomp->decompress(data, len, sink); return len; @@ -29,5 +29,4 @@ class DecompressStream : public Stream { }; DECLARE_LOADER("decompstream", DecompressStream); -INSTANTIATESTORE(std::string, DecompressorLoader); diff --git a/project2/compression/decompressor.cpp b/project2/compression/decompressor.cpp new file mode 100644 index 0000000..b727aa8 --- /dev/null +++ b/project2/compression/decompressor.cpp @@ -0,0 +1,7 @@ +#include "decompressor.h" +#include + +Decompressor::~Decompressor() = default; + +INSTANTIATEVOIDFACTORY(Decompressor); + diff --git a/project2/compression/decompressor.h b/project2/compression/decompressor.h index c57ff61..c15fef2 100644 --- a/project2/compression/decompressor.h +++ b/project2/compression/decompressor.h @@ -3,15 +3,15 @@ #include "stream.h" #include "intrusivePtrBase.h" +#include class Decompressor : public IntrusivePtrBase { public: - virtual ~Decompressor() - { - } + virtual ~Decompressor(); + virtual void decompress(const char * dataIn, size_t lengthIn, const Stream::Sink &) = 0; }; typedef boost::intrusive_ptr DecompressorPtr; -typedef GenLoader DecompressorLoader; +typedef AdHoc::Factory DecompressorFactory; #endif diff --git a/project2/compression/gzip.cpp b/project2/compression/gzip.cpp index 2bf0a8d..653143f 100644 --- a/project2/compression/gzip.cpp +++ b/project2/compression/gzip.cpp @@ -49,5 +49,5 @@ class GZip : public Decompressor { z_stream strm; int status; }; -DECLARE_GENERIC_LOADER("gz", DecompressorLoader, GZip); +NAMEDFACTORY("gz", GZip, DecompressorFactory); diff --git a/project2/compression/nocomp.cpp b/project2/compression/nocomp.cpp index 6861171..78f4d4c 100644 --- a/project2/compression/nocomp.cpp +++ b/project2/compression/nocomp.cpp @@ -9,6 +9,5 @@ class NoComp : public Decompressor { sink(data, len); } }; -DECLARE_GENERIC_LOADER("nocomp", DecompressorLoader, NoComp); - +NAMEDFACTORY("nocomp", NoComp, DecompressorFactory); -- cgit v1.2.3 From d2b82979ee18ad1e827ab79834e6e5b762f35725 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 01:37:56 +0100 Subject: Suport finding ComponentLoaders in AdHoc Plugins --- project2/common/plugable.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/project2/common/plugable.cpp b/project2/common/plugable.cpp index 969f530..15d8cda 100644 --- a/project2/common/plugable.cpp +++ b/project2/common/plugable.cpp @@ -1,8 +1,15 @@ #include "plugable.h" +#include "componentLoader.h" +#include void Plugable::onAllComponents(const boost::function & func) { InstanceSet::OnAll(func); + for(auto p : AdHoc::PluginManager::getDefault()->getAll()) { + if (auto c = dynamic_cast(p->implementation())) { + func(c); + } + } } -- cgit v1.2.3 From 22d80295755a371cba345751aea348b5c5aae806 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 01:38:35 +0100 Subject: Use AdHoc plugins for daemons --- project2/daemon/lib/daemon.cpp | 4 ++-- project2/daemon/lib/daemon.h | 4 ++-- project2/daemon/p2daemonAppEngine.cpp | 6 +++--- project2/ice/iceDaemon.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/project2/daemon/lib/daemon.cpp b/project2/daemon/lib/daemon.cpp index bde0f45..f4af1c8 100644 --- a/project2/daemon/lib/daemon.cpp +++ b/project2/daemon/lib/daemon.cpp @@ -1,5 +1,5 @@ #include "daemon.h" -#include "instanceStore.impl.h" +#include Daemon::Daemon() { @@ -19,5 +19,5 @@ Daemon::teardown() const { } -INSTANTIATESTORE(std::string, DaemonLoader); +INSTANTIATEFACTORY(Daemon, int &, char **); diff --git a/project2/daemon/lib/daemon.h b/project2/daemon/lib/daemon.h index d565e57..261d2f0 100644 --- a/project2/daemon/lib/daemon.h +++ b/project2/daemon/lib/daemon.h @@ -2,7 +2,7 @@ #define DAEMON_H #include -#include +#include #include class Daemon : public IntrusivePtrBase { @@ -17,7 +17,7 @@ class Daemon : public IntrusivePtrBase { }; typedef boost::intrusive_ptr DaemonPtr; -typedef GenLoader DaemonLoader; +typedef AdHoc::Factory DaemonFactory; #endif diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp index 42b4cda..6ed0472 100644 --- a/project2/daemon/p2daemonAppEngine.cpp +++ b/project2/daemon/p2daemonAppEngine.cpp @@ -53,8 +53,8 @@ END_OPTIONS(DaemonAppEngine); DaemonAppEngine::DaemonAppEngine(int argc, char ** argv) : main_loop(Glib::MainLoop::create()), - daemonFactory(boost::bind(&DaemonLoader::create, - boost::bind(DaemonLoader::getFor, boost::cref(daemonType)), argc, argv)) + daemonFactory(boost::bind(&::DaemonFactory::create, + boost::bind(::DaemonFactory::get, boost::cref(daemonType)), argc, argv)) { } @@ -174,6 +174,6 @@ class DummyDaemon : public Daemon { private: mutable bool stop; }; -DECLARE_GENERIC_LOADER("dummydaemon", DaemonLoader, DummyDaemon); +NAMEDFACTORY("dummydaemon", DummyDaemon, DaemonFactory); #endif diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index ccd64a0..15ae1b0 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -24,14 +24,14 @@ std::string IceDaemon::viewRoot; std::string IceDaemon::taskRoot; IceBase::Libs IceDaemon::libs; -class IceDaemonLoader : public DaemonLoader::For { +class IceDaemonFactory : public DaemonFactory::For, public ComponentLoader { public: void onConfigLoad() override { IceBase::FinaliseLoad(IceDaemon::libs); } }; -DECLARE_CUSTOM_COMPONENT_LOADER("ice", IceDaemon, IceDaemonLoader, DaemonLoader); +NAMEDPLUGIN("ice", IceDaemonFactory, DaemonFactory); DECLARE_OPTIONS(IceDaemon, "ICE Daemon Options") ("ice.daemon.viewRoot", Options::value(&viewRoot, "views"), "The folder in which to find view scripts") -- cgit v1.2.3 From 32a83c9dc929d05e1b3c01a2527ae63dc115c5c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 01:57:15 +0100 Subject: Use AdHoc plugins for ICE daemon modules --- project2/ice/iceDaemon.cpp | 6 +++--- project2/ice/iceModule.cpp | 4 ++-- project2/ice/iceModule.h | 3 ++- project2/ice/slice2Daemon.cpp | 2 +- project2/ice/unittests/testDaemon.cpp | 6 +++--- project2/ice/unittests/testDaemonCompile.cpp | 4 ++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index 15ae1b0..0f56a33 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -72,9 +72,9 @@ IceDaemon::setup() const Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(adapterName, adapterEndpoint); Logger()->messagebf(LOG_DEBUG, " %s installing servants...", __PRETTY_FUNCTION__); - InstanceSet::OnAll([this, adapter](IceDaemonAdapterHandlerLoader * loader) { - loader->create(this)->add(adapter, ic); - }); + for(auto p : AdHoc::PluginManager::getDefault()->getAll()) { + p->implementation()->create(this)->add(adapter, ic); + } Logger()->messagebf(LOG_DEBUG, " %s starting...", __PRETTY_FUNCTION__); adapter->activate(); diff --git a/project2/ice/iceModule.cpp b/project2/ice/iceModule.cpp index 7e39858..309e9a5 100644 --- a/project2/ice/iceModule.cpp +++ b/project2/ice/iceModule.cpp @@ -1,7 +1,7 @@ #include #include "iceModule.h" #include "iceDaemon.h" -#include "instanceStore.impl.h" +#include IceDaemonModule::IceDaemonModule(const std::string & n, const IceDaemon * id) : name(n), @@ -31,5 +31,5 @@ IceDaemonModule::remove(Ice::ObjectAdapterPtr adapter, Ice::CommunicatorPtr ic) adapter->remove(ic->stringToIdentity(name)); } -INSTANTIATESTORE(std::string, IceDaemonAdapterHandlerLoader); +INSTANTIATEFACTORY(IceDaemonModule, const IceDaemon *); diff --git a/project2/ice/iceModule.h b/project2/ice/iceModule.h index fcdd3e4..49aa63b 100644 --- a/project2/ice/iceModule.h +++ b/project2/ice/iceModule.h @@ -9,6 +9,7 @@ #include #include #include "iceConvert.h" +#include typedef std::map ParamMap; class IceDaemon; @@ -29,7 +30,7 @@ class IceDaemonModule : virtual public ::Ice::Object { const IceDaemon * const iceDaemon; }; -typedef GenLoader IceDaemonAdapterHandlerLoader; +typedef AdHoc::Factory IceDaemonAdapterHandlerFactory; #endif diff --git a/project2/ice/slice2Daemon.cpp b/project2/ice/slice2Daemon.cpp index 177e406..41e71f1 100644 --- a/project2/ice/slice2Daemon.cpp +++ b/project2/ice/slice2Daemon.cpp @@ -65,7 +65,7 @@ Slice2Daemon::visitClassDefEnd(const Slice::ClassDefPtr & c) { if (code) { fprintf(code, "\t}; // class %sImpl\n\n", c->name().c_str()); - fprintf(code, "\tDECLARE_GENERIC_LOADER(\"%s-%s\", IceDaemonAdapterHandlerLoader, %sImpl);\n\n", + fprintf(code, "\tNAMEDFACTORY(\"%s-%s\", %sImpl, IceDaemonAdapterHandlerFactory);\n\n", module.c_str(), c->name().c_str(), c->name().c_str()); } components += 1; diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index f12935d..a1985a4 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -96,8 +96,8 @@ void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest-SimpleInterface")); - BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTestComplex-ComplexInterface")); + BOOST_REQUIRE(IceDaemonAdapterHandlerFactory::get("UnitTest-SimpleInterface")); + BOOST_REQUIRE(IceDaemonAdapterHandlerFactory::get("UnitTestComplex-ComplexInterface")); int dummy = 0; BOOST_TEST_CHECKPOINT("Run daemon"); @@ -195,7 +195,7 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest-SimpleInterface", NULL), NotSupported); + BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerFactory::createNew("UnitTest-SimpleInterface", NULL), AdHoc::NoSuchPluginException); } BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); diff --git a/project2/ice/unittests/testDaemonCompile.cpp b/project2/ice/unittests/testDaemonCompile.cpp index 95fb6f2..c3f7064 100644 --- a/project2/ice/unittests/testDaemonCompile.cpp +++ b/project2/ice/unittests/testDaemonCompile.cpp @@ -18,7 +18,7 @@ void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest-SimpleInterface")); + BOOST_REQUIRE(IceDaemonAdapterHandlerFactory::get("UnitTest-SimpleInterface")); } static @@ -26,7 +26,7 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerLoader::createNew("UnitTest-SimpleInterface", NULL), NotSupported); + BOOST_REQUIRE_THROW(IceDaemonAdapterHandlerFactory::createNew("UnitTest-SimpleInterface", NULL), AdHoc::NoSuchPluginException); } BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); -- cgit v1.2.3 From aea0cfc52472af5c6e848617507db2744a28d570 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 19:59:31 +0100 Subject: Use AdHoc plugins for CGI routers --- project2/cgi/cgiAppEngine.cpp | 4 ++-- project2/cgi/cgiAppEngine.h | 2 +- project2/cgi/cgiProgRouter.cpp | 16 ++++++++-------- project2/cgi/cgiRequestContext.cpp | 2 +- project2/cgi/cgiRouter.cpp | 4 ++-- project2/cgi/cgiRouter.h | 3 ++- project2/cgi/cgiSimpleRouter.cpp | 2 +- 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 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 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 { +class ProgRouterFactory : public RouterFactory::For, public ComponentLoader { public: - void onBefore() + void onBefore() override { routingTable.onBefore(); } @@ -139,14 +139,14 @@ class ProgRouterLoader : public RouterLoader::For { 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 -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 #include +#include class MultiRowSetPresenter; @@ -15,7 +16,7 @@ class Router : public IntrusivePtrBase { virtual void present(const MultiRowSetPresenter * p) const = 0; }; typedef boost::intrusive_ptr RouterPtr; -typedef GenLoader RouterLoader; +typedef AdHoc::Factory 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 elems; }; -DECLARE_GENERIC_LOADER("simple", RouterLoader, SimpleRouter); +NAMEDFACTORY("simple", SimpleRouter, RouterFactory); -- cgit v1.2.3 From 00e36ad1c77c478bf86abef5751a5d027c3486f3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 28 Sep 2015 23:45:17 +0100 Subject: Use AdHoc plugins for options --- project2/basics/options/preload.cpp | 6 +++--- project2/basics/options/showHelp.cpp | 4 +++- project2/common/options.cpp | 4 ++-- project2/common/options.h | 14 ++++++-------- project2/common/optionsSource.cpp | 25 +++++++++++++++---------- project2/common/variables/config.cpp | 4 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/project2/basics/options/preload.cpp b/project2/basics/options/preload.cpp index 5cf42e8..4781abb 100644 --- a/project2/basics/options/preload.cpp +++ b/project2/basics/options/preload.cpp @@ -19,7 +19,7 @@ class Preload { static void LoadLibrary(const VariableType & librarypath) { - const auto beforeOpts = InstanceSet::GetAll(); + const auto beforeOpts = AdHoc::PluginManager::getDefault()->getAll(); void * handle = dlopen(librarypath, RTLD_GLOBAL | RTLD_NOW); if (handle) { @@ -32,10 +32,10 @@ class Preload { } libs[librarypath.as()] = boost::shared_ptr(handle, &dlclose); - const auto afterOpts = InstanceSet::GetAll(); + const auto afterOpts = AdHoc::PluginManager::getDefault()->getAll(); for (const auto & opt : afterOpts) { if (std::find(beforeOpts.begin(), beforeOpts.end(), opt) == beforeOpts.end()) { - opt->reset(); + opt->implementation()->reset(); } } } diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index 86dbc6f..b7f481c 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -8,7 +8,9 @@ void ShowHelpComponent::onConfigLoad() if (!showHelp) return; fprintf(stdout, "Help\n"); - InstanceSet::OnAll(boost::bind(&ShowHelpComponent::outputOptions, this, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + outputOptions(opts->implementation()); + } exit(1); } diff --git a/project2/common/options.cpp b/project2/common/options.cpp index c1ed762..7819bd9 100644 --- a/project2/common/options.cpp +++ b/project2/common/options.cpp @@ -1,6 +1,6 @@ #include #include "options.h" -#include "instanceStore.impl.h" +#include class NamedOption : public Options::Option { public: @@ -169,5 +169,5 @@ Options::InstanceTarget::assign(const VariableType & value) const assigner(value); } -INSTANTIATESTORE(std::string, Options); +INSTANTIATEPLUGINOF(Options); diff --git a/project2/common/options.h b/project2/common/options.h index 0d90826..6e734bb 100644 --- a/project2/common/options.h +++ b/project2/common/options.h @@ -9,9 +9,9 @@ #include #include #include "variableType.h" -#include "plugable.h" +#include -class Options { +class Options : public AdHoc::AbstractPluginImplementation { public: class Target; @@ -99,22 +99,20 @@ class Options { OptionList options; }; -// Registration helpers -// These work pluggable component style -typedef PluginsSameBase OptionsSets; - #define DECLARE_OPTIONS(Type, Label) \ static void init_options_##Type() __attribute__ ((constructor(200))); \ static void init_options_##Type() { \ Options * o = new Options(Label); \ Type::InitOptions(*o); \ - OptionsSets::Add(#Type, o); } \ + AdHoc::PluginManager::getDefault()->add(o, #Type, __FILE__, __LINE__); } \ void Type::InitOptions(Options & o) { o #define END_OPTIONS(Type) \ ;} \ static void kill_options_##Type() __attribute__ ((destructor(200))); \ - static void kill_options_##Type() { OptionsSets::Remove(#Type); } + static void kill_options_##Type() { \ + AdHoc::PluginManager::getDefault()->remove(#Type); \ + } #define INITOPTIONS \ static void InitOptions(Options &) diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 0e1d751..c74243d 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -5,17 +5,18 @@ class DefaultConfigConsumer : public ConfigConsumer { public: void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const { - InstanceSet::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->consume(n, p, v, cp); + } } const Options::Option * get(const Glib::ustring & n) const { - const Options::Option * rtn = NULL; - InstanceSet::OnAll([n,&rtn](const Options * os) { - const Options::Option * o = os->find(n); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + const Options::Option * o = opts->implementation()->find(n); if (o) { - rtn = o; + return o; } - }); - return rtn; + } + return nullptr; } }; @@ -27,7 +28,9 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) { const auto & configs = InstanceSet::GetAll(); if (std::find_if(configs.begin(), configs.end(), [](const OptionsSourcePtr & c) { return c->modifiedTime() > loadedTime; }) != configs.end()) { - InstanceSet::OnAll(boost::bind(&Options::reset, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->reset(); + } DefaultConfigConsumer dcc; std::set> loadedConfigs; @@ -40,7 +43,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) } } Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); - + loadedTime = boost::posix_time::microsec_clock::universal_time(); Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); } @@ -49,7 +52,9 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) void OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts) { - InstanceSet::OnAll(boost::bind(&Options::reset, _1)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->reset(); + } DefaultConfigConsumer dcc; opts->loadInto(dcc, platform); diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index 273b5aa..1696f43 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -72,12 +72,12 @@ class VariableConfigLoader : public VariableFactory::For { opts(new Options("Variables - ModConfig options")) { (*opts)(new AppSettings()); - OptionsSets::Add(typeid(AppSettings).name(), opts); + AdHoc::PluginManager::getDefault()->add(opts, typeid(AppSettings).name(), __FILE__, __LINE__); } ~VariableConfigLoader() { - OptionsSets::Remove(typeid(AppSettings).name()); + AdHoc::PluginManager::getDefault()->remove(typeid(AppSettings).name()); } const Options * options() const { -- cgit v1.2.3 From 3ca7fa124296a39de60676a27f33f545b36f1474 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Sep 2015 00:26:13 +0100 Subject: Use AdHoc plugins for options sources --- project2/cgi/testCgi.cpp | 10 +++++----- project2/common/optionsSource.cpp | 16 ++++++++-------- project2/common/optionsSource.h | 8 ++------ project2/console/p2consoleMain.cpp | 3 ++- project2/daemon/p2daemonMain.cpp | 4 ++-- project2/files/optionsSource.cpp | 14 +++++++++++--- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index 4ab13d1..b61a475 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -27,14 +27,14 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput { typedef std::map OptStore; TestInput(int argc, char ** argv) { - OptionsSources::Add("_1", new FileOptions(".testCgi.settings")); - OptionsSources::Add("_2", new CommandLineArguments(argc, argv, - [](const char * url) { urls.push_back(url); })); + AdHoc::PluginManager::getDefault()->add(new FileOptions(".testCgi.settings"), "_1", __FILE__, __LINE__); + AdHoc::PluginManager::getDefault()->add( + new CommandLineArguments(argc, argv, [](const char * url) { urls.push_back(url); }), "_2", __FILE__, __LINE__); } ~TestInput() { - OptionsSources::Remove("_1"); - OptionsSources::Remove("_2"); + AdHoc::PluginManager::getDefault()->remove("_1"); + AdHoc::PluginManager::getDefault()->remove("_2"); } std::string getenv(const std::string & varName) const diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index c74243d..1739ed5 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -1,6 +1,6 @@ #include "optionsSource.h" #include "logger.h" -#include "instanceStore.impl.h" +#include class DefaultConfigConsumer : public ConfigConsumer { public: @@ -26,19 +26,19 @@ boost::posix_time::ptime OptionsSource::loadedTime = boost::posix_time::special_ void OptionsSource::loadSources(const Options::CurrentPlatform & platform) { - const auto & configs = InstanceSet::GetAll(); - if (std::find_if(configs.begin(), configs.end(), [](const OptionsSourcePtr & c) { return c->modifiedTime() > loadedTime; }) != configs.end()) { + const auto & configs = AdHoc::PluginManager::getDefault()->getAll(); + if (std::find_if(configs.begin(), configs.end(), [](boost::shared_ptr> c) { return c->implementation()->modifiedTime() > loadedTime; }) != configs.end()) { for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { opts->implementation()->reset(); } DefaultConfigConsumer dcc; - std::set> loadedConfigs; + std::set loadedConfigs; while (loadedConfigs.size() != configs.size()) { for (const auto & c : configs) { - if (loadedConfigs.find(c) == loadedConfigs.end()) { - c->loadInto(dcc, platform); - loadedConfigs.insert(c); + if (loadedConfigs.find(c->implementation()) == loadedConfigs.end()) { + c->implementation()->loadInto(dcc, platform); + loadedConfigs.insert(c->implementation()); } } } @@ -64,5 +64,5 @@ OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSour Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); } -INSTANTIATESTORE(std::string, OptionsSource); +INSTANTIATEPLUGINOF(OptionsSource); diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h index 7f1deee..32c43ed 100644 --- a/project2/common/optionsSource.h +++ b/project2/common/optionsSource.h @@ -18,7 +18,7 @@ class OptionsSource; typedef boost::shared_ptr OptionsSourcePtr; /// Base class of things that load options -class OptionsSource { +class OptionsSource : public AdHoc::AbstractPluginImplementation { public: virtual ~OptionsSource() = default; @@ -32,12 +32,8 @@ class OptionsSource { static boost::posix_time::ptime loadedTime; }; -typedef PluginsSameBase OptionsSources; #define DECLARE_OPTIONSSOURCE(Id, Inst) \ - static void init_optionsSource() __attribute__ ((constructor(200))); \ - static void init_optionsSource() { OptionsSources::Add(Id, Inst); } \ - static void kill_optionsSource() __attribute__ ((destructor(200))); \ - static void kill_optionsSource() { OptionsSources::Remove(Id); } + NAMEDPLUGIN(Id, Inst, OptionsSource) #endif diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index 62f09b0..87a3293 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -6,7 +6,8 @@ int main(int argc, char ** argv) { - OptionsSources::Add("", new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript)); + AdHoc::PluginManager::getDefault()->add( + new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript), "", __FILE__, __LINE__); Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); ConsoleApplicationEngine app; diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp index 95de88e..0da41f3 100644 --- a/project2/daemon/p2daemonMain.cpp +++ b/project2/daemon/p2daemonMain.cpp @@ -45,8 +45,8 @@ int main(int argc, char ** argv) { Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); - OptionsSources::Add("_2", new CommandLineArguments(argc, argv, - [](const char * a) { throw UnsupportedArguments(a); })); + AdHoc::PluginManager::getDefault()->add( + new CommandLineArguments(argc, argv, [](const char * a) { throw UnsupportedArguments(a); }), "_2", __FILE__, __LINE__); DaemonAppEngine dae(argc, argv); OptionsSource::loadSources([] { return DaemonAppEngine::reqPlatform;} ); diff --git a/project2/files/optionsSource.cpp b/project2/files/optionsSource.cpp index 8e98df0..2ce320c 100644 --- a/project2/files/optionsSource.cpp +++ b/project2/files/optionsSource.cpp @@ -38,19 +38,27 @@ FileOptions::modifiedTime() const FileOptions::ExtraFileOptions FileOptions::extraFileOptions; +class DefaultFileOptions : public FileOptions { + public: + DefaultFileOptions() : + FileOptions(".p2config") + { + } +}; + // Z... process last :) -DECLARE_OPTIONSSOURCE("Z_configfile", new FileOptions(".p2config")) +DECLARE_OPTIONSSOURCE("Z_configfile", DefaultFileOptions) DECLARE_OPTIONS(FileOptions, "File Options options") ("file.options.read", Options::functions( [](const VariableType & vt) { auto fo = new FileOptions(vt.as()); extraFileOptions[vt] = boost::shared_ptr(fo); - OptionsSources::Add(vt, fo); + AdHoc::PluginManager::getDefault()->add(fo, vt, __FILE__, __LINE__); }, []() { for (const auto & fo : extraFileOptions) { - OptionsSources::Remove(fo.first); + AdHoc::PluginManager::getDefault()->remove(fo.first); } extraFileOptions.clear(); }), -- cgit v1.2.3 From afa2f269aae385b00800bb8a351f6687ddc627a2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Sep 2015 09:05:23 +0100 Subject: Use AdHoc plugins for loggers --- project2/common/logger.cpp | 13 +++++++------ project2/common/logger.h | 15 ++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/project2/common/logger.cpp b/project2/common/logger.cpp index 98aaf0b..64df516 100644 --- a/project2/common/logger.cpp +++ b/project2/common/logger.cpp @@ -2,7 +2,7 @@ #define SYSLOG_NAMES 1 // Enables the definition of names in syslog.h #include "logger.h" -#include "instanceStore.impl.h" +#include Log Logger::log; @@ -17,7 +17,7 @@ Log::~Log() } void -Log::setLoggerAt(LogDriverLoader * ldr, int level) +Log::setLoggerAt(LogDriverFactory * ldr, int level) { if (level == -1) { logs.erase(ldr); @@ -26,9 +26,9 @@ Log::setLoggerAt(LogDriverLoader * ldr, int level) logs[ldr] = ldr->create(); } lowestLevel = -1; - for (const auto & log : InstanceSet::GetAll()) { - if (log->loggerLevel() > lowestLevel) { - lowestLevel = log->loggerLevel(); + for (const auto & log : AdHoc::PluginManager::getDefault()->getAll()) { + if (log->implementation()->loggerLevel() > lowestLevel) { + lowestLevel = log->implementation()->loggerLevel(); } } } @@ -102,5 +102,6 @@ LogDriverBase::~LogDriverBase() { } -INSTANTIATESTORE(std::string, LogDriverLoader); +template class AdHoc::Factory; +INSTANTIATEPLUGINOF(LogDriverFactory) diff --git a/project2/common/logger.h b/project2/common/logger.h index 0a6398e..cc4409f 100644 --- a/project2/common/logger.h +++ b/project2/common/logger.h @@ -8,7 +8,8 @@ #include #include #include "intrusivePtrBase.h" -#include "genLoader.h" +#include "componentLoader.h" +#include #include /// Base class for classes providing a logging facility @@ -20,7 +21,7 @@ class LogDriverBase : public virtual IntrusivePtrBase { virtual void message(int priority, const char * msg) const = 0; }; -class LogDriverLoader : public GenLoader { +class LogDriverFactory : public AdHoc::Factory { public: virtual int loggerLevel() const = 0; }; @@ -28,12 +29,12 @@ class LogDriverLoader : public GenLoader { class Log { public: typedef boost::intrusive_ptr LogDriverBasePtr; - typedef std::map LogDrivers; + typedef std::map LogDrivers; Log(); ~Log(); - void setLoggerAt(LogDriverLoader *, int level); + void setLoggerAt(LogDriverFactory *, int level); void message(int priority, const char * msg) const; void messagef(int priority, const char * msgfmt, ...) const __attribute__ ((format (printf, 3, 4))); @@ -68,9 +69,9 @@ class Logger { }; template -class LogDriverLoaderImpl : public LogDriverLoader::For { +class LogDriverFactoryImpl : public LogDriverFactory, public ComponentLoader { public: - LogDriverLoaderImpl() : + LogDriverFactoryImpl() : level(LoggerType::level) { } @@ -94,7 +95,7 @@ class LogDriverLoaderImpl : public LogDriverLoader::For instance; }; #define DECLARE_LOGGER_LOADER(N, T) \ - DECLARE_CUSTOM_COMPONENT_LOADER(N, T, LogDriverLoaderImpl, LogDriverLoader); + NAMEDPLUGIN(N, LogDriverFactoryImpl, LogDriverFactory) #endif -- cgit v1.2.3 From 5dd982e1ffb2d7c10a4dbb891c97489da177944f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Sep 2015 21:21:23 +0100 Subject: Remove NoOutputExecute for not being a thing --- project2/common/iHaveSubTasks.cpp | 2 +- project2/common/iHaveSubTasks.h | 7 ++++--- project2/common/noOutputExecute.cpp | 17 ----------------- project2/common/noOutputExecute.h | 23 ----------------------- project2/common/task.cpp | 8 ++++++-- project2/common/task.h | 5 +++-- project2/common/taskHost.cpp | 1 - project2/common/taskHost.h | 3 --- project2/files/writeStream.cpp | 1 + project2/sql/sqlMergeTask.cpp | 6 +++--- project2/sql/sqlTask.cpp | 8 ++++---- project2/sql/sqlTask.h | 7 ++++--- 12 files changed, 26 insertions(+), 62 deletions(-) delete mode 100644 project2/common/noOutputExecute.cpp delete mode 100644 project2/common/noOutputExecute.h diff --git a/project2/common/iHaveSubTasks.cpp b/project2/common/iHaveSubTasks.cpp index 6371475..578601f 100644 --- a/project2/common/iHaveSubTasks.cpp +++ b/project2/common/iHaveSubTasks.cpp @@ -3,7 +3,7 @@ IHaveSubTasks::IHaveSubTasks(ScriptNodePtr e) : SourceObject(e), - NoOutputExecute(e) + Task(e) { } diff --git a/project2/common/iHaveSubTasks.h b/project2/common/iHaveSubTasks.h index 3e7d16c..1fd5041 100644 --- a/project2/common/iHaveSubTasks.h +++ b/project2/common/iHaveSubTasks.h @@ -1,12 +1,13 @@ #ifndef HASSUBTASKS_H #define HASSUBTASKS_H -#include "noOutputExecute.h" +#include "task.h" +#include "scriptStorage.h" /// Base class for Project2 compoments that perform actions, but product no output -class IHaveSubTasks : public NoOutputExecute { +class IHaveSubTasks : public Task { public: - typedef ANONORDEREDSTORAGEOF(NoOutputExecute) Tasks; + typedef ANONORDEREDSTORAGEOF(Task) Tasks; IHaveSubTasks(ScriptNodePtr p); virtual ~IHaveSubTasks(); diff --git a/project2/common/noOutputExecute.cpp b/project2/common/noOutputExecute.cpp deleted file mode 100644 index bed7bf0..0000000 --- a/project2/common/noOutputExecute.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "noOutputExecute.h" - -NoOutputExecute::NoOutputExecute(ScriptNodePtr p) : - SourceObject(p) -{ -} - -NoOutputExecute::NoOutputExecute(const std::string & n) : - SourceObject(n) -{ -} - -NoOutputExecute::~NoOutputExecute() -{ -} - diff --git a/project2/common/noOutputExecute.h b/project2/common/noOutputExecute.h deleted file mode 100644 index 61d03b5..0000000 --- a/project2/common/noOutputExecute.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NOOUTPUTEXECUTE_H -#define NOOUTPUTEXECUTE_H - -#include "sourceObject.h" -#include "scriptStorage.h" - -class NoOutputExecute; -class ExecContext; -typedef boost::intrusive_ptr NoOutputExecutePtr; - -/// Base class for Project2 compoments that perform actions, but product no output -class NoOutputExecute : public virtual SourceObject { - public: - NoOutputExecute(ScriptNodePtr p); - NoOutputExecute(const std::string & n); - - virtual ~NoOutputExecute(); - - virtual void execute(ExecContext *) const = 0; -}; - -#endif - diff --git a/project2/common/task.cpp b/project2/common/task.cpp index 2cfe761..bee3767 100644 --- a/project2/common/task.cpp +++ b/project2/common/task.cpp @@ -2,8 +2,12 @@ #include "task.h" Task::Task(ScriptNodePtr p) : - SourceObject(p), - NoOutputExecute(p) + SourceObject(p) +{ +} + +Task::Task(const std::string & n) : + SourceObject(n) { } diff --git a/project2/common/task.h b/project2/common/task.h index 15ccfbd..d29b533 100644 --- a/project2/common/task.h +++ b/project2/common/task.h @@ -2,12 +2,13 @@ #define TASK_H #include "sourceObject.h" -#include "noOutputExecute.h" +#include "execContext.h" /// Base class for Project2 components that perform some specific task -class Task : public NoOutputExecute { +class Task : public virtual SourceObject { public: Task(ScriptNodePtr p); + Task(const std::string & name); virtual ~Task(); virtual void execute(ExecContext *) const = 0; }; diff --git a/project2/common/taskHost.cpp b/project2/common/taskHost.cpp index 035e701..23b75fe 100644 --- a/project2/common/taskHost.cpp +++ b/project2/common/taskHost.cpp @@ -1,6 +1,5 @@ #include #include "taskHost.h" -#include "noOutputExecute.h" #include "dataSource.h" #include #include "scriptLoader.h" diff --git a/project2/common/taskHost.h b/project2/common/taskHost.h index e4b8b3a..84c04c9 100644 --- a/project2/common/taskHost.h +++ b/project2/common/taskHost.h @@ -6,9 +6,6 @@ #include "iHaveSubTasks.h" #include "commonObjects.h" -class NoOutputExecute; -class DataSource; - class TaskHost : public IHaveSubTasks, virtual public CheckHost, virtual public CommonObjects { protected: TaskHost(ScriptNodePtr script); diff --git a/project2/files/writeStream.cpp b/project2/files/writeStream.cpp index 954ec8b..9946ec6 100644 --- a/project2/files/writeStream.cpp +++ b/project2/files/writeStream.cpp @@ -2,6 +2,7 @@ #include "task.h" #include "stream.h" #include "variables.h" +#include #include SimpleMessageException(OpenTargetFile); diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp index b6c504f..ea334eb 100644 --- a/project2/sql/sqlMergeTask.cpp +++ b/project2/sql/sqlMergeTask.cpp @@ -46,7 +46,7 @@ DECLARE_LOADER("sqlmergeinsert", SqlMergeInsert); // Conversion logic SqlMergeTask::SqlMergeTask(const std::string & datasource, const std::string & target) : SourceObject(__PRETTY_FUNCTION__), - Task(NULL), + Task(__PRETTY_FUNCTION__), insteadOfDelete(NULL), updateWhere(NULL), patchOrder(NULL), @@ -265,11 +265,11 @@ SqlMergeTask::insertCommand() const return destdb->newModifyCommand(ins); } -class Populate : public NoOutputExecute { +class Populate : public Task { public: Populate(DB::ModifyCommand * c) : SourceObject(__FUNCTION__), - NoOutputExecute(__FUNCTION__), + Task(__FUNCTION__), cmd(c) { } diff --git a/project2/sql/sqlTask.cpp b/project2/sql/sqlTask.cpp index a98748f..94f5102 100644 --- a/project2/sql/sqlTask.cpp +++ b/project2/sql/sqlTask.cpp @@ -17,8 +17,8 @@ SqlTask::SqlTask(ScriptNodePtr p) : sqlCommand(p->child("sql")), db(NULL) { - p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into(&changesNOEs)); - p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into(&noChangesNOEs)); + p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into(&changesTasks)); + p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into(&noChangesTasks)); } SqlTask::~SqlTask() @@ -40,12 +40,12 @@ SqlTask::execute(ExecContext * ec) const unsigned int offset = 0; sqlCommand.bindParams(ec, modify.get(), offset); if (modify->execute() == 0) { - for (const SubNOEs::value_type & sq : noChangesNOEs) { + for (const auto & sq : noChangesTasks) { sq->execute(ec); } } else { - for (const SubNOEs::value_type & sq : changesNOEs) { + for (const auto & sq : changesTasks) { sq->execute(ec); } } diff --git a/project2/sql/sqlTask.h b/project2/sql/sqlTask.h index 94901a9..20f7415 100644 --- a/project2/sql/sqlTask.h +++ b/project2/sql/sqlTask.h @@ -6,6 +6,7 @@ #include "task.h" #include "variables.h" #include "sqlWriter.h" +#include namespace DB { class ModifyCommand; } class RdbmsDataSource; @@ -21,9 +22,9 @@ class SqlTask : public Task { const Variable dataSource; const Variable filter; - typedef ANONORDEREDSTORAGEOF(NoOutputExecute) SubNOEs; - SubNOEs changesNOEs; - SubNOEs noChangesNOEs; + typedef ANONORDEREDSTORAGEOF(Task) SubTasks; + SubTasks changesTasks; + SubTasks noChangesTasks; protected: const DynamicSql::SqlCommand sqlCommand; -- cgit v1.2.3 From d10b8914aeb4f297d6b6deca2408cd81b1adad08 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 30 Sep 2015 23:48:05 +0100 Subject: Use AdHoc plugins for scriptable things and remove legacy plugin support --- project2/basics/aggregates/avg.cpp | 2 +- project2/basics/aggregates/count.cpp | 3 +- project2/basics/aggregates/countDistinct.cpp | 2 +- project2/basics/aggregates/distinct.cpp | 3 +- project2/basics/aggregates/join.cpp | 2 +- project2/basics/aggregates/max.cpp | 3 +- project2/basics/aggregates/min.cpp | 2 +- project2/basics/aggregates/sum.cpp | 2 +- project2/basics/caches/memoryCache.cpp | 4 +- project2/basics/if.cpp | 10 ++- project2/basics/options/showHelp.cpp | 2 +- project2/basics/tasks/iterate.cpp | 4 +- project2/basics/tasks/session/sessionClearTask.cpp | 2 +- project2/basics/tasks/session/sessionSetTask.cpp | 2 +- project2/basics/tasks/structExceptHandling.cpp | 9 +- project2/basics/tests/compoundTest.cpp | 12 +-- project2/basics/tests/equals.cpp | 4 +- project2/basics/tests/greaterthan.cpp | 4 +- project2/basics/tests/greaterthanorequal.cpp | 4 +- project2/basics/tests/isdistinct.cpp | 3 +- project2/basics/tests/isuniq.cpp | 3 +- project2/basics/tests/lessthan.cpp | 4 +- project2/basics/tests/lessthanorequal.cpp | 4 +- project2/basics/tests/notequals.cpp | 4 +- project2/basics/tests/validDateCheck.cpp | 2 +- project2/basics/unittests/dummylib.cpp | 2 +- project2/basics/unittests/testLibraries.cpp | 7 +- project2/basics/views/autotree.cpp | 2 +- project2/basics/views/flatView.cpp | 4 +- project2/basics/views/flatView.h | 1 + project2/basics/views/rowView.cpp | 8 +- project2/basics/views/singleton.cpp | 4 +- project2/basics/views/viewGroup.cpp | 4 +- project2/cgi/cgiAppEngine.cpp | 1 + project2/cgi/cgiContentNegotiate.cpp | 8 +- project2/cgi/cgiOutputOptions.cpp | 15 ++-- project2/cgi/cgiOutputOptions.h | 12 +-- project2/cgi/cgiProgRouter.cpp | 14 ++-- project2/cgi/cgiStageDefaultError.cpp | 2 +- project2/cgi/cgiStageFail.cpp | 3 +- project2/cgi/cgiStagePresent.cpp | 10 +-- project2/cgi/cgiStageRedirect.cpp | 4 +- project2/cgi/p2webCgi.cpp | 1 + project2/cgi/p2webFCgi.cpp | 1 + project2/cgi/testCgi.cpp | 5 +- project2/common/Jamfile.jam | 2 +- project2/common/aggregate.cpp | 4 + project2/common/aggregate.h | 2 + project2/common/check.cpp | 7 +- project2/common/check.h | 1 + project2/common/checkHost.cpp | 2 +- project2/common/commonObjects.cpp | 4 +- project2/common/componentLoader.cpp | 2 + project2/common/componentLoader.h | 12 +-- project2/common/dataSource.cpp | 3 + project2/common/dataSource.h | 1 + project2/common/genLoader.h | 38 --------- project2/common/instanceStore.h | 52 ------------ project2/common/instanceStore.impl.h | 97 ---------------------- project2/common/library.cpp | 5 +- project2/common/optionsSource.cpp | 1 + project2/common/plugable.cpp | 1 - project2/common/plugable.h | 70 +--------------- project2/common/presenter.cpp | 4 +- project2/common/presenter.h | 2 +- project2/common/presenterCache.cpp | 3 + project2/common/presenterCache.h | 1 + project2/common/rowProcessor.cpp | 4 +- project2/common/rowSet.cpp | 3 + project2/common/rowSet.h | 1 + project2/common/rowSetCache.cpp | 3 + project2/common/rowSetCache.h | 1 + project2/common/scriptLoader.cpp | 11 ++- project2/common/scriptLoader.h | 7 +- project2/common/scriptStorage.h | 10 ++- project2/common/scripts.cpp | 7 +- project2/common/scripts.h | 9 +- project2/common/sourceObject.cpp | 4 - project2/common/stream.cpp | 3 + project2/common/stream.h | 1 + project2/common/task.cpp | 3 + project2/common/task.h | 1 + project2/common/taskHost.cpp | 3 +- project2/common/test.cpp | 3 + project2/common/test.h | 1 + project2/common/transform.cpp | 14 ++-- project2/common/transform.h | 9 +- project2/common/variables.cpp | 1 - project2/common/variables/lookup.cpp | 2 +- project2/common/view.cpp | 3 + project2/common/view.h | 1 + project2/common/viewHost.cpp | 2 +- project2/compression/decompressStream.cpp | 5 +- project2/console/consoleAppEngine.cpp | 1 + project2/console/p2consoleMain.cpp | 1 + project2/daemon/p2daemonAppEngine.cpp | 1 + project2/daemon/p2daemonMain.cpp | 1 + project2/files/fileStream.cpp | 6 +- project2/files/fsFilterMaxDepth.cpp | 3 +- project2/files/fsFilterName.cpp | 3 +- project2/files/fsFilterType.cpp | 4 +- project2/files/fsRows.cpp | 11 +-- project2/files/fsRows.h | 19 +---- project2/files/presenterCache.cpp | 5 +- project2/files/writeStream.cpp | 4 +- project2/ice/iceDaemon.cpp | 2 +- project2/ice/iceDataSource.cpp | 4 +- project2/ice/iceRows.h | 3 +- project2/ice/iceTask.h | 5 +- project2/ice/slice2Common.cpp | 6 +- project2/ice/slice2Common.h | 2 +- project2/ice/slice2Rows.cpp | 2 +- project2/ice/slice2Task.cpp | 2 +- project2/ice/unittests/testClient.cpp | 28 +++---- project2/ice/unittests/testClientCompile.cpp | 20 ++--- project2/ice/unittests/testDaemon.cpp | 6 +- project2/json/presenter-p.cpp | 3 +- project2/json/presenter.cpp | 3 +- project2/mail/sendmailTask.cpp | 2 +- project2/processes/processStream.cpp | 3 +- project2/regex/regexRows.cpp | 2 +- project2/regex/regexTest.cpp | 2 +- project2/sql/rdbmsDataSource.cpp | 4 +- project2/sql/sqlBulkLoad.cpp | 5 +- project2/sql/sqlCache.cpp | 4 +- project2/sql/sqlMergeTask.cpp | 6 +- project2/sql/sqlRows.cpp | 2 +- project2/sql/sqlTask.cpp | 6 +- project2/sql/sqlTest.cpp | 2 +- project2/streams/streamNvpRows.cpp | 4 +- project2/streams/streamPresenter.cpp | 5 +- project2/streams/streamRows.cpp | 4 +- project2/streams/viewStream.cpp | 6 +- project2/url/downloadToFile.cpp | 2 +- project2/url/urlStream.cpp | 2 +- project2/ut/testScriptHost.cpp | 2 +- project2/xml/mutators/copy.cpp | 2 +- project2/xml/mutators/copyToAttr.cpp | 3 +- project2/xml/mutators/create.cpp | 3 +- project2/xml/mutators/delete.cpp | 3 +- project2/xml/mutators/rename.cpp | 4 +- project2/xml/rawView.cpp | 4 +- project2/xml/transformHtml.cpp | 29 ++++--- project2/xml/transformText.cpp | 4 +- project2/xml/xmlCache.cpp | 6 +- project2/xml/xmlDocumentCache.cpp | 2 +- project2/xml/xmlDocumentPrefetch.cpp | 3 +- project2/xml/xmlPresenter.cpp | 8 +- project2/xml/xmlPresenter.h | 2 +- project2/xml/xmlRawRows.cpp | 2 +- project2/xml/xmlRows.cpp | 2 +- project2/xml/xmlScriptParser.cpp | 7 +- project2/xml/xpathRows.cpp | 2 +- 153 files changed, 355 insertions(+), 569 deletions(-) delete mode 100644 project2/common/genLoader.h delete mode 100644 project2/common/instanceStore.h delete mode 100644 project2/common/instanceStore.impl.h diff --git a/project2/basics/aggregates/avg.cpp b/project2/basics/aggregates/avg.cpp index 900bc5f..0547120 100644 --- a/project2/basics/aggregates/avg.cpp +++ b/project2/basics/aggregates/avg.cpp @@ -26,5 +26,5 @@ class Average : public ValueAggregate { mutable std::list vals; }; -DECLARE_LOADER("average", Average); +NAMEDFACTORY("average", Average, ValueAggregateFactory); diff --git a/project2/basics/aggregates/count.cpp b/project2/basics/aggregates/count.cpp index be22783..3d47b34 100644 --- a/project2/basics/aggregates/count.cpp +++ b/project2/basics/aggregates/count.cpp @@ -25,6 +25,5 @@ class Count : public ValueAggregate { mutable int c; }; -DECLARE_LOADER("count", Count); - +NAMEDFACTORY("count", Count, ValueAggregateFactory); diff --git a/project2/basics/aggregates/countDistinct.cpp b/project2/basics/aggregates/countDistinct.cpp index 205b932..9acba4c 100644 --- a/project2/basics/aggregates/countDistinct.cpp +++ b/project2/basics/aggregates/countDistinct.cpp @@ -22,5 +22,5 @@ class CountDistinct : public ValueAggregate { mutable std::set result; }; -DECLARE_LOADER("countdistinct", CountDistinct); +NAMEDFACTORY("countdistinct", CountDistinct, ValueAggregateFactory); diff --git a/project2/basics/aggregates/distinct.cpp b/project2/basics/aggregates/distinct.cpp index 33d71b0..c7f5fe0 100644 --- a/project2/basics/aggregates/distinct.cpp +++ b/project2/basics/aggregates/distinct.cpp @@ -24,4 +24,5 @@ class Distinct : public SetAggregate { mutable std::set result; }; -DECLARE_LOADER("distinct", Distinct); +NAMEDFACTORY("distinct", Distinct, SetAggregateFactory); + diff --git a/project2/basics/aggregates/join.cpp b/project2/basics/aggregates/join.cpp index 405c093..695626f 100644 --- a/project2/basics/aggregates/join.cpp +++ b/project2/basics/aggregates/join.cpp @@ -31,5 +31,5 @@ class Join : public ValueAggregate { Variable sep; }; -DECLARE_LOADER("join", Join); +NAMEDFACTORY("join", Join, ValueAggregateFactory); diff --git a/project2/basics/aggregates/max.cpp b/project2/basics/aggregates/max.cpp index 6304647..a193ed4 100644 --- a/project2/basics/aggregates/max.cpp +++ b/project2/basics/aggregates/max.cpp @@ -22,6 +22,5 @@ class Max : public ValueAggregate { mutable VariableType result; }; -DECLARE_LOADER("max", Max); - +NAMEDFACTORY("max", Max, ValueAggregateFactory); diff --git a/project2/basics/aggregates/min.cpp b/project2/basics/aggregates/min.cpp index 75b0b87..f5e442c 100644 --- a/project2/basics/aggregates/min.cpp +++ b/project2/basics/aggregates/min.cpp @@ -28,5 +28,5 @@ class Min : public ValueAggregate { mutable bool first; }; -DECLARE_LOADER("min", Min); +NAMEDFACTORY("min", Min, ValueAggregateFactory); diff --git a/project2/basics/aggregates/sum.cpp b/project2/basics/aggregates/sum.cpp index 68a9cd4..bdbf229 100644 --- a/project2/basics/aggregates/sum.cpp +++ b/project2/basics/aggregates/sum.cpp @@ -23,5 +23,5 @@ class Sum : public ValueAggregate { mutable double sum; }; -DECLARE_LOADER("sum", Sum); +NAMEDFACTORY("sum", Sum, ValueAggregateFactory); diff --git a/project2/basics/caches/memoryCache.cpp b/project2/basics/caches/memoryCache.cpp index 2bec824..5d58a47 100644 --- a/project2/basics/caches/memoryCache.cpp +++ b/project2/basics/caches/memoryCache.cpp @@ -145,7 +145,7 @@ class MemoryCache : public RowSetCache { time_t MemoryCache::CacheLife; MemoryCache::CacheStore MemoryCache::Store; -class CustomMemoryCacheLoader : public ElementLoader::For { +class CustomMemoryCacheLoader : public RowSetCacheFactory::For, public ComponentLoader { public: void onPeriodic() override { typedef MemoryCache::CacheStore::index::type::iterator iter; @@ -156,7 +156,7 @@ class CustomMemoryCacheLoader : public ElementLoader::For { INITOPTIONS; }; -DECLARE_CUSTOM_LOADER("memorycache", CustomMemoryCacheLoader); +NAMEDPLUGIN("memorycache", CustomMemoryCacheLoader, RowSetCacheFactory); DECLARE_OPTIONS(CustomMemoryCacheLoader, "Memory Cache options") ("cache.memory.life", Options::value(&MemoryCache::CacheLife, 3600), diff --git a/project2/basics/if.cpp b/project2/basics/if.cpp index bdd9835..d860b55 100644 --- a/project2/basics/if.cpp +++ b/project2/basics/if.cpp @@ -4,8 +4,10 @@ #include "scriptLoader.h" #include #include +#include -DECLARE_LOADER("if", If); +NAMEDFACTORY("if", If, ViewFactory); +NAMEDFACTORY("if", If, TaskFactory); StaticMessageException(NoTestsToPerform, "No tests to perform"); If::If(ScriptNodePtr e) : @@ -13,9 +15,9 @@ If::If(ScriptNodePtr e) : IHaveSubTasks(e), View(e) { - e->script->loader.addLoadTarget(e, Storer::into(&normal)); - e->script->loader.addLoadTarget(e, Storer::into(&subViews)); - e->script->loader.addLoadTarget(e, Storer::into(&test)); + e->script->loader.addLoadTarget(e, Storer::into(&normal)); + e->script->loader.addLoadTarget(e, Storer::into(&subViews)); + e->script->loader.addLoadTarget(e, Storer::into(&test)); } bool diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index b7f481c..81c9150 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -29,5 +29,5 @@ ShowHelpComponent::Option() } bool ShowHelpComponent::showHelp; -DECLARE_COMPONENT("ShowHelpComponent", ShowHelpComponent); +NAMEDPLUGIN("ShowHelpComponent", ShowHelpComponent, ComponentLoader); diff --git a/project2/basics/tasks/iterate.cpp b/project2/basics/tasks/iterate.cpp index d2a767a..16224f6 100644 --- a/project2/basics/tasks/iterate.cpp +++ b/project2/basics/tasks/iterate.cpp @@ -4,14 +4,14 @@ #include #include "scriptLoader.h" -DECLARE_LOADER("iterate", Iterate); +NAMEDFACTORY("iterate", Iterate, TaskFactory); Iterate::Iterate(ScriptNodePtr p) : SourceObject(p), IHaveSubTasks(p), RowProcessor(p) { - p->script->loader.addLoadTarget(p, Storer::into(&normal)); + p->script->loader.addLoadTarget(p, Storer::into(&normal)); } Iterate::~Iterate() diff --git a/project2/basics/tasks/session/sessionClearTask.cpp b/project2/basics/tasks/session/sessionClearTask.cpp index 8a21791..2b016be 100644 --- a/project2/basics/tasks/session/sessionClearTask.cpp +++ b/project2/basics/tasks/session/sessionClearTask.cpp @@ -4,7 +4,7 @@ #include "session.h" #include "execContext.h" -DECLARE_LOADER("sessionclear", SessionClearTask); +NAMEDFACTORY("sessionclear", SessionClearTask, TaskFactory); SessionClearTask::SessionClearTask(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/tasks/session/sessionSetTask.cpp b/project2/basics/tasks/session/sessionSetTask.cpp index 120dd06..f009e46 100644 --- a/project2/basics/tasks/session/sessionSetTask.cpp +++ b/project2/basics/tasks/session/sessionSetTask.cpp @@ -4,7 +4,7 @@ #include "session.h" #include "execContext.h" -DECLARE_LOADER("sessionset", SessionSetTask); +NAMEDFACTORY("sessionset", SessionSetTask, TaskFactory); SessionSetTask::SessionSetTask(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/tasks/structExceptHandling.cpp b/project2/basics/tasks/structExceptHandling.cpp index b79dae6..4e46466 100644 --- a/project2/basics/tasks/structExceptHandling.cpp +++ b/project2/basics/tasks/structExceptHandling.cpp @@ -3,16 +3,17 @@ #include "scriptLoader.h" #include "scriptStorage.h" #include "scripts.h" +#include -DECLARE_LOADER("handler", StructuredExceptionHandler); +NAMEDFACTORY("handler", StructuredExceptionHandler, TaskFactory); StructuredExceptionHandler::StructuredExceptionHandler(ScriptNodePtr e) : SourceObject(e), IHaveSubTasks(e) { - e->script->loader.addLoadTargetSub(e, "try", true, Storer::into(&normal)); - e->script->loader.addLoadTargetSub(e, "catch", false, Storer::into(&catches)); - e->script->loader.addLoadTargetSub(e, "finally", false, Storer::into(&finallies)); + e->script->loader.addLoadTargetSub(e, "try", true, Storer::into(&normal)); + e->script->loader.addLoadTargetSub(e, "catch", false, Storer::into(&catches)); + e->script->loader.addLoadTargetSub(e, "finally", false, Storer::into(&finallies)); } void diff --git a/project2/basics/tests/compoundTest.cpp b/project2/basics/tests/compoundTest.cpp index 3799d06..88cff62 100644 --- a/project2/basics/tests/compoundTest.cpp +++ b/project2/basics/tests/compoundTest.cpp @@ -10,7 +10,7 @@ CompoundTest::CompoundTest(ScriptNodePtr s) : SourceObject(s), Test(s) { - s->script->loader.addLoadTarget(s, Storer::into(&tests)); + s->script->loader.addLoadTarget(s, Storer::into(&tests)); } class All : public CompoundTest { @@ -26,7 +26,7 @@ class All : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), !boost::bind(&Test::passes, _1, ec)) == tests.end()); } }; -DECLARE_LOADER("all", All); +NAMEDFACTORY("all", All, TestFactory); class Any : public CompoundTest { public: @@ -41,7 +41,7 @@ class Any : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1, ec)) != tests.end()); } }; -DECLARE_LOADER("any", Any); +NAMEDFACTORY("any", Any, TestFactory); class None : public CompoundTest { public: @@ -56,7 +56,7 @@ class None : public CompoundTest { return (std::find_if(tests.begin(), tests.end(), boost::bind(&Test::passes, _1, ec)) == tests.end()); } }; -DECLARE_LOADER("none", None); +NAMEDFACTORY("none", None, TestFactory); class Not : public Test { public: @@ -64,7 +64,7 @@ class Not : public Test { SourceObject(s), Test(s) { - s->script->loader.addLoadTarget(s, Storer::into(&test)); + s->script->loader.addLoadTarget(s, Storer::into(&test)); } bool passes(ExecContext * ec) const { if (!test) { @@ -75,4 +75,4 @@ class Not : public Test { private: TestPtr test; }; -DECLARE_LOADER("not", Not); +NAMEDFACTORY("not", Not, TestFactory); diff --git a/project2/basics/tests/equals.cpp b/project2/basics/tests/equals.cpp index 425d317..3f32053 100644 --- a/project2/basics/tests/equals.cpp +++ b/project2/basics/tests/equals.cpp @@ -16,9 +16,9 @@ class Equals : public Test { bool passes(ExecContext * ec) const { return (a(ec) == b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("equals", Equals); +NAMEDFACTORY("equals", Equals, TestFactory); diff --git a/project2/basics/tests/greaterthan.cpp b/project2/basics/tests/greaterthan.cpp index b43cef1..01e5812 100644 --- a/project2/basics/tests/greaterthan.cpp +++ b/project2/basics/tests/greaterthan.cpp @@ -16,9 +16,9 @@ class GreaterThan : public Test { bool passes(ExecContext * ec) const { return (a(ec) > b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("greaterthan", GreaterThan); +NAMEDFACTORY("greaterthan", GreaterThan, TestFactory); diff --git a/project2/basics/tests/greaterthanorequal.cpp b/project2/basics/tests/greaterthanorequal.cpp index 67328b2..f5f0124 100644 --- a/project2/basics/tests/greaterthanorequal.cpp +++ b/project2/basics/tests/greaterthanorequal.cpp @@ -16,9 +16,9 @@ class GreaterThanOrEqual : public Test { bool passes(ExecContext * ec) const { return (a(ec) >= b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("greaterthanorequal", GreaterThanOrEqual); +NAMEDFACTORY("greaterthanorequal", GreaterThanOrEqual, TestFactory); diff --git a/project2/basics/tests/isdistinct.cpp b/project2/basics/tests/isdistinct.cpp index 47ed647..2c95535 100644 --- a/project2/basics/tests/isdistinct.cpp +++ b/project2/basics/tests/isdistinct.cpp @@ -37,4 +37,5 @@ class IsDistinct : public Test, IHaveParameters { typedef std::set Rows; mutable Rows previous; }; -DECLARE_LOADER("isdistinct", IsDistinct); +NAMEDFACTORY("isdistinct", IsDistinct, TestFactory); + diff --git a/project2/basics/tests/isuniq.cpp b/project2/basics/tests/isuniq.cpp index dc71ac5..295be40 100644 --- a/project2/basics/tests/isuniq.cpp +++ b/project2/basics/tests/isuniq.cpp @@ -45,4 +45,5 @@ class IsUniq : public Test, IHaveParameters { typedef std::vector Vars; mutable Vars previous; }; -DECLARE_LOADER("isuniq", IsUniq); +NAMEDFACTORY("isuniq", IsUniq, TestFactory); + diff --git a/project2/basics/tests/lessthan.cpp b/project2/basics/tests/lessthan.cpp index f040532..3f172ef 100644 --- a/project2/basics/tests/lessthan.cpp +++ b/project2/basics/tests/lessthan.cpp @@ -16,9 +16,9 @@ class LessThan : public Test { bool passes(ExecContext * ec) const { return (a(ec) < b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("lessthan", LessThan); +NAMEDFACTORY("lessthan", LessThan, TestFactory); diff --git a/project2/basics/tests/lessthanorequal.cpp b/project2/basics/tests/lessthanorequal.cpp index 1cb0e9e..8a64e01 100644 --- a/project2/basics/tests/lessthanorequal.cpp +++ b/project2/basics/tests/lessthanorequal.cpp @@ -16,9 +16,9 @@ class LessThanOrEqual : public Test { bool passes(ExecContext * ec) const { return (a(ec) <= b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("lessthanorequal", LessThanOrEqual); +NAMEDFACTORY("lessthanorequal", LessThanOrEqual, TestFactory); diff --git a/project2/basics/tests/notequals.cpp b/project2/basics/tests/notequals.cpp index aeb784e..bbf3186 100644 --- a/project2/basics/tests/notequals.cpp +++ b/project2/basics/tests/notequals.cpp @@ -16,9 +16,9 @@ class NotEquals : public Test { bool passes(ExecContext * ec) const { return (a(ec) != b(ec)); } - + private: Variable a, b; }; -DECLARE_LOADER("notequals", NotEquals); +NAMEDFACTORY("notequals", NotEquals, TestFactory); diff --git a/project2/basics/tests/validDateCheck.cpp b/project2/basics/tests/validDateCheck.cpp index b1ab5a3..231a478 100644 --- a/project2/basics/tests/validDateCheck.cpp +++ b/project2/basics/tests/validDateCheck.cpp @@ -62,5 +62,5 @@ class ValidDateTest : public Test { int warnLev; }; -DECLARE_LOADER("validdatetest", ValidDateTest); +NAMEDFACTORY("validdatetest", ValidDateTest, TestFactory); diff --git a/project2/basics/unittests/dummylib.cpp b/project2/basics/unittests/dummylib.cpp index 2e919a0..a493f3c 100644 --- a/project2/basics/unittests/dummylib.cpp +++ b/project2/basics/unittests/dummylib.cpp @@ -13,5 +13,5 @@ class DummyTask : public Task { } }; -DECLARE_LOADER("DummyTask", DummyTask); +NAMEDFACTORY("DummyTask", DummyTask, TaskFactory); diff --git a/project2/basics/unittests/testLibraries.cpp b/project2/basics/unittests/testLibraries.cpp index 9b05166..7797694 100644 --- a/project2/basics/unittests/testLibraries.cpp +++ b/project2/basics/unittests/testLibraries.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #define XSTR(s) STR(s) @@ -24,18 +25,18 @@ BOOST_AUTO_TEST_CASE( load_missing_library ) BOOST_AUTO_TEST_CASE( load_and_unload_library ) { - BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported); + BOOST_REQUIRE_THROW(TaskFactory::get("DummyTask"), AdHoc::NoSuchPluginException); BOOST_TEST_CHECKPOINT("Configure (load)"); TestOptionsSource::LoadTestOptions({ { "library", (root / "bin" / self.parent_path().parent_path().leaf() / self.parent_path().leaf() / "libdummylib.so").string() } }); BOOST_TEST_CHECKPOINT("Verify"); - BOOST_REQUIRE(ElementLoader::getFor("DummyTask")); + BOOST_REQUIRE(TaskFactory::get("DummyTask")); BOOST_TEST_CHECKPOINT("Configure (empty)"); TestOptionsSource::LoadTestOptions({ }); - BOOST_REQUIRE_THROW(ElementLoader::getFor("DummyTask"), NotSupported); + BOOST_REQUIRE_THROW(TaskFactory::get("DummyTask"), AdHoc::NoSuchPluginException); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/project2/basics/views/autotree.cpp b/project2/basics/views/autotree.cpp index 48cb643..bfeabee 100644 --- a/project2/basics/views/autotree.cpp +++ b/project2/basics/views/autotree.cpp @@ -4,7 +4,7 @@ #include "scriptLoader.h" #include -DECLARE_LOADER("autotree", AutoTree); +NAMEDFACTORY("autotree", AutoTree, ViewFactory); AutoTree::AutoTree(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/views/flatView.cpp b/project2/basics/views/flatView.cpp index ad13105..1ad2c68 100644 --- a/project2/basics/views/flatView.cpp +++ b/project2/basics/views/flatView.cpp @@ -3,8 +3,10 @@ #include "presenter.h" #include "scriptLoader.h" #include +#include -DECLARE_LOADER("flatview", FlatView); +NAMEDFACTORY("flatview", FlatView, FlatViewFactory); +INSTANTIATEFACTORY(FlatView, ScriptNodePtr); FlatView::FlatView(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/basics/views/flatView.h b/project2/basics/views/flatView.h index 5dc24dc..3e7f9d2 100644 --- a/project2/basics/views/flatView.h +++ b/project2/basics/views/flatView.h @@ -23,6 +23,7 @@ class FlatView : public SourceObject, public RowProcessor { typedef std::map Columns; Columns viewColumns; }; +typedef AdHoc::Factory FlatViewFactory; #endif diff --git a/project2/basics/views/rowView.cpp b/project2/basics/views/rowView.cpp index 8ec5417..a798688 100644 --- a/project2/basics/views/rowView.cpp +++ b/project2/basics/views/rowView.cpp @@ -5,7 +5,7 @@ #include #include -DECLARE_LOADER("view", RowView); +NAMEDFACTORY("view", RowView, ViewFactory); RowView::RowView(ScriptNodePtr p) : SourceObject(p), @@ -23,9 +23,9 @@ RowView::RowView(ScriptNodePtr p) : viewColumns->insert(Columns::value_type(node->get_name(), Variable(node))); } } - p->script->loader.addLoadTarget(p, Storer::into(&subViews)); - p->script->loader.addLoadTarget(p, Storer::into(&valueAggregates)); - p->script->loader.addLoadTarget(p, Storer::into(&setAggregates)); + p->script->loader.addLoadTarget(p, Storer::into(&subViews)); + p->script->loader.addLoadTarget(p, Storer::into(&valueAggregates)); + p->script->loader.addLoadTarget(p, Storer::into(&setAggregates)); } RowView::~RowView() diff --git a/project2/basics/views/singleton.cpp b/project2/basics/views/singleton.cpp index 29b32aa..15f2908 100644 --- a/project2/basics/views/singleton.cpp +++ b/project2/basics/views/singleton.cpp @@ -14,7 +14,7 @@ class Singleton : public View { for (ScriptNodePtr node : p->childrenIn("columns")) { viewColumns.insert(Columns::value_type(node->get_name(), Variable(node))); } - p->script->loader.addLoadTarget(p, Storer::into(&subViews)); + p->script->loader.addLoadTarget(p, Storer::into(&subViews)); } void execute(const MultiRowSetPresenter * p, ExecContext * ec) const { @@ -40,5 +40,5 @@ class Singleton : public View { typedef ANONSTORAGEOF(View) SubViews; SubViews subViews; }; -DECLARE_LOADER("singleton", Singleton); +NAMEDFACTORY("singleton", Singleton, ViewFactory); diff --git a/project2/basics/views/viewGroup.cpp b/project2/basics/views/viewGroup.cpp index 0049e9d..8237e86 100644 --- a/project2/basics/views/viewGroup.cpp +++ b/project2/basics/views/viewGroup.cpp @@ -7,7 +7,7 @@ class ViewGroup : public View { SourceObject(s), View(s) { - s->script->loader.addLoadTarget(s, Storer::into(&subViews)); + s->script->loader.addLoadTarget(s, Storer::into(&subViews)); } void execute(const MultiRowSetPresenter * presenter, ExecContext * ec) const @@ -23,4 +23,4 @@ class ViewGroup : public View { SubViews subViews; }; -DECLARE_LOADER("viewgroup", ViewGroup); +NAMEDFACTORY("viewgroup", ViewGroup, ViewFactory); 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 #include #include +#include #include 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 #include -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 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 OutputOptionsPtr; - -class OutputOptionsLoader : public ComponentLoader { - public: - typedef std::string KeyType; - - OutputOptionsPtr create(ScriptNodePtr e) const; - INITOPTIONS; -}; +typedef AdHoc::Factory 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 typedef std::map VarMap; class RoutingTable { public: + class Route; + typedef AdHoc::Factory 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(&routes)); + routeScript->loader.addLoadTarget(routeScript->root(), Storer::into(&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 routes; }; -typedef RoutingTable::Route Route; -DECLARE_LOADER("route", Route); +NAMEDFACTORY("route", RoutingTable::Route, RoutingTable::RouteFactory); class ProgRouter; class ProgRouterFactory : public RouterFactory::For, 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(pres.get()); auto cp = dynamic_cast(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(p); auto cp = dynamic_cast(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(&outputOptions)); - s->loader.addLoadTarget(s->root(), Storer::into(&presenter, Scripted, crc)); - s->loader.addLoadTarget(s->root(), Storer::into(&caches)); + s->loader.addLoadTarget(s->root(), Storer::into(&outputOptions)); + s->loader.addLoadTarget(s->root(), Storer::into(&presenter, Scripted, crc)); + s->loader.addLoadTarget(s->root(), Storer::into(&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 +#include 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 #include +#include 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 +#include #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::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp)); + for (auto opts : AdHoc::PluginManager::getDefault()->getAll()) { + opts->implementation()->consume(n, p, v, cp); + } } const Options::Option * get(const Glib::ustring &) const { return NULL; diff --git a/project2/common/Jamfile.jam b/project2/common/Jamfile.jam index 775d61c..5b6ad69 100644 --- a/project2/common/Jamfile.jam +++ b/project2/common/Jamfile.jam @@ -16,7 +16,7 @@ cpp-pch pch : pch.hpp : lib p2common : pch - [ glob-tree *.cpp : unittests ] + [ glob-tree *.cpp : unittests library.cpp ] : . glibmm diff --git a/project2/common/aggregate.cpp b/project2/common/aggregate.cpp index ee7c871..f00f7dc 100644 --- a/project2/common/aggregate.cpp +++ b/project2/common/aggregate.cpp @@ -1,4 +1,5 @@ #include "aggregate.h" +#include Aggregate::Aggregate(ScriptNodePtr s) : SourceObject(s), @@ -22,3 +23,6 @@ Aggregate::pushValue(ExecContext * ec) const pushValue(value(ec), ec); } +INSTANTIATEFACTORY(ValueAggregate, ScriptNodePtr); +INSTANTIATEFACTORY(SetAggregate, ScriptNodePtr); + diff --git a/project2/common/aggregate.h b/project2/common/aggregate.h index 7f33b6b..a2ad54d 100644 --- a/project2/common/aggregate.h +++ b/project2/common/aggregate.h @@ -24,6 +24,7 @@ class ValueAggregate : public Aggregate { virtual VariableType resultValue() const = 0; }; typedef boost::intrusive_ptr ValueAggregateCPtr; +typedef AdHoc::Factory ValueAggregateFactory; class SetAggregate : public Aggregate { public: @@ -33,5 +34,6 @@ class SetAggregate : public Aggregate { virtual void onResultValues(const UseAgg &) const = 0; }; typedef boost::intrusive_ptr SetAggregateCPtr; +typedef AdHoc::Factory SetAggregateFactory; #endif diff --git a/project2/common/check.cpp b/project2/common/check.cpp index d288e2f..703a3ea 100644 --- a/project2/common/check.cpp +++ b/project2/common/check.cpp @@ -2,8 +2,9 @@ #include "check.h" #include "scriptLoader.h" #include "scriptStorage.h" +#include -DECLARE_LOADER("check", Check); +NAMEDFACTORY("check", Check, CheckFactory); StaticMessageException(NoTestsToPerform, "No tests to perform"); Check::Check(ScriptNodePtr p) : @@ -12,7 +13,7 @@ Check::Check(ScriptNodePtr p) : group(p, "group", "default"), present(p, "present", "") { - p->script->loader.addLoadTarget(p, Storer::into(&test)); + p->script->loader.addLoadTarget(p, Storer::into(&test)); } Check::~Check() @@ -28,3 +29,5 @@ Check::performCheck(ExecContext * ec) const return test->passes(ec); } +INSTANTIATEFACTORY(Check, ScriptNodePtr); + diff --git a/project2/common/check.h b/project2/common/check.h index dc97f8f..d108f7c 100644 --- a/project2/common/check.h +++ b/project2/common/check.h @@ -21,6 +21,7 @@ class Check : public SourceObject { TestPtr test; }; typedef boost::intrusive_ptr CheckCPtr; +typedef AdHoc::Factory CheckFactory; #endif diff --git a/project2/common/checkHost.cpp b/project2/common/checkHost.cpp index a900d7a..eb2bae7 100644 --- a/project2/common/checkHost.cpp +++ b/project2/common/checkHost.cpp @@ -5,7 +5,7 @@ CheckHost::CheckHost(ScriptNodePtr s) : CommonObjects(s) { - s->script->loader.addLoadTarget(s, Storer::into(&checks)); + s->script->loader.addLoadTarget(s, Storer::into(&checks)); } CheckHost::~CheckHost() diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp index 3ffa47f..a2f7d0f 100644 --- a/project2/common/commonObjects.cpp +++ b/project2/common/commonObjects.cpp @@ -19,7 +19,7 @@ CommonObjects::CommonObjects(ScriptNodePtr s) : script(s->script), scriptLoaded(false) { - s->script->loader.addLoadTarget(s, Storer::into(&rowSets)); + s->script->loader.addLoadTarget(s, Storer::into(&rowSets)); } CommonObjects::~CommonObjects() @@ -36,7 +36,7 @@ CommonObjects::DataSources::const_iterator CommonObjects::loadDataSource(const std::string & name) const { ScriptReaderPtr dbs = ScriptReader::resolveScript(datasourceRoot, name, true); - dbs->loader.addLoadTarget(dbs->root(), Storer::into(&datasources)); + dbs->loader.addLoadTarget(dbs->root(), Storer::into(&datasources)); dbs->load(NULL, false); return AdHoc::safeMapFind(datasources, name); } diff --git a/project2/common/componentLoader.cpp b/project2/common/componentLoader.cpp index 56eb833..5506ed2 100644 --- a/project2/common/componentLoader.cpp +++ b/project2/common/componentLoader.cpp @@ -1,4 +1,5 @@ #include "componentLoader.h" +#include ComponentLoader::~ComponentLoader() { @@ -34,4 +35,5 @@ ComponentLoader::onConfigLoad() { } +INSTANTIATEPLUGINOF(ComponentLoader); diff --git a/project2/common/componentLoader.h b/project2/common/componentLoader.h index 45664e3..d3cff99 100644 --- a/project2/common/componentLoader.h +++ b/project2/common/componentLoader.h @@ -1,10 +1,10 @@ #ifndef COMPONENTLOADER_H #define COMPONENTLOADER_H -#include "plugable.h" +#include /// Helper for loading and maintaining Project2 components -class ComponentLoader { +class ComponentLoader : public virtual AdHoc::AbstractPluginImplementation { public: virtual ~ComponentLoader() = 0; virtual void onBegin(); // App engine start up (before settings are processed) @@ -15,13 +15,7 @@ class ComponentLoader { virtual void onConfigLoad(); // When the environment reloads the configuration virtual bool cacheable() const { return true; } // The component can be cached for next run }; - -typedef PluginsSameBase Components; -#define DECLARE_COMPONENT(Id, Inst) \ - static void init_optionsSource_##Type() __attribute__ ((constructor(200))); \ - static void init_optionsSource_##Type() { Components::Add(Id, new Inst()); } \ - static void kill_optionsSource_##Type() __attribute__ ((destructor(200))); \ - static void kill_optionsSource_##Type() { Components::Remove(Id); } +typedef AdHoc::PluginOf LifeCycleComponentPlugin; #endif diff --git a/project2/common/dataSource.cpp b/project2/common/dataSource.cpp index b5760c5..5b23c9a 100644 --- a/project2/common/dataSource.cpp +++ b/project2/common/dataSource.cpp @@ -1,9 +1,12 @@ #include #include "dataSource.h" #include "scripts.h" +#include DataSource::DataSource(ScriptNodePtr p) : SourceObject(p) { } +INSTANTIATEFACTORY(DataSource, ScriptNodePtr); + diff --git a/project2/common/dataSource.h b/project2/common/dataSource.h index bd7170f..c60cceb 100644 --- a/project2/common/dataSource.h +++ b/project2/common/dataSource.h @@ -17,6 +17,7 @@ class DataSource : public SourceObject { virtual void commit() { }; virtual void rollback() { }; }; +typedef AdHoc::Factory DataSourceFactory; #endif diff --git a/project2/common/genLoader.h b/project2/common/genLoader.h deleted file mode 100644 index 2e4300b..0000000 --- a/project2/common/genLoader.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GENLOADER_H -#define GENLOADER_H - -#include "componentLoader.h" -#include "plugable.h" - -template -class GenLoader : public ComponentLoader { - public: - typedef Key KeyType; - typedef GenLoader Self; - - template - class For : public BaseLoader { - public: - inline Impl * create(const Params & ... p) const - { - return new T(p...); - } - }; - - virtual Impl * create(const Params & ...) const = 0; - - template - inline static Impl * createNew(const KeyType & n, const Params & ... p) - { - return InstanceMap::template Get(n)->create(p...); - } - - template - inline static boost::shared_ptr getFor(const KeyType & n) - { - return InstanceMap::template Get(n); - } -}; - -#endif - diff --git a/project2/common/instanceStore.h b/project2/common/instanceStore.h deleted file mode 100644 index 4fd4519..0000000 --- a/project2/common/instanceStore.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef INSTANCESTORE_H -#define INSTANCESTORE_H - -#include -#include -#include -#include - -/// A static collection of any type, specifically with automatically cleaned up storage of a function static variable -// which makes it safe to use in constructor functions. -template -class InstanceStore { - public: - static const StoreType & GetAll(); - static void Add(const typename StoreType::value_type & p); - - protected: - static void prune(); - static StoreType * & getInstances(); -}; - -/// Keyed collection of instances -template -class InstanceMap : public InstanceStore>> { - public: - typedef std::map> Store; - typedef InstanceStore>> IStore; - typedef typename Store::value_type Value; - - static void Add(const KeyType & k, Type * p); - static void Add(const KeyType & k, const boost::shared_ptr & p); - static void Remove(const KeyType &); - - template static boost::shared_ptr Get(const KeyType & n) - { - return AdHoc::safeMapLookup(InstanceStore::GetAll(), n); - } - - static void OnEach(const boost::function & func); -}; - -/// Anonymous collection of instances -template -class InstanceSet : public InstanceStore>> { - public: - typedef InstanceStore>> IStore; - static void OnAll(const boost::function & func); - static void Remove(const boost::shared_ptr &); -}; - -#endif - diff --git a/project2/common/instanceStore.impl.h b/project2/common/instanceStore.impl.h deleted file mode 100644 index 2a2f497..0000000 --- a/project2/common/instanceStore.impl.h +++ /dev/null @@ -1,97 +0,0 @@ -#include "instanceStore.h" -#include - -template -const StoreType & -InstanceStore::GetAll() -{ - return *getInstances(); -} - -template -void -InstanceStore::Add(const typename StoreType::value_type & p) -{ - getInstances()->insert(p); -} - -template -void -InstanceStore::prune() -{ - auto & ps = getInstances(); - if (ps->empty()) { - delete ps; - ps = NULL; - } -} - -template -StoreType * & -InstanceStore::getInstances() -{ - static StoreType * instances = NULL; - if (!instances) { - instances = new StoreType(); - } - return instances; -} - -template -void -InstanceMap::Add(const KeyType & k, Type * p) -{ - BOOST_ASSERT(IStore::getInstances()->find(k) == IStore::getInstances()->end()); - IStore::Add(Value(k, boost::shared_ptr(p))); -} - -template -void -InstanceMap::Add(const KeyType & k, const boost::shared_ptr & p) -{ - BOOST_ASSERT(IStore::getInstances()->find(k) == IStore::getInstances()->end()); - IStore::Add(Value(k, p)); -} - -template -void -InstanceMap::Remove(const KeyType & k) -{ - IStore::getInstances()->erase(k); - IStore::prune(); -} - -template -void -InstanceMap::OnEach(const boost::function & func) -{ - for (const auto & l : IStore::GetAll()) { - func(l); - } - IStore::prune(); -} - -template -void -InstanceSet::OnAll(const boost::function & func) -{ - for (const auto & l : IStore::GetAll()) { - func(l.get()); - } - IStore::prune(); -} - -template -void -InstanceSet::Remove(const boost::shared_ptr & p) -{ - IStore::getInstances()->erase(p); - IStore::prune(); -} - -#define INSTANTIATESTORE(K, T) \ -template class InstanceStore>>; \ -template class InstanceMap; \ -template class InstanceStore>>; \ -template class InstanceSet - diff --git a/project2/common/library.cpp b/project2/common/library.cpp index 11dadb3..ce753bd 100644 --- a/project2/common/library.cpp +++ b/project2/common/library.cpp @@ -23,7 +23,7 @@ Library::~Library() } STORAGEOF(Library) libraries; -class LibraryLoader : public ElementLoader::For { +class LibraryLoader : public ScriptNodeFactory::For, public ComponentLoader { public: void onIteration() override { @@ -31,6 +31,5 @@ class LibraryLoader : public ElementLoader::For { } }; -DECLARE_CUSTOM_LOADER("library", LibraryLoader); - +NAMEDPLUGIN("library", LibraryLoader, ScriptNodeFactory); diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 1739ed5..f10ff4f 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -1,6 +1,7 @@ #include "optionsSource.h" #include "logger.h" #include +#include class DefaultConfigConsumer : public ConfigConsumer { public: diff --git a/project2/common/plugable.cpp b/project2/common/plugable.cpp index 15d8cda..deb7910 100644 --- a/project2/common/plugable.cpp +++ b/project2/common/plugable.cpp @@ -5,7 +5,6 @@ void Plugable::onAllComponents(const boost::function & func) { - InstanceSet::OnAll(func); for(auto p : AdHoc::PluginManager::getDefault()->getAll()) { if (auto c = dynamic_cast(p->implementation())) { func(c); diff --git a/project2/common/plugable.h b/project2/common/plugable.h index eaccd49..8e3889f 100644 --- a/project2/common/plugable.h +++ b/project2/common/plugable.h @@ -2,81 +2,13 @@ #define PLUGABLE_H #include -#include -#include "instanceStore.h" -#include "exceptions.h" class ComponentLoader; -class Plugable : public InstanceSet { +class Plugable { public: static void onAllComponents(const boost::function & func); }; -/// All loaders, keyed by string, enum, int, etc -template -class PluginsDiffBase { - public: - typedef Key KeyType; - typedef InstanceMap Map; - typedef InstanceSet Set; - typedef InstanceSet AnonSet; - - static void Add(const KeyType & k, Base * i) - { - auto p = boost::shared_ptr(i); - Map::Add(k, p); - Set::Add(p); - AnonSet::Add(p); - } - - static void Remove(const KeyType & k) - { - auto p = Map::GetAll().find(k)->second; - Set::Remove(p); - AnonSet::Remove(p); - Map::Remove(k); - } -}; - -template -class PluginsSameBase { - public: - typedef Key KeyType; - typedef InstanceMap Map; - typedef InstanceSet Set; - - static void Add(const KeyType & k, Base * i) - { - auto p = boost::shared_ptr(i); - Map::Add(k, p); - Set::Add(p); - } - - static void Remove(const KeyType & k) - { - Set::Remove(Map::GetAll().find(k)->second); - Map::Remove(k); - } -}; - -#define TOKENPASTE(x, y) x ## y -#define TOKENPASTE2(x, y) TOKENPASTE(x, y) -#define DECLARE_CUSTOM_COMPONENT_LOADER(Key, Impl, Loader, BaseLoader) \ -namespace TOKENPASTE2(Impl, __LINE__) { \ - static void init_loader_##Impl() __attribute__ ((constructor(201))); \ - static void init_loader_##Impl() { PluginsDiffBase::Add(Key, new Loader()); } \ - static void kill_loader_##Impl() __attribute__ ((destructor(201))); \ - static void kill_loader_##Impl() { PluginsDiffBase::Remove(Key); } \ -} -#define DECLARE_CUSTOM_LOADER(Key, T) \ - DECLARE_CUSTOM_COMPONENT_LOADER(Key, T, T, ElementLoader) -#define DECLARE_COMPONENT_LOADER(Key, Type, BaseLoader) \ - DECLARE_CUSTOM_COMPONENT_LOADER(Key, Type, BaseLoader::For, BaseLoader) -#define DECLARE_LOADER(Key, Loader) \ - DECLARE_COMPONENT_LOADER(Key, Loader, ElementLoader) -#define DECLARE_GENERIC_LOADER(Key, B, T) \ - DECLARE_CUSTOM_COMPONENT_LOADER(Key, T, B::For, B); - #endif diff --git a/project2/common/presenter.cpp b/project2/common/presenter.cpp index 012020d..a28f00c 100644 --- a/project2/common/presenter.cpp +++ b/project2/common/presenter.cpp @@ -1,7 +1,7 @@ #include #include "presenter.h" #include "dataSource.h" -#include "instanceStore.impl.h" +#include NameValuePairPresenter::NameValuePairPresenter() { @@ -120,5 +120,5 @@ MultiRowSetPresenter::finalizeContent() const { } -INSTANTIATESTORE(std::string, PresenterLoader); +INSTANTIATEFACTORY(MultiRowSetPresenter, ScriptNodePtr, ObjectSource, ExecContext *); diff --git a/project2/common/presenter.h b/project2/common/presenter.h index 107e878..037e7bf 100644 --- a/project2/common/presenter.h +++ b/project2/common/presenter.h @@ -77,7 +77,7 @@ typedef boost::intrusive_ptr RowSetPresenterPtr; typedef boost::intrusive_ptr MultiRowSetPresenterPtr; typedef boost::intrusive_ptr NameValuePairPresenterPtr; -typedef GenLoader PresenterLoader; +typedef AdHoc::Factory PresenterFactory; #endif diff --git a/project2/common/presenterCache.cpp b/project2/common/presenterCache.cpp index 78122d0..429f93e 100644 --- a/project2/common/presenterCache.cpp +++ b/project2/common/presenterCache.cpp @@ -1,4 +1,5 @@ #include "presenterCache.h" +#include PresenterCache::PresenterCache(ScriptNodePtr s) : SourceObject(s), @@ -12,6 +13,8 @@ PresenterCache::flushCache() { } +INSTANTIATEFACTORY(PresenterCache, ScriptNodePtr); + class WriteToCache : public TransformImpl { public: void transform(const WritableContent * wc, PresenterCache * pc, ExecContext * ec) const { diff --git a/project2/common/presenterCache.h b/project2/common/presenterCache.h index b0adab8..c90c077 100644 --- a/project2/common/presenterCache.h +++ b/project2/common/presenterCache.h @@ -15,5 +15,6 @@ class PresenterCache : public SourceObject, public virtual TransformSource, publ const std::string encoding; }; typedef boost::intrusive_ptr PresenterCachePtr; +typedef AdHoc::Factory PresenterCacheFactory; #endif diff --git a/project2/common/rowProcessor.cpp b/project2/common/rowProcessor.cpp index acfaec5..a83fe00 100644 --- a/project2/common/rowProcessor.cpp +++ b/project2/common/rowProcessor.cpp @@ -13,8 +13,8 @@ RowProcessor::RowProcessor(ScriptNodePtr p) : CROE(p->value("cacheRowsOnError", false, NULL)), IRSE(p->value("ignoreRowSourceError", false, NULL)) { - p->script->loader.addLoadTarget(p, Storer::into(&caches)); - p->script->loader.addLoadTarget(p, Storer::into(&tests)); + p->script->loader.addLoadTarget(p, Storer::into(&caches)); + p->script->loader.addLoadTarget(p, Storer::into(&tests)); } void diff --git a/project2/common/rowSet.cpp b/project2/common/rowSet.cpp index a050bab..1299818 100644 --- a/project2/common/rowSet.cpp +++ b/project2/common/rowSet.cpp @@ -6,6 +6,7 @@ #include "variables.h" #include #include "execContext.h" +#include RowSet::RowSet(ScriptNodePtr p) : SourceObject(p) @@ -87,3 +88,5 @@ RowState::foreachAttr(const AttrAction &) const // rowNum is magic, so it doesn't count :) } +INSTANTIATEFACTORY(RowSet, ScriptNodePtr); + diff --git a/project2/common/rowSet.h b/project2/common/rowSet.h index f36f79f..5cb991e 100644 --- a/project2/common/rowSet.h +++ b/project2/common/rowSet.h @@ -55,6 +55,7 @@ class RowState { private: unsigned int rowNum; }; +typedef AdHoc::Factory RowSetFactory; #endif diff --git a/project2/common/rowSetCache.cpp b/project2/common/rowSetCache.cpp index 95a949b..e6d2884 100644 --- a/project2/common/rowSetCache.cpp +++ b/project2/common/rowSetCache.cpp @@ -4,6 +4,7 @@ #include "rowProcessor.h" #include "logger.h" #include +#include RowSetCache::RowSetCache(ScriptNodePtr p) : IHaveParameters(p), @@ -47,3 +48,5 @@ RowSetCache::applyKeys(ExecContext * ec, const KeyApplier & f, const IHaveParame } } +INSTANTIATEFACTORY(RowSetCache, ScriptNodePtr); + diff --git a/project2/common/rowSetCache.h b/project2/common/rowSetCache.h index 055b07e..b365c72 100644 --- a/project2/common/rowSetCache.h +++ b/project2/common/rowSetCache.h @@ -26,6 +26,7 @@ class RowSetCache : public IHaveParameters, public SourceObject { const bool inherit; }; typedef boost::intrusive_ptr RowSetCachePtr; +typedef AdHoc::Factory RowSetCacheFactory; #endif diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index 523a316..17ebd19 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -5,10 +5,10 @@ #include #include #include -#include "instanceStore.impl.h" #include "appInstance.h" +#include -typedef std::map > ElementLoaderMap; +typedef std::map > ElementLoaderMap; typedef std::set > ComponentLoaderSet; LoaderBase::LoaderBase() : @@ -68,7 +68,7 @@ LoaderBase::collectAll(ScriptNodePtr node, LoadedObjects & loadedObjects, bool c node->obj = s->create(node); break; } - catch (const NotSupported &) { + catch (const AdHoc::NoSuchPluginException &) { } } if (!node->obj) { @@ -99,9 +99,8 @@ LoaderBase::collectAll(ScriptNodePtr node, LoadedObjects & loadedObjects, bool c } void -LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePtr node) +LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly) { - addLoadTarget(node, Storer::into(&libraries)); Targets::iterator i; LoadedObjects loadedObjects; while ((i = targets.begin()) != targets.end()) { @@ -115,5 +114,5 @@ LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePt } } -INSTANTIATESTORE(std::string, ScriptReaderLoader); +INSTANTIATEFACTORY(ScriptReader, const std::string &, const std::string &); diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index ca888cf..032d6c7 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -6,7 +6,7 @@ #include #include "intrusivePtrBase.h" #include "sourceObject.h" -#include "genLoader.h" +#include #include "scripts_fwd.h" #include #include @@ -29,7 +29,7 @@ class LoaderBase { LoaderBase(); virtual ~LoaderBase(); - void collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePtr script); + void collectAll(const CommonObjects * co, bool childrenOnly); void addLoadTarget(ScriptNodePtr src, boost::intrusive_ptr target); void addLoadTargetSub(ScriptNodePtr src, const Glib::ustring & name, bool required, boost::intrusive_ptr target); void discardLoadTargets(); @@ -45,8 +45,5 @@ class LoaderBase { const Glib::ustring ns; }; -/// Helper for loading and maintaining Project2 script components -typedef GenLoader ElementLoader; - #endif diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h index cb947aa..9947633 100644 --- a/project2/common/scriptStorage.h +++ b/project2/common/scriptStorage.h @@ -44,16 +44,20 @@ class Storer : public virtual IntrusivePtrBase { template class StorerBase : public Storer { public: - typedef boost::function2, L *, ScriptNodePtr> Creator; + typedef boost::function2, const L *, ScriptNodePtr> Creator; StorerBase(const Creator & c) : creator(c) { } boost::intrusive_ptr create(ScriptNodePtr p) const { - return creator(InstanceMap::template Get(p->get_name()).get(), p); + return creator(L::get(p->get_name()), p); } bool cacheable(ScriptNodePtr p) const { - return InstanceMap::template Get(p->get_name())->cacheable(); + auto f = AdHoc::PluginManager::getDefault()->get(p->get_name()); + if (auto c = dynamic_cast(f->implementation())) { + return c->cacheable(); + } + return true; } bool save(boost::intrusive_ptr o, ScriptNodePtr name) { boost::intrusive_ptr O = boost::dynamic_pointer_cast(o); diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp index ff80870..0410817 100644 --- a/project2/common/scripts.cpp +++ b/project2/common/scripts.cpp @@ -3,6 +3,7 @@ #include "variables/fixed.h" #include #include "appInstance.h" +#include DECLARE_OPTIONS(Scripts, "Project2 Script options") ("common.namespace", Options::value(&scriptNamespace, "http://project2.randomdan.homeip.net"), @@ -61,7 +62,7 @@ ScriptNode::value(const Glib::ustring & n, ExecContext * ec) const void ScriptReader::load(const CommonObjects * co, bool childrenOnly) const { - loader.collectAll(co, childrenOnly, root()); + loader.collectAll(co, childrenOnly); } ScriptReaderPtr @@ -75,8 +76,8 @@ ScriptReader::resolveScript(const std::string & group, const std::string & name, return rs; } else { - for (const auto & rl : InstanceSet::GetAll()) { - rs = rl->resolveScript(group, e.string()); + for (const auto & rl : AdHoc::PluginManager::getDefault()->getAll()) { + rs = rl->implementation()->create(group, e.string()); if (rs) { AppInstance::current().cacheScript(sk, rs); return rs; diff --git a/project2/common/scripts.h b/project2/common/scripts.h index 8bf450d..e3fab9c 100644 --- a/project2/common/scripts.h +++ b/project2/common/scripts.h @@ -11,6 +11,7 @@ #include "exceptions.h" #include "variableType.h" #include "options.h" +#include "componentLoader.h" #include SimpleMessageException(ValueNotFound); @@ -80,13 +81,7 @@ class ScriptReader : public virtual IntrusivePtrBase { mutable std::map namedComponents; }; -/// Base class to implement script reader modules -class ScriptReaderLoader : public ComponentLoader { - public: - typedef std::string KeyType; - - virtual ScriptReaderPtr resolveScript(const std::string & group, const std::string & name) const = 0; -}; +typedef AdHoc::Factory ScriptReaderFactory; #endif diff --git a/project2/common/sourceObject.cpp b/project2/common/sourceObject.cpp index 45c7d19..09fe94e 100644 --- a/project2/common/sourceObject.cpp +++ b/project2/common/sourceObject.cpp @@ -1,5 +1,4 @@ #include -#include "instanceStore.impl.h" #include "sourceObject.h" #include "exceptions.h" #include "safeMapFind.h" @@ -48,6 +47,3 @@ SourceObject::findComponent(const std::string & name) const return AdHoc::safeMapLookup(script->namedComponents, name); } -INSTANTIATESTORE(std::string, ComponentLoader); -INSTANTIATESTORE(std::string, ElementLoader); - diff --git a/project2/common/stream.cpp b/project2/common/stream.cpp index 0db9225..d97d1ab 100644 --- a/project2/common/stream.cpp +++ b/project2/common/stream.cpp @@ -1,5 +1,6 @@ #include "stream.h" #include +#include Glib::ustring Stream::getContentType(ExecContext *) const @@ -20,3 +21,5 @@ Stream::writeTo(std::ostream & os, const std::string &, ExecContext * ec) const runStream(boost::bind(&Stream::write, &os, _1, _2), ec); } +INSTANTIATEFACTORY(Stream, ScriptNodePtr); + diff --git a/project2/common/stream.h b/project2/common/stream.h index bf0dc41..4fe47f0 100644 --- a/project2/common/stream.h +++ b/project2/common/stream.h @@ -21,6 +21,7 @@ class Stream : public SourceObject, public WritableContent { static size_t write(std::ostream * os, const char * data, size_t len); }; typedef boost::intrusive_ptr StreamPtr; +typedef AdHoc::Factory StreamFactory; #endif diff --git a/project2/common/task.cpp b/project2/common/task.cpp index bee3767..f77d518 100644 --- a/project2/common/task.cpp +++ b/project2/common/task.cpp @@ -1,5 +1,6 @@ #include #include "task.h" +#include Task::Task(ScriptNodePtr p) : SourceObject(p) @@ -15,3 +16,5 @@ Task::~Task() { } +INSTANTIATEFACTORY(Task, ScriptNodePtr); + diff --git a/project2/common/task.h b/project2/common/task.h index d29b533..9a9548f 100644 --- a/project2/common/task.h +++ b/project2/common/task.h @@ -12,6 +12,7 @@ class Task : public virtual SourceObject { virtual ~Task(); virtual void execute(ExecContext *) const = 0; }; +typedef AdHoc::Factory TaskFactory; #endif diff --git a/project2/common/taskHost.cpp b/project2/common/taskHost.cpp index 23b75fe..136f481 100644 --- a/project2/common/taskHost.cpp +++ b/project2/common/taskHost.cpp @@ -1,5 +1,6 @@ #include #include "taskHost.h" +#include "task.h" #include "dataSource.h" #include #include "scriptLoader.h" @@ -11,7 +12,7 @@ TaskHost::TaskHost(ScriptNodePtr s) : CheckHost(s), IHaveSubTasks(s) { - s->script->loader.addLoadTarget(s, Storer::into(&tasks)); + s->script->loader.addLoadTarget(s, Storer::into(&tasks)); } TaskHost::~TaskHost() diff --git a/project2/common/test.cpp b/project2/common/test.cpp index 427848a..db7514d 100644 --- a/project2/common/test.cpp +++ b/project2/common/test.cpp @@ -1,4 +1,5 @@ #include "test.h" +#include Test::Test(ScriptNodePtr s) : SourceObject(s) @@ -10,3 +11,5 @@ Test::reset() const { } +INSTANTIATEFACTORY(Test, ScriptNodePtr); + diff --git a/project2/common/test.h b/project2/common/test.h index 7cf563c..b821844 100644 --- a/project2/common/test.h +++ b/project2/common/test.h @@ -13,5 +13,6 @@ class Test : public virtual SourceObject { virtual void reset() const; }; typedef boost::intrusive_ptr TestPtr; +typedef AdHoc::Factory TestFactory; #endif diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp index 37173c7..6b44da0 100644 --- a/project2/common/transform.cpp +++ b/project2/common/transform.cpp @@ -3,7 +3,7 @@ #include "logger.h" #include "ostreamWrapper.h" #include "scriptStorage.h" -#include "instanceStore.impl.h" +#include class TransformTargetStorer : public Storer { public: @@ -13,7 +13,7 @@ class TransformTargetStorer : public Storer { } boost::intrusive_ptr create(ScriptNodePtr p) const { - return InstanceMap::Get(p->get_name())->create(p, Scripted); + return TransformTargetFactory::createNew(p->get_name(), p, Scripted); } bool save(boost::intrusive_ptr o, ScriptNodePtr s) { @@ -42,12 +42,12 @@ TransformChainLink::~TransformChainLink() { } -typedef std::map > TransformLoaderMap; +typedef std::map > TransformFactoryMap; void TransformSource::addTarget(TransformChainLinkPtr tcl, ExecContext * ec, ScriptNodePtr e) { - for (const auto & tl : InstanceSet::GetAll()) { - TransformPtr t = tl->create(); + for (const auto & tl : AdHoc::PluginManager::getDefault()->getAll()) { + TransformPtr t = tl->implementation()->create(); if (t->canTransform(this, tcl.get())) { if (e) { t->configure(e, ec); @@ -106,6 +106,6 @@ class TransformStaticContentToStdStream : public TransformImpl +#include #include "range.h" class ExecContext; @@ -49,11 +50,11 @@ class Transform : public virtual IntrusivePtrBase { virtual void configure(ScriptNodePtr, ExecContext *) { }; }; -typedef GenLoader TransformLoader; -#define DECLARE_TRANSFORM(T) DECLARE_COMPONENT_LOADER(#T, T, TransformLoader) +typedef AdHoc::Factory TransformFactory; +#define DECLARE_TRANSFORM(T) NAMEDFACTORY(#T, T, TransformFactory) -typedef GenLoader TransformTargetLoader; -#define DECLARE_TRANSFORMTARGET(N, T) DECLARE_COMPONENT_LOADER(N, T, TransformTargetLoader) +typedef AdHoc::Factory TransformTargetFactory; +#define DECLARE_TRANSFORMTARGET(N, T) NAMEDFACTORY(N, T, TransformTargetFactory) template class TransformImpl : public Transform { diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp index 71cc36b..526f90c 100644 --- a/project2/common/variables.cpp +++ b/project2/common/variables.cpp @@ -12,7 +12,6 @@ #include #include #include -#include "instanceStore.impl.h" #include "execContext.h" #include diff --git a/project2/common/variables/lookup.cpp b/project2/common/variables/lookup.cpp index eac3317..6c6ca55 100644 --- a/project2/common/variables/lookup.cpp +++ b/project2/common/variables/lookup.cpp @@ -34,7 +34,7 @@ class VariableLookup : public VariableImplDyn, public RowProcessor { RowProcessor(e), name(e->value("name", NULL).as()) { - e->script->loader.addLoadTarget(e, Storer::into(&rowSets)); + e->script->loader.addLoadTarget(e, Storer::into(&rowSets)); } VariableType value(ExecContext * ec) const { diff --git a/project2/common/view.cpp b/project2/common/view.cpp index 30a6491..5ab8f0a 100644 --- a/project2/common/view.cpp +++ b/project2/common/view.cpp @@ -1,5 +1,6 @@ #include #include "view.h" +#include View::View(ScriptNodePtr p) : SourceObject(p) @@ -10,3 +11,5 @@ View::~View() { } +INSTANTIATEFACTORY(View, ScriptNodePtr); + diff --git a/project2/common/view.h b/project2/common/view.h index 52a4130..fa0f37b 100644 --- a/project2/common/view.h +++ b/project2/common/view.h @@ -16,6 +16,7 @@ class View : public virtual SourceObject { virtual void execute(const MultiRowSetPresenter *, ExecContext *) const = 0; }; +typedef AdHoc::Factory ViewFactory; #endif diff --git a/project2/common/viewHost.cpp b/project2/common/viewHost.cpp index ce99506..a276e99 100644 --- a/project2/common/viewHost.cpp +++ b/project2/common/viewHost.cpp @@ -8,7 +8,7 @@ ViewHost::ViewHost(ScriptNodePtr s) : CommonObjects(s), CheckHost(s) { - s->script->loader.addLoadTarget(s, Storer::into(&views)); + s->script->loader.addLoadTarget(s, Storer::into(&views)); } ViewHost::~ViewHost() diff --git a/project2/compression/decompressStream.cpp b/project2/compression/decompressStream.cpp index b986a0a..68f8869 100644 --- a/project2/compression/decompressStream.cpp +++ b/project2/compression/decompressStream.cpp @@ -4,7 +4,6 @@ #include "scripts.h" #include "variables.h" #include "scriptStorage.h" -#include "instanceStore.impl.h" class DecompressStream : public Stream { public: @@ -12,7 +11,7 @@ class DecompressStream : public Stream { Stream(p), method(p, "method") { - p->script->loader.addLoadTarget(p, Storer::into(&stream)); + p->script->loader.addLoadTarget(p, Storer::into(&stream)); } void runStream(const Sink & sink, ExecContext * ec) const @@ -28,5 +27,5 @@ class DecompressStream : public Stream { const Variable method; }; -DECLARE_LOADER("decompstream", DecompressStream); +NAMEDFACTORY("decompstream", DecompressStream, StreamFactory); diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 54c9b2f..41bf14c 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -12,6 +12,7 @@ #include #include #include +#include StaticMessageException(InvalidScriptName, "Script name should be group/name"); SimpleMessageException(UnknownPlatformAlias); diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index 87a3293..03771f0 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -2,6 +2,7 @@ #include #include "claOptions.h" #include "consoleAppEngine.h" +#include int main(int argc, char ** argv) diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp index 6ed0472..6d07201 100644 --- a/project2/daemon/p2daemonAppEngine.cpp +++ b/project2/daemon/p2daemonAppEngine.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "pidfile.h" #include "tempPrivs.h" diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp index 0da41f3..e65f941 100644 --- a/project2/daemon/p2daemonMain.cpp +++ b/project2/daemon/p2daemonMain.cpp @@ -5,6 +5,7 @@ #include #include #include +#include SimpleMessageException(UnsupportedArguments); diff --git a/project2/files/fileStream.cpp b/project2/files/fileStream.cpp index 62bfa5b..ddfa30b 100644 --- a/project2/files/fileStream.cpp +++ b/project2/files/fileStream.cpp @@ -7,7 +7,6 @@ #include "exceptions.h" #include - class FileStream : public Stream { public: FileStream(ScriptNodePtr p) : @@ -22,7 +21,7 @@ class FileStream : public Stream { throw NotSupported(__PRETTY_FUNCTION__); } - void runStream(const Sink & sink, ExecContext * ec) const + void runStream(const Sink & sink, ExecContext * ec) const override { FILE * file = fopen(path(ec), "r"); if (!file) { @@ -46,4 +45,5 @@ class FileStream : public Stream { const Variable contentType; const Variable path; }; -DECLARE_LOADER("filestream", FileStream); +NAMEDFACTORY("filestream", FileStream, StreamFactory); + diff --git a/project2/files/fsFilterMaxDepth.cpp b/project2/files/fsFilterMaxDepth.cpp index 089737a..d55b0d1 100644 --- a/project2/files/fsFilterMaxDepth.cpp +++ b/project2/files/fsFilterMaxDepth.cpp @@ -19,4 +19,5 @@ class FsRowSpecMaxDepth : public FsRows::SpecBase { Variable maxDepth; }; -DECLARE_COMPONENT_LOADER("maxdepth", FsRowSpecMaxDepth, FsRows::SpecBaseLoader); +NAMEDFACTORY("maxdepth", FsRowSpecMaxDepth, FsRows::SpecBaseFactory); +NAMEDFACTORY("maxdepth", FsRowSpecMaxDepth, FsRows::SpecBaseStringFactory); diff --git a/project2/files/fsFilterName.cpp b/project2/files/fsFilterName.cpp index 92279c2..62ca04b 100644 --- a/project2/files/fsFilterName.cpp +++ b/project2/files/fsFilterName.cpp @@ -54,4 +54,5 @@ class FsRowSpecName : public FsRows::SpecBase { const Variable pattern; }; -DECLARE_COMPONENT_LOADER("name", FsRowSpecName, FsRows::SpecBaseLoader); +NAMEDFACTORY("name", FsRowSpecName, FsRows::SpecBaseFactory); +NAMEDFACTORY("name", FsRowSpecName, FsRows::SpecBaseStringFactory); diff --git a/project2/files/fsFilterType.cpp b/project2/files/fsFilterType.cpp index ba9ad72..2aecfee 100644 --- a/project2/files/fsFilterType.cpp +++ b/project2/files/fsFilterType.cpp @@ -40,4 +40,6 @@ class FsRowSpecType : public FsRows::SpecBase { const Variable typelist; }; -DECLARE_COMPONENT_LOADER("type", FsRowSpecType, FsRows::SpecBaseLoader); +NAMEDFACTORY("type", FsRowSpecType, FsRows::SpecBaseFactory); +NAMEDFACTORY("type", FsRowSpecType, FsRows::SpecBaseStringFactory); + diff --git a/project2/files/fsRows.cpp b/project2/files/fsRows.cpp index d22b6ea..c67c02f 100644 --- a/project2/files/fsRows.cpp +++ b/project2/files/fsRows.cpp @@ -14,11 +14,11 @@ #include #include #include -#include "instanceStore.impl.h" +#include typedef boost::filesystem::directory_iterator DirEnt; -DECLARE_LOADER("fsrows", FsRows); +NAMEDFACTORY("fsrows", FsRows, RowSetFactory); const Glib::ustring field_absPath("absPath"); const Glib::ustring field_relPath("relPath"); @@ -50,7 +50,7 @@ FsRows::FsRows(ScriptNodePtr p) : spec(p, "spec", ""), ignoreErrors(p, "ignoreerrors", true) { - p->script->loader.addLoadTarget(p, Storer::into(&specs)); + p->script->loader.addLoadTarget(p, Storer::into(&specs)); } FsRows::~FsRows() @@ -81,7 +81,7 @@ FsRows::execute(const Glib::ustring &, const RowProcessorCallback & rp, ExecCont for (SpecSpec::const_iterator sf = s.begin(); sf != s.end(); ) { const Glib::ustring & name = (*sf++); if (name[0] == '-') { - ss.specs.insert(InstanceMap::Get(name.substr(1))->createWith(*sf++)); + ss.specs.insert(SpecBaseStringFactory::createNew(name.substr(1), *sf++)); } else { throw NotSupported(name); @@ -237,5 +237,6 @@ FsRows::SearchState::fileType() const throw NotSupported(__PRETTY_FUNCTION__); } -INSTANTIATESTORE(std::string, FsRows::SpecBaseLoader); +INSTANTIATEFACTORY(FsRows::SpecBase, ScriptNodePtr); +INSTANTIATEFACTORY(FsRows::SpecBase, const Glib::ustring &); diff --git a/project2/files/fsRows.h b/project2/files/fsRows.h index 2e44750..897f274 100644 --- a/project2/files/fsRows.h +++ b/project2/files/fsRows.h @@ -8,6 +8,7 @@ #include "rowSet.h" #include "scriptStorage.h" #include "scriptLoader.h" +#include class CommonObjects; @@ -25,22 +26,8 @@ class FsRows : public RowSet { const struct stat & curStat(const SearchState * fs) const; }; typedef boost::intrusive_ptr SpecBasePtr; - template - class SpecBaseLoaderX : public GenLoader { - public: - virtual SpecBase * createWith(const Glib::ustring &) const = 0; - template > - class For : public BaseLoader { - public: - inline SpecBase * create(const ScriptNodePtr & v) const { - return new T(v); - } - inline SpecBase * createWith(const Glib::ustring & v) const { - return new T(v); - } - }; - }; - typedef SpecBaseLoaderX SpecBaseLoader; + typedef AdHoc::Factory SpecBaseFactory; + typedef AdHoc::Factory SpecBaseStringFactory; typedef ANONSTORAGEOF(SpecBase) SpecBases; typedef std::list SpecSpec; typedef boost::filesystem::path Path; diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 9e3c8ad..87d1223 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -247,7 +247,7 @@ DECLARE_OPTIONS(FilePresenterCache, "File Presenter Cache options") "The name of the component used to provide a unique request ID") END_OPTIONS(FilePresenterCache) -class FilePresenterCacheLoader : public ElementLoader::For { +class FilePresenterCacheLoader : public ComponentLoader { public: FilePresenterCacheLoader() { @@ -299,4 +299,5 @@ class FilePresenterCacheLoader : public ElementLoader::For { return files; } }; -DECLARE_CUSTOM_LOADER("filecache", FilePresenterCacheLoader); +NAMEDFACTORY("filecache", FilePresenterCache, PresenterCacheFactory); + diff --git a/project2/files/writeStream.cpp b/project2/files/writeStream.cpp index 9946ec6..485c138 100644 --- a/project2/files/writeStream.cpp +++ b/project2/files/writeStream.cpp @@ -14,7 +14,7 @@ class WriteStream : public Task { Task(s), path(s, "path") { - s->script->loader.addLoadTarget(s, Storer::into(&stream)); + s->script->loader.addLoadTarget(s, Storer::into(&stream)); } void execute(ExecContext * ec) const @@ -33,5 +33,5 @@ class WriteStream : public Task { StreamPtr stream; }; -DECLARE_LOADER("writestream", WriteStream); +NAMEDFACTORY("writestream", WriteStream, TaskFactory); diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index 0f56a33..cf1c446 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -96,7 +96,7 @@ class IceDaemonViewHost : public virtual CommonObjects, public virtual CheckHost CommonObjects(s), CheckHost(s) { - s->script->loader.addLoadTarget(s, Storer::into(&view)); + s->script->loader.addLoadTarget(s, Storer::into(&view)); } void executeView(RowSetPresenterPtr presenter, ExecContext * ec) const { diff --git a/project2/ice/iceDataSource.cpp b/project2/ice/iceDataSource.cpp index aa033fc..734eedc 100644 --- a/project2/ice/iceDataSource.cpp +++ b/project2/ice/iceDataSource.cpp @@ -44,12 +44,12 @@ IceDataSource::ClearSlice() libs.clear(); } -class IceDataSourceLoader : public ElementLoader::For { +class IceDataSourceLoader : public DataSourceFactory::For, public ComponentLoader { public: void onConfigLoad() override { IceBase::FinaliseLoad(IceDataSource::libs); } }; -DECLARE_CUSTOM_LOADER("icedatasource", IceDataSourceLoader); +NAMEDPLUGIN("icedatasource", IceDataSourceLoader, DataSourceFactory); diff --git a/project2/ice/iceRows.h b/project2/ice/iceRows.h index dc729ff..7fcda85 100644 --- a/project2/ice/iceRows.h +++ b/project2/ice/iceRows.h @@ -30,7 +30,8 @@ class IceRows : public RowSet, public IceClient { IceClient(p) { } - void loadComplete(const CommonObjects * co) { + void loadComplete(const CommonObjects * co) override + { IceClient::loadComplete(co); } }; diff --git a/project2/ice/iceTask.h b/project2/ice/iceTask.h index 2d71818..281429f 100644 --- a/project2/ice/iceTask.h +++ b/project2/ice/iceTask.h @@ -15,7 +15,10 @@ class IceTask : public Task, public IceClient { { } - void loadComplete(const CommonObjects * co) { IceClient::loadComplete(co); } + void loadComplete(const CommonObjects * co) override + { + IceClient::loadComplete(co); + } }; #endif diff --git a/project2/ice/slice2Common.cpp b/project2/ice/slice2Common.cpp index 9dfcf9f..9bd79aa 100644 --- a/project2/ice/slice2Common.cpp +++ b/project2/ice/slice2Common.cpp @@ -59,10 +59,10 @@ Slice2Common::ParameterVariables(Slice::OperationPtr o) } void -Slice2Common::Declaration(Slice::OperationPtr o) +Slice2Common::Declaration(Slice::OperationPtr o, const std::string & base) { - fprintf(code, "\t\t\tDECLARE_LOADER(\"%s-%s-%s\", %s);\n\n", - module.c_str(), interface.c_str(), o->name().c_str(), o->name().c_str()); + fprintf(code, "\t\t\tNAMEDFACTORY(\"%s-%s-%s\", %s, %s);\n\n", + module.c_str(), interface.c_str(), o->name().c_str(), o->name().c_str(), base.c_str()); } void diff --git a/project2/ice/slice2Common.h b/project2/ice/slice2Common.h index 170f0e7..8ea21d0 100644 --- a/project2/ice/slice2Common.h +++ b/project2/ice/slice2Common.h @@ -9,7 +9,7 @@ class Slice2Common : public Slice::ParserVisitor { void FunctionBegin(Slice::OperationPtr o); void ParameterVariables(Slice::OperationPtr o); - void Declaration(Slice::OperationPtr o); + void Declaration(Slice::OperationPtr o, const std::string &); void CallOperation(Slice::OperationPtr o); unsigned int Components() const; diff --git a/project2/ice/slice2Rows.cpp b/project2/ice/slice2Rows.cpp index 8c67222..b91d158 100644 --- a/project2/ice/slice2Rows.cpp +++ b/project2/ice/slice2Rows.cpp @@ -63,7 +63,7 @@ Slice2Rows::visitOperation(const Slice::OperationPtr & o) fprintf(code, "\t\t\t\t\t}\n\n"); ParameterVariables(o); fprintf(code, "\t\t\t};\n"); - Declaration(o); + Declaration(o, "RowSetFactory"); } } diff --git a/project2/ice/slice2Task.cpp b/project2/ice/slice2Task.cpp index 84a4f29..f6dc58f 100644 --- a/project2/ice/slice2Task.cpp +++ b/project2/ice/slice2Task.cpp @@ -61,7 +61,7 @@ Slice2Task::visitOperation(const Slice::OperationPtr & o) fprintf(code, "\t\t\t\t\t}\n\n"); ParameterVariables(o); fprintf(code, "\t\t\t};\n"); - Declaration(o); + Declaration(o, "TaskFactory"); } } diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp index e979f82..e151055 100644 --- a/project2/ice/unittests/testClient.cpp +++ b/project2/ice/unittests/testClient.cpp @@ -105,13 +105,13 @@ void commonTests(ExecContext * ec) { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexParam")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexRow")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTask")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams")); + BOOST_REQUIRE(TaskFactory::get("UnitTestComplex-ComplexInterface-ComplexParam")); + BOOST_REQUIRE(RowSetFactory::get("UnitTestComplex-ComplexInterface-ComplexRow")); BOOST_TEST_CHECKPOINT("Load test script"); ScriptReaderPtr r = new XmlScriptParser(iceroot / "testClient.xml"); @@ -142,13 +142,13 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexParam"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexRow"), NotSupported); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTask"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTestComplex-ComplexInterface-ComplexParam"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTestComplex-ComplexInterface-ComplexRow"), AdHoc::NoSuchPluginException); } void test_client_run(ExecContext *, const boost::filesystem::path & tmpdir); diff --git a/project2/ice/unittests/testClientCompile.cpp b/project2/ice/unittests/testClientCompile.cpp index 0332da7..a299fff 100644 --- a/project2/ice/unittests/testClientCompile.cpp +++ b/project2/ice/unittests/testClientCompile.cpp @@ -21,11 +21,11 @@ void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTask")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams")); } static @@ -33,11 +33,11 @@ void unloadTests() { BOOST_TEST_CHECKPOINT("Verify unloaded"); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows"), NotSupported); - BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTask"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams"), AdHoc::NoSuchPluginException); } BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index a1985a4..3a31ebd 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -27,7 +27,7 @@ class DummyTask : public Task { static unsigned int execCount; }; -DECLARE_LOADER("DummyTask", DummyTask); +NAMEDFACTORY("DummyTask", DummyTask, TaskFactory); unsigned int DummyTask::execCount = 0; class DummyParamTask : public Task { @@ -53,7 +53,7 @@ class DummyParamTask : public Task { static VariableType execA; static VariableType execB; }; -DECLARE_LOADER("DummyParamTask", DummyParamTask); +NAMEDFACTORY("DummyParamTask", DummyParamTask, TaskFactory); unsigned int DummyParamTask::execCount = 0; VariableType DummyParamTask::execA; VariableType DummyParamTask::execB; @@ -85,7 +85,7 @@ class DummyComplexParamTask : public Task { static VariableType execB; static VariableType execD; }; -DECLARE_LOADER("DummyComplexParamTask", DummyComplexParamTask); +NAMEDFACTORY("DummyComplexParamTask", DummyComplexParamTask, TaskFactory); unsigned int DummyComplexParamTask::execCount = 0; VariableType DummyComplexParamTask::execA; VariableType DummyComplexParamTask::execB; diff --git a/project2/json/presenter-p.cpp b/project2/json/presenter-p.cpp index 92ba8c1..29db13c 100644 --- a/project2/json/presenter-p.cpp +++ b/project2/json/presenter-p.cpp @@ -20,4 +20,5 @@ class Json_P_Presenter : public JsonPresenter { Variable Callback; }; -DECLARE_GENERIC_LOADER("json-p", PresenterLoader, Json_P_Presenter) +NAMEDFACTORY("json-p", Json_P_Presenter, PresenterFactory) + diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp index 8db182c..fe0a75d 100644 --- a/project2/json/presenter.cpp +++ b/project2/json/presenter.cpp @@ -141,4 +141,5 @@ JsonPresenter::writeTo(std::ostream & o, const std::string & encoding, ExecConte } } -DECLARE_GENERIC_LOADER("json", PresenterLoader, JsonPresenter) +NAMEDFACTORY("json", JsonPresenter, PresenterFactory); + diff --git a/project2/mail/sendmailTask.cpp b/project2/mail/sendmailTask.cpp index 054f844..5442887 100644 --- a/project2/mail/sendmailTask.cpp +++ b/project2/mail/sendmailTask.cpp @@ -19,7 +19,7 @@ DECLARE_OPTIONS(SendMailTask, "Send Email Task options") "The default encoding to use in email content") END_OPTIONS(SendMailTask); -DECLARE_LOADER("sendmail", SendMailTask); +NAMEDFACTORY("sendmail", SendMailTask, TaskFactory); uint8_t SendMailTask::MailPart::mimeIdx; diff --git a/project2/processes/processStream.cpp b/project2/processes/processStream.cpp index a4b5567..079def9 100644 --- a/project2/processes/processStream.cpp +++ b/project2/processes/processStream.cpp @@ -49,4 +49,5 @@ class ProcessStream : public Stream, IHaveParameters { const Variable path; }; -DECLARE_LOADER("processstream", ProcessStream); +NAMEDFACTORY("processstream", ProcessStream, StreamFactory); + diff --git a/project2/regex/regexRows.cpp b/project2/regex/regexRows.cpp index 6d72ccc..8939b2a 100644 --- a/project2/regex/regexRows.cpp +++ b/project2/regex/regexRows.cpp @@ -4,7 +4,7 @@ #include #include -DECLARE_LOADER("regexrows", RegexRows); +NAMEDFACTORY("regexrows", RegexRows, RowSetFactory); RegexRows::RegexRows(ScriptNodePtr p) : DefinedColumns(p, "columns", boost::bind(&Column::make, _1, _2)), diff --git a/project2/regex/regexTest.cpp b/project2/regex/regexTest.cpp index 59dca68..ab1bb47 100644 --- a/project2/regex/regexTest.cpp +++ b/project2/regex/regexTest.cpp @@ -3,7 +3,7 @@ #include "commonObjects.h" #include -DECLARE_LOADER("regextest", RegexTest); +NAMEDFACTORY("regextest", RegexTest, TestFactory); RegexTest::RegexTest(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index e1091a3..9b295d3 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -8,7 +8,7 @@ #define LOCK(l) std::lock_guard _lock##l(l) /// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections -class RdbmsDataSourceLoader : public ElementLoader::For { +class RdbmsDataSourceLoader : public ComponentLoader { public: void onIdle() override { @@ -32,7 +32,7 @@ class RdbmsDataSourceLoader : public ElementLoader::For { RdbmsDataSource::changedDSNs.clear(); } }; -DECLARE_CUSTOM_LOADER("rdbmsdatasource", RdbmsDataSourceLoader); +NAMEDFACTORY("rdbmsdatasource", RdbmsDataSource, DataSourceFactory); RdbmsDataSource::DBHosts RdbmsDataSource::dbhosts; RdbmsDataSource::FailedHosts RdbmsDataSource::failedhosts; diff --git a/project2/sql/sqlBulkLoad.cpp b/project2/sql/sqlBulkLoad.cpp index d976997..4f17837 100644 --- a/project2/sql/sqlBulkLoad.cpp +++ b/project2/sql/sqlBulkLoad.cpp @@ -15,7 +15,7 @@ class SqlBulkLoad : public Task { extras(p, "extras"), db(NULL) { - p->script->loader.addLoadTarget(p, Storer::into(&stream)); + p->script->loader.addLoadTarget(p, Storer::into(&stream)); } void loadComplete(const CommonObjects * co) @@ -41,4 +41,5 @@ class SqlBulkLoad : public Task { const RdbmsDataSource * db; }; -DECLARE_LOADER("sqlbulkload", SqlBulkLoad); +NAMEDFACTORY("sqlbulkload", SqlBulkLoad, TaskFactory); + diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index cf33f8e..6e5bd20 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -264,7 +264,7 @@ std::string SqlCache::DataSource; std::string SqlCache::HeaderTable; time_t SqlCache::CacheLife; -class CustomSqlCacheLoader : public ElementLoader::For { +class CustomSqlCacheLoader : public RowSetCacheFactory::For, public ComponentLoader { public: void onIdle() override { @@ -284,7 +284,7 @@ class CustomSqlCacheLoader : public ElementLoader::For { } } }; -DECLARE_CUSTOM_LOADER("sqlcache", CustomSqlCacheLoader); +NAMEDPLUGIN("sqlcache", CustomSqlCacheLoader, RowSetCacheFactory); DECLARE_OPTIONS(SqlCache, "SQL Cache options") ("cache.sql.dataSource", Options::value(&DataSource), diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp index ea334eb..cbf2210 100644 --- a/project2/sql/sqlMergeTask.cpp +++ b/project2/sql/sqlMergeTask.cpp @@ -40,8 +40,8 @@ class SqlMergeInsert : IHaveParameters, public Task { DB::ModifyCommand * insert; }; -DECLARE_LOADER("sqlmerge", SqlMergeTask); -DECLARE_LOADER("sqlmergeinsert", SqlMergeInsert); +NAMEDFACTORY("sqlmerge", SqlMergeTask, TaskFactory); +NAMEDFACTORY("sqlmergeinsert", SqlMergeInsert, TaskFactory); // Conversion logic SqlMergeTask::SqlMergeTask(const std::string & datasource, const std::string & target) : @@ -85,7 +85,7 @@ SqlMergeTask::SqlMergeTask(ScriptNodePtr p) : dtable(p->value("targettable", NULL).as()), dtablet(stringf("tmp_%s_%d", dtable.c_str(), getpid())) { - p->script->loader.addLoadTarget(p, Storer::into(&sources)); + p->script->loader.addLoadTarget(p, Storer::into(&sources)); if (!sources.empty() && useView(NULL)) { throw NotSupported("useview not supported with iterate fillers"); diff --git a/project2/sql/sqlRows.cpp b/project2/sql/sqlRows.cpp index f8a16e1..b6e40cc 100644 --- a/project2/sql/sqlRows.cpp +++ b/project2/sql/sqlRows.cpp @@ -10,7 +10,7 @@ #include "commonObjects.h" #include -DECLARE_LOADER("sqlrows", SqlRows); +NAMEDFACTORY("sqlrows", SqlRows, RowSetFactory); SqlRows::SqlRows(ScriptNodePtr p) : RowSet(p), diff --git a/project2/sql/sqlTask.cpp b/project2/sql/sqlTask.cpp index 94f5102..78c6d81 100644 --- a/project2/sql/sqlTask.cpp +++ b/project2/sql/sqlTask.cpp @@ -6,7 +6,7 @@ #include "commonObjects.h" #include "sqlVariableBinder.h" -DECLARE_LOADER("sqltask", SqlTask); +NAMEDFACTORY("sqltask", SqlTask, TaskFactory); StaticMessageException(RunOnNotSpecified, "runon attribute must be specified"); SqlTask::SqlTask(ScriptNodePtr p) : @@ -17,8 +17,8 @@ SqlTask::SqlTask(ScriptNodePtr p) : sqlCommand(p->child("sql")), db(NULL) { - p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into(&changesTasks)); - p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into(&noChangesTasks)); + p->script->loader.addLoadTargetSub(p, "changes", false, Storer::into(&changesTasks)); + p->script->loader.addLoadTargetSub(p, "nochanges", false, Storer::into(&noChangesTasks)); } SqlTask::~SqlTask() diff --git a/project2/sql/sqlTest.cpp b/project2/sql/sqlTest.cpp index fedc2a0..f3a5516 100644 --- a/project2/sql/sqlTest.cpp +++ b/project2/sql/sqlTest.cpp @@ -8,7 +8,7 @@ #include "sqlVariableBinder.h" #include -DECLARE_LOADER("sqltest", SqlTest); +NAMEDFACTORY("sqltest", SqlTest, TestFactory); class CantCompareNulls : public std::exception { }; diff --git a/project2/streams/streamNvpRows.cpp b/project2/streams/streamNvpRows.cpp index 2e97a5f..01242cf 100644 --- a/project2/streams/streamNvpRows.cpp +++ b/project2/streams/streamNvpRows.cpp @@ -157,7 +157,7 @@ class StreamNvpRows : public RowSet { assign(p->value("assign", "=", NULL).as()), encoding(p->value("encoding", "utf-8", NULL).as()) { - p->script->loader.addLoadTarget(p, Storer::into(&stream)); + p->script->loader.addLoadTarget(p, Storer::into(&stream)); } void execute(const Glib::ustring &, const RowProcessorCallback & rp, ExecContext * ec) const @@ -178,5 +178,5 @@ class StreamNvpRows : public RowSet { const Glib::ustring assign; const std::string encoding; }; -DECLARE_LOADER("streamnvprows", StreamNvpRows); +NAMEDFACTORY("streamnvprows", StreamNvpRows, RowSetFactory); diff --git a/project2/streams/streamPresenter.cpp b/project2/streams/streamPresenter.cpp index 229799c..37553c3 100644 --- a/project2/streams/streamPresenter.cpp +++ b/project2/streams/streamPresenter.cpp @@ -8,7 +8,7 @@ class StreamPresenter : public Presenter, public SourceOf { StreamPresenter(ScriptNodePtr e, ObjectSource os, ExecContext * ) : Presenter(os) { - e->script->loader.addLoadTarget(e, Storer::into(&stream)); + e->script->loader.addLoadTarget(e, Storer::into(&stream)); } void addNewArray(const Glib::ustring&, bool) const @@ -44,4 +44,5 @@ class StreamPresenter : public Presenter, public SourceOf { StreamPtr stream; }; -DECLARE_GENERIC_LOADER("stream", PresenterLoader, StreamPresenter) +NAMEDFACTORY("stream", StreamPresenter, PresenterFactory); + diff --git a/project2/streams/streamRows.cpp b/project2/streams/streamRows.cpp index c8f7ee1..a4f8aae 100644 --- a/project2/streams/streamRows.cpp +++ b/project2/streams/streamRows.cpp @@ -55,7 +55,7 @@ class StreamRows : public DefinedColumns, public RowSet { encoding(p->value("encoding", "utf-8", NULL).as()), skipheader(p->value("skipheader", 0, NULL).as()) { - p->script->loader.addLoadTarget(p, Storer::into(&stream)); + p->script->loader.addLoadTarget(p, Storer::into(&stream)); } void execute(const Glib::ustring &, const RowProcessorCallback & rp, ExecContext * ec) const @@ -143,5 +143,5 @@ class StreamRows : public DefinedColumns, public RowSet { const std::string encoding; const size_t skipheader; }; -DECLARE_LOADER("streamrows", StreamRows); +NAMEDFACTORY("streamrows", StreamRows, RowSetFactory); diff --git a/project2/streams/viewStream.cpp b/project2/streams/viewStream.cpp index 17763ab..0f2308a 100644 --- a/project2/streams/viewStream.cpp +++ b/project2/streams/viewStream.cpp @@ -5,6 +5,7 @@ #include "viewHost.h" #include #include +#include class SinkStream : public boost::iostreams::sink { public: @@ -27,7 +28,7 @@ class ViewStream : public Stream, public ViewHost { Stream(p), ViewHost(p) { - p->script->loader.addLoadTarget(p, Storer::into(&presenter, Scripted, (ExecContext*)NULL)); + p->script->loader.addLoadTarget(p, Storer::into(&presenter, Scripted, (ExecContext*)NULL)); } void runStream(const Stream::Sink & s, ExecContext * ec) const { @@ -49,4 +50,5 @@ class ViewStream : public Stream, public ViewHost { MultiRowSetPresenterPtr presenter; }; -DECLARE_LOADER("viewstream", ViewStream); +NAMEDFACTORY("viewstream", ViewStream, StreamFactory); + diff --git a/project2/url/downloadToFile.cpp b/project2/url/downloadToFile.cpp index af23112..3b90ffc 100644 --- a/project2/url/downloadToFile.cpp +++ b/project2/url/downloadToFile.cpp @@ -31,5 +31,5 @@ class Download : public Task, VariableCurlHelper { const Variable destination; }; -DECLARE_LOADER("download", Download); +NAMEDFACTORY("download", Download, TaskFactory); diff --git a/project2/url/urlStream.cpp b/project2/url/urlStream.cpp index e3ee862..21bf5c2 100644 --- a/project2/url/urlStream.cpp +++ b/project2/url/urlStream.cpp @@ -19,5 +19,5 @@ class UrlStream : public Stream, VariableCurlHelper { } }; -DECLARE_LOADER("urlstream", UrlStream); +NAMEDFACTORY("urlstream", UrlStream, StreamFactory); diff --git a/project2/ut/testScriptHost.cpp b/project2/ut/testScriptHost.cpp index c3090ff..c989abb 100644 --- a/project2/ut/testScriptHost.cpp +++ b/project2/ut/testScriptHost.cpp @@ -11,7 +11,7 @@ TestScriptHost::TestScriptHost(ScriptReaderPtr script) : ViewHost(script->root()) { Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - script->loader.addLoadTarget(script->root(), Storer::into(&presenter, Scripted, (ExecContext*)NULL)); + script->loader.addLoadTarget(script->root(), Storer::into(&presenter, Scripted, (ExecContext*)NULL)); } TestScriptHost::~TestScriptHost() diff --git a/project2/xml/mutators/copy.cpp b/project2/xml/mutators/copy.cpp index f58bef7..c94d76d 100644 --- a/project2/xml/mutators/copy.cpp +++ b/project2/xml/mutators/copy.cpp @@ -27,5 +27,5 @@ class Copy : public XmlDocMutator { Variable delAfter; }; -DECLARE_GENERIC_LOADER("copy", XmlDocMutatorLoader, Copy); +NAMEDFACTORY("copy", Copy, XmlDocMutatorFactory); diff --git a/project2/xml/mutators/copyToAttr.cpp b/project2/xml/mutators/copyToAttr.cpp index a58ac93..6311f1a 100644 --- a/project2/xml/mutators/copyToAttr.cpp +++ b/project2/xml/mutators/copyToAttr.cpp @@ -31,6 +31,5 @@ class CopyToAttr : public XmlDocMutator { Variable delAfter; }; -DECLARE_GENERIC_LOADER("copytoattr", XmlDocMutatorLoader, CopyToAttr); - +NAMEDFACTORY("copytoattr", CopyToAttr, XmlDocMutatorFactory); diff --git a/project2/xml/mutators/create.cpp b/project2/xml/mutators/create.cpp index 88d8808..645914f 100644 --- a/project2/xml/mutators/create.cpp +++ b/project2/xml/mutators/create.cpp @@ -20,4 +20,5 @@ class Create : public XmlDocMutator { Variable name; }; -DECLARE_GENERIC_LOADER("create", XmlDocMutatorLoader, Create); +NAMEDFACTORY("create", Create, XmlDocMutatorFactory); + diff --git a/project2/xml/mutators/delete.cpp b/project2/xml/mutators/delete.cpp index 6e4d597..f1c3f61 100644 --- a/project2/xml/mutators/delete.cpp +++ b/project2/xml/mutators/delete.cpp @@ -18,6 +18,5 @@ class Delete : public XmlDocMutator { Variable xpath; }; -DECLARE_GENERIC_LOADER("delete", XmlDocMutatorLoader, Delete); - +NAMEDFACTORY("delete", Delete, XmlDocMutatorFactory); diff --git a/project2/xml/mutators/rename.cpp b/project2/xml/mutators/rename.cpp index ec347d8..ed1a5ca 100644 --- a/project2/xml/mutators/rename.cpp +++ b/project2/xml/mutators/rename.cpp @@ -20,7 +20,5 @@ class Rename : public XmlDocMutator { Variable newname; }; -DECLARE_GENERIC_LOADER("rename", XmlDocMutatorLoader, Rename); - - +NAMEDFACTORY("rename", Rename, XmlDocMutatorFactory); diff --git a/project2/xml/rawView.cpp b/project2/xml/rawView.cpp index ace271c..69009aa 100644 --- a/project2/xml/rawView.cpp +++ b/project2/xml/rawView.cpp @@ -68,7 +68,7 @@ class RawView : public RawViewBase { private: const xmlpp::Element * copyRoot; }; -DECLARE_LOADER("rawview", RawView); +NAMEDFACTORY("rawview", RawView, ViewFactory); class XmlResourceView : public RawViewBase, XmlDocumentCache, VariableCurlHelper { public: @@ -91,5 +91,5 @@ class XmlResourceView : public RawViewBase, XmlDocumentCache, VariableCurlHelper private: Variable encoding; }; -DECLARE_LOADER("xmlresourceview", XmlResourceView); +NAMEDFACTORY("xmlresourceview", XmlResourceView, ViewFactory); diff --git a/project2/xml/transformHtml.cpp b/project2/xml/transformHtml.cpp index 6d1e925..2cfc181 100644 --- a/project2/xml/transformHtml.cpp +++ b/project2/xml/transformHtml.cpp @@ -82,21 +82,20 @@ class TransformXmlToHtml : public TransformImpl { } }; -class XmlTransformLoader : public TransformLoader::For { - public: - XmlTransformLoader() - { - xmlInitParser(); - exsltRegisterAll(); - } +static void initLibXml() __attribute__((constructor(102))); +void initLibXml() +{ + xmlInitParser(); + exsltRegisterAll(); +} - ~XmlTransformLoader() - { - xsltCleanupGlobals(); - xmlCleanupParser(); - } -}; +static void cleanupLibXml() __attribute__((constructor(102))); +void cleanupLibXml() +{ + xsltCleanupGlobals(); + xmlCleanupParser(); +} -DECLARE_CUSTOM_COMPONENT_LOADER("TransformXmlToHtml", TransformXmlToHtml, XmlTransformLoader, TransformLoader) -DECLARE_TRANSFORMTARGET("htmldocument", HtmlDocument) +NAMEDFACTORY("TransformXmlToHtml", TransformXmlToHtml, TransformFactory); +NAMEDFACTORY("htmldocument", HtmlDocument, TransformTargetFactory); diff --git a/project2/xml/transformText.cpp b/project2/xml/transformText.cpp index 662674d..525b910 100644 --- a/project2/xml/transformText.cpp +++ b/project2/xml/transformText.cpp @@ -96,6 +96,6 @@ END_OPTIONS(TransformHtmlToText) int TransformHtmlToText::defaultWidth; bool TransformHtmlToText::defaultLinks; -DECLARE_COMPONENT_LOADER("TransformHtmlToText", TransformHtmlToText, TransformLoader); -DECLARE_TRANSFORMTARGET("textdocument", TextDocument) +NAMEDFACTORY("TransformHtmlToText", TransformHtmlToText, TransformFactory); +NAMEDFACTORY("textdocument", TextDocument, TransformTargetFactory) diff --git a/project2/xml/xmlCache.cpp b/project2/xml/xmlCache.cpp index 52e693a..6104730 100644 --- a/project2/xml/xmlCache.cpp +++ b/project2/xml/xmlCache.cpp @@ -74,7 +74,7 @@ class XmlCache : public RowSetCache { XmlPresenterPtr writeTo; - friend class CustomXmlCacheLoader; + friend class CustomXmlCacheFactory; static boost::filesystem::path Store; static std::string FileName; static time_t CacheLife; @@ -84,7 +84,7 @@ boost::filesystem::path XmlCache::Store; std::string XmlCache::FileName; time_t XmlCache::CacheLife; -class CustomXmlCacheLoader : public ElementLoader::For { +class CustomXmlCacheFactory : public AdHoc::Factory::For, public ComponentLoader { public: void onIdle() override { @@ -125,7 +125,7 @@ class CustomXmlCacheLoader : public ElementLoader::For { return files; } }; -DECLARE_CUSTOM_LOADER("xmlcache", CustomXmlCacheLoader); +NAMEDPLUGIN("xmlcache", CustomXmlCacheFactory, RowSetCacheFactory); DECLARE_OPTIONS(XmlCache, "XML Cache options") ("cache.xml.store", Options::value(&XmlCache::Store, "/tmp/project2.cache"), diff --git a/project2/xml/xmlDocumentCache.cpp b/project2/xml/xmlDocumentCache.cpp index 81833f9..f37924d 100644 --- a/project2/xml/xmlDocumentCache.cpp +++ b/project2/xml/xmlDocumentCache.cpp @@ -69,5 +69,5 @@ class XmlDocumentCacheClearer : public ComponentLoader { Logger()->messagef(LOG_DEBUG, "%s: Cleared XML document cache", __PRETTY_FUNCTION__); } }; -DECLARE_COMPONENT("XmlDocumentCacheClearer", XmlDocumentCacheClearer); +NAMEDPLUGIN("XmlDocumentCacheClearer", XmlDocumentCacheClearer, ComponentLoader); diff --git a/project2/xml/xmlDocumentPrefetch.cpp b/project2/xml/xmlDocumentPrefetch.cpp index 4af0055..357f50b 100644 --- a/project2/xml/xmlDocumentPrefetch.cpp +++ b/project2/xml/xmlDocumentPrefetch.cpp @@ -2,7 +2,8 @@ #include "xmlDocumentPrefetch.h" #include "scriptLoader.h" -DECLARE_LOADER("xmldocumentprefetch", XmlDocumentPrefetch); +NAMEDFACTORY("xmldocumentprefetch", XmlDocumentPrefetch, ViewFactory); +NAMEDFACTORY("xmldocumentprefetch", XmlDocumentPrefetch, TaskFactory); XmlDocumentPrefetch::XmlDocumentPrefetch(ScriptNodePtr p) : SourceObject(p), diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index a43f9f8..ec3d2f3 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "instanceStore.impl.h" +#include DECLARE_OPTIONS(XmlPresenter, "XML Presenter options") ("presenter.xml.typeid.null", Options::value(&typeidNull, false), @@ -43,7 +43,7 @@ bool XmlPresenter::dateAttr; bool XmlPresenter::timeAttr; boost::optional XmlPresenter::customFormat; -DECLARE_GENERIC_LOADER("xml", PresenterLoader, XmlPresenter) +NAMEDFACTORY("xml", XmlPresenter, PresenterFactory) XmlPresenter::XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & ct) : Presenter(Default), @@ -67,7 +67,7 @@ XmlPresenter::XmlPresenter(ScriptNodePtr e, ObjectSource os, ExecContext * ec) : style(e, "style", Null()) { if (os == Scripted) { - e->script->loader.addLoadTarget(e, Storer::into(&mutators)); + e->script->loader.addLoadTarget(e, Storer::into(&mutators)); } } @@ -275,5 +275,5 @@ XmlDocMutator::XmlDocMutator(ScriptNodePtr) { } -INSTANTIATESTORE(std::string, XmlDocMutatorLoader); +INSTANTIATEFACTORY(XmlDocMutator, ScriptNodePtr); diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h index 6e3dac2..996ce9b 100644 --- a/project2/xml/xmlPresenter.h +++ b/project2/xml/xmlPresenter.h @@ -18,7 +18,7 @@ class XmlDocMutator : public IntrusivePtrBase { virtual void mutateElement(xmlpp::Element *) const = 0; }; typedef boost::intrusive_ptr XmlDocMutatorPtr; -typedef GenLoader XmlDocMutatorLoader; +typedef AdHoc::Factory XmlDocMutatorFactory; class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf, public SourceOf, public SourceOf >, public WritableContent, public SourceOf { public: diff --git a/project2/xml/xmlRawRows.cpp b/project2/xml/xmlRawRows.cpp index eb6e003..5b46279 100644 --- a/project2/xml/xmlRawRows.cpp +++ b/project2/xml/xmlRawRows.cpp @@ -3,7 +3,7 @@ #include #include -DECLARE_LOADER("xmlrawrows", XmlRawRows); +NAMEDFACTORY("xmlrawrows", XmlRawRows, RowSetFactory); class XmlRowState : public RowState { public: diff --git a/project2/xml/xmlRows.cpp b/project2/xml/xmlRows.cpp index 2d3e631..1277274 100644 --- a/project2/xml/xmlRows.cpp +++ b/project2/xml/xmlRows.cpp @@ -10,7 +10,7 @@ #include #include -DECLARE_LOADER("xmlrows", XmlRows); +NAMEDFACTORY("xmlrows", XmlRows, RowSetFactory); XmlRows::XmlRows(ScriptNodePtr p) : RowSet(p), diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index 66b6b0b..c86f8c0 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -90,9 +90,9 @@ XmlScriptParser::isCurrent() const return true; } -class XmlScriptReaderLoader : public ScriptReaderLoader { +class XmlScriptReaderLoader : public ScriptReaderFactory { public: - ScriptReaderPtr resolveScript(const std::string & group, const std::string & name) const { + XmlScriptParser * create(const std::string & group, const std::string & name) const { boost::filesystem::path script(boost::filesystem::path(group) / (name + ".xml")); if (boost::filesystem::is_regular_file(script)) { return new XmlScriptParser(script); @@ -248,4 +248,5 @@ XmlScriptNode::composeWithCallbacks(const LiteralCallback & lcb, const NodeCallb } } -DECLARE_CUSTOM_COMPONENT_LOADER("xmlScriptReader", XmlScriptReaderLoader, XmlScriptReaderLoader, ScriptReaderLoader); +NAMEDPLUGIN("xmlScriptReader", XmlScriptReaderLoader, ScriptReaderFactory); + diff --git a/project2/xml/xpathRows.cpp b/project2/xml/xpathRows.cpp index 656bbac..0501012 100644 --- a/project2/xml/xpathRows.cpp +++ b/project2/xml/xpathRows.cpp @@ -9,7 +9,7 @@ #include #include -DECLARE_LOADER("xpathrows", XPathRows); +NAMEDFACTORY("xpathrows", XPathRows, RowSetFactory); SimpleMessageException(XpathInitError); SimpleMessageException(XpathEvalError); -- cgit v1.2.3 From 1be0775221f8ae6262cbde7bb28e97d7e29d8b55 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Oct 2015 00:11:28 +0100 Subject: Slash the amount of inclusion in pre-compiled headers --- project2/cgi/pch.hpp | 6 ++---- project2/common/pch.hpp | 16 ++-------------- project2/common/scripts.cpp | 1 + project2/common/variableType.cpp | 1 + project2/common/viewHost.h | 1 - project2/console/pch.hpp | 7 +------ project2/files/pch.hpp | 20 +------------------- project2/ice/pch.hpp | 8 ++------ project2/json/pch.hpp | 4 +--- project2/sql/pch.hpp | 28 ++++------------------------ project2/xml/pch.hpp | 10 +--------- 11 files changed, 16 insertions(+), 86 deletions(-) diff --git a/project2/cgi/pch.hpp b/project2/cgi/pch.hpp index 065558b..125c912 100644 --- a/project2/cgi/pch.hpp +++ b/project2/cgi/pch.hpp @@ -2,11 +2,9 @@ #ifndef CGI_PCH #define CGI_PCH -#include "cgiRequestContext.h" -#include "cgiHttpHeader.h" -#include "scriptLoader.h" +#include +#include #include -#include "options.h" #include #include #include diff --git a/project2/common/pch.hpp b/project2/common/pch.hpp index a18ebbb..2feca3c 100644 --- a/project2/common/pch.hpp +++ b/project2/common/pch.hpp @@ -5,15 +5,10 @@ #include #include #include -#include -#include +#include #include -#include -#include -#include -#include "options.h" #include -#include +#include #include #include #include @@ -25,13 +20,6 @@ #include #include #include -#include "scriptStorage.h" -#include "scriptLoader.h" -#include "plugable.h" -#include "variables.h" -#include "variableType.h" -#include "sourceObject.h" -#include "scripts.h" #endif #endif diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp index 0410817..3714d37 100644 --- a/project2/common/scripts.cpp +++ b/project2/common/scripts.cpp @@ -2,6 +2,7 @@ #include #include "variables/fixed.h" #include +#include #include "appInstance.h" #include diff --git a/project2/common/variableType.cpp b/project2/common/variableType.cpp index 2902638..84170b7 100644 --- a/project2/common/variableType.cpp +++ b/project2/common/variableType.cpp @@ -1,6 +1,7 @@ #include #include "variableType.h" #include "logger.h" +#include "exceptions.h" #include #include diff --git a/project2/common/viewHost.h b/project2/common/viewHost.h index 5ede3e4..09196f3 100644 --- a/project2/common/viewHost.h +++ b/project2/common/viewHost.h @@ -5,7 +5,6 @@ #include "presenter.h" #include "checkHost.h" #include -#include #include "commonObjects.h" class ViewHost : virtual public CheckHost, virtual public CommonObjects { diff --git a/project2/console/pch.hpp b/project2/console/pch.hpp index fa98d28..829f4a0 100644 --- a/project2/console/pch.hpp +++ b/project2/console/pch.hpp @@ -2,13 +2,8 @@ #ifndef CONSOLE_PCH #define CONSOLE_PCH -#include "consoleAppEngine.h" -#include "consolePresenter.h" -#include "exceptions.h" -#include "logger.h" -#include "scriptLoader.h" +#include #include -#include "options.h" #include #include diff --git a/project2/files/pch.hpp b/project2/files/pch.hpp index 58f05b9..91c45d8 100644 --- a/project2/files/pch.hpp +++ b/project2/files/pch.hpp @@ -2,29 +2,11 @@ #ifndef FILES_PCH #define FILES_PCH -#include -#include -#include #include -#include #include #include #include -#include -#include "definedColumns.h" -#include "exceptions.h" -#include "fsRows.h" -#include -#include -#include "logger.h" -#include "optionsSource.h" -#include "rowProcessor.h" -#include "rowSet.h" -#include "scopeExit.h" -#include "scriptLoader.h" -#include "scripts.h" -#include "scriptStorage.h" -#include "variables.h" +#include #endif #endif diff --git a/project2/ice/pch.hpp b/project2/ice/pch.hpp index 3ed09f0..1268e36 100644 --- a/project2/ice/pch.hpp +++ b/project2/ice/pch.hpp @@ -4,16 +4,12 @@ #include #include -#include +#include #include -#include -#include -#include #include -#include #include #include -#include +#include #include #include diff --git a/project2/json/pch.hpp b/project2/json/pch.hpp index 1309317..3aa19d4 100644 --- a/project2/json/pch.hpp +++ b/project2/json/pch.hpp @@ -2,10 +2,8 @@ #ifndef JSON_PCH #define JSON_PCH -#include +#include #include -#include -#include #include #include diff --git a/project2/sql/pch.hpp b/project2/sql/pch.hpp index e3dcda2..857eb5b 100644 --- a/project2/sql/pch.hpp +++ b/project2/sql/pch.hpp @@ -2,31 +2,11 @@ #ifndef SQL_PCH #define SQL_PCH -#include "cache.h" -#include "column.h" -#include "columns.h" -#include "command.h" -#include "commonObjects.h" -#include "exceptions.h" -#include "iHaveParameters.h" -#include "logger.h" -#include "modifycommand.h" -#include "rdbmsDataSource.h" -#include "rowProcessor.h" -#include "rowSet.h" -#include "selectcommand.h" -#include "sqlHandleAsVariableType.h" -#include "sqlVariableBinder.h" -#include "sqlWriter.h" -#include "variables.h" -#include "scriptLoader.h" -#include "scripts.h" -#include -#include "options.h" -#include -#include -#include #include +#include +#include +#include +#include #endif #endif diff --git a/project2/xml/pch.hpp b/project2/xml/pch.hpp index 1eb8309..5832628 100644 --- a/project2/xml/pch.hpp +++ b/project2/xml/pch.hpp @@ -2,16 +2,8 @@ #ifndef XML_PCH #define XML_PCH -#include "cache.h" -#include "exceptions.h" -#include "iHaveParameters.h" -#include "logger.h" -#include "presenter.h" -#include "rowProcessor.h" -#include "safeMapFind.h" -#include "variables.h" #include -#include "options.h" +#include #include #include #include -- cgit v1.2.3 From 49b523b9edd52b250d30adac6cd5abbabb8318ed Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Oct 2015 08:58:27 +0100 Subject: Fix factory type in sqlMerge --- project2/sql/sqlMergeTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project2/sql/sqlMergeTask.cpp b/project2/sql/sqlMergeTask.cpp index cbf2210..6e2e002 100644 --- a/project2/sql/sqlMergeTask.cpp +++ b/project2/sql/sqlMergeTask.cpp @@ -85,7 +85,7 @@ SqlMergeTask::SqlMergeTask(ScriptNodePtr p) : dtable(p->value("targettable", NULL).as()), dtablet(stringf("tmp_%s_%d", dtable.c_str(), getpid())) { - p->script->loader.addLoadTarget(p, Storer::into(&sources)); + p->script->loader.addLoadTarget(p, Storer::into(&sources)); if (!sources.empty() && useView(NULL)) { throw NotSupported("useview not supported with iterate fillers"); -- cgit v1.2.3 From cd467d5978b4e232b66c0fd8041f7c193ead3d5b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Oct 2015 21:05:13 +0100 Subject: Merge Plugable and ComponentLoader into new LifeCycle class --- project2/basics/caches/memoryCache.cpp | 2 +- project2/basics/options/showHelp.cpp | 2 +- project2/basics/options/showHelp.h | 4 +-- project2/cgi/cgiAppEngine.cpp | 3 +- project2/cgi/cgiProgRouter.cpp | 2 +- project2/cgi/p2webCgi.cpp | 9 +++--- project2/cgi/p2webFCgi.cpp | 9 +++--- project2/cgi/testCgi.cpp | 9 +++--- project2/common/componentLoader.cpp | 39 ------------------------ project2/common/componentLoader.h | 21 ------------- project2/common/library.cpp | 2 +- project2/common/lifeCycle.cpp | 50 +++++++++++++++++++++++++++++++ project2/common/lifeCycle.h | 25 ++++++++++++++++ project2/common/logger.h | 4 +-- project2/common/optionsSource.cpp | 5 ++-- project2/common/plugable.cpp | 14 --------- project2/common/plugable.h | 14 --------- project2/common/scriptLoader.cpp | 3 -- project2/common/scriptLoader.h | 1 - project2/common/scriptStorage.h | 3 +- project2/common/scripts.h | 1 - project2/compression/decompressStream.cpp | 1 - project2/console/consoleAppEngine.cpp | 5 ++-- project2/console/p2consoleMain.cpp | 7 ++--- project2/daemon/p2daemonAppEngine.cpp | 3 +- project2/daemon/p2daemonMain.cpp | 5 ++-- project2/files/presenterCache.cpp | 2 +- project2/ice/iceDaemon.cpp | 2 +- project2/ice/iceDataSource.cpp | 2 +- project2/sql/rdbmsDataSource.cpp | 2 +- project2/sql/sqlCache.cpp | 2 +- project2/xml/sessionXml.cpp | 2 +- project2/xml/xmlCache.cpp | 2 +- project2/xml/xmlDocumentCache.cpp | 4 +-- 34 files changed, 117 insertions(+), 144 deletions(-) delete mode 100644 project2/common/componentLoader.cpp delete mode 100644 project2/common/componentLoader.h create mode 100644 project2/common/lifeCycle.cpp create mode 100644 project2/common/lifeCycle.h delete mode 100644 project2/common/plugable.cpp delete mode 100644 project2/common/plugable.h diff --git a/project2/basics/caches/memoryCache.cpp b/project2/basics/caches/memoryCache.cpp index 5d58a47..0f3ddf6 100644 --- a/project2/basics/caches/memoryCache.cpp +++ b/project2/basics/caches/memoryCache.cpp @@ -145,7 +145,7 @@ class MemoryCache : public RowSetCache { time_t MemoryCache::CacheLife; MemoryCache::CacheStore MemoryCache::Store; -class CustomMemoryCacheLoader : public RowSetCacheFactory::For, public ComponentLoader { +class CustomMemoryCacheLoader : public RowSetCacheFactory::For, public LifeCycle { public: void onPeriodic() override { typedef MemoryCache::CacheStore::index::type::iterator iter; diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp index 81c9150..395baed 100644 --- a/project2/basics/options/showHelp.cpp +++ b/project2/basics/options/showHelp.cpp @@ -29,5 +29,5 @@ ShowHelpComponent::Option() } bool ShowHelpComponent::showHelp; -NAMEDPLUGIN("ShowHelpComponent", ShowHelpComponent, ComponentLoader); +NAMEDPLUGIN("ShowHelpComponent", ShowHelpComponent, LifeCycle); diff --git a/project2/basics/options/showHelp.h b/project2/basics/options/showHelp.h index 75fb4cb..c42a736 100644 --- a/project2/basics/options/showHelp.h +++ b/project2/basics/options/showHelp.h @@ -1,10 +1,10 @@ #ifndef SHOWHELP_H #define SHOWHELP_H -#include #include +#include -class ShowHelpComponent : public ComponentLoader { +class ShowHelpComponent : public LifeCycle { public: void onConfigLoad() override; static Options::TargetPtr Option(); diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index a263a38..a69fa9e 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include typedef boost::uuids::uuid SIDKey; @@ -319,7 +318,7 @@ CgiApplicationEngine::process(std::ostream & IO, cgicc::CgiInput * cgii, const C boost::function sn = boost::bind(&CgiEnvInput::getenv, &cgienv, "SERVER_NAME"); OptionsSource::loadSources(boost::bind(&CgiApplicationEngine::derivedPlatform, sn)); CgiRequestContext crc(cgii, cgienv); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBefore, _1)); Logger()->messagebf(LOG_DEBUG, "%s: Processing request (%s)", __FUNCTION__, crc.getRedirectURL()); process(IO, &crc); Logger()->messagef(LOG_DEBUG, "%s: Completed request", __FUNCTION__); diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp index da04be6..2b72652 100644 --- a/project2/cgi/cgiProgRouter.cpp +++ b/project2/cgi/cgiProgRouter.cpp @@ -130,7 +130,7 @@ class RoutingTable { NAMEDFACTORY("route", RoutingTable::Route, RoutingTable::RouteFactory); class ProgRouter; -class ProgRouterFactory : public RouterFactory::For, public ComponentLoader { +class ProgRouterFactory : public RouterFactory::For, public LifeCycle { public: void onBefore() override { diff --git a/project2/cgi/p2webCgi.cpp b/project2/cgi/p2webCgi.cpp index a59621d..33e1b8b 100644 --- a/project2/cgi/p2webCgi.cpp +++ b/project2/cgi/p2webCgi.cpp @@ -1,6 +1,5 @@ #include "cgiAppEngine.h" #include -#include class GetEnv : public CgiEnvInput { public: @@ -15,12 +14,12 @@ class GetEnv : public CgiEnvInput { int main(void) { - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBegin, _1)); CgiApplicationEngine app; GetEnv ge; app.process(std::cout, NULL, ge); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1)); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIteration, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onPeriodic, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIdle, _1)); } diff --git a/project2/cgi/p2webFCgi.cpp b/project2/cgi/p2webFCgi.cpp index e31986d..fae6cca 100644 --- a/project2/cgi/p2webFCgi.cpp +++ b/project2/cgi/p2webFCgi.cpp @@ -2,7 +2,6 @@ #include "cgiAppEngine.h" #include #include -#include time_t lastPeriodic = 0; time_t periodicDelay = 600; @@ -12,7 +11,7 @@ void p2webPeriodic() { time(&lastPeriodic); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onPeriodic, _1)); } static @@ -22,7 +21,7 @@ p2webGoingIdle(int) if (time(NULL) > lastPeriodic + periodicDelay) { p2webPeriodic(); } - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIdle, _1)); } int @@ -41,7 +40,7 @@ main(void) fprintf(stderr, "Failed to set signal handler\n"); } alarm(60); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBegin, _1)); CgiApplicationEngine app; while (FCGX_Accept_r(&request) == 0) { alarm(0); @@ -49,7 +48,7 @@ main(void) boost::filesystem::current_path(boost::filesystem::initial_path()); app.process(IO, &IO, IO); FCGX_Finish_r(&request); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIteration, _1)); if (time(NULL) > lastPeriodic + periodicDelay) { p2webPeriodic(); } diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index 3c79a77..7f9df28 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -8,7 +8,6 @@ #include "cgiRequestContext.h" #include "cgiAppEngine.h" #include -#include #define TESTOPT(name, def, desc) \ (name, Options::value(optStore().insert(OptStore::value_type(name, StrPtr(new std::string()))).first->second.get(), def), desc) @@ -52,7 +51,7 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput { } void run() { - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBegin, _1)); CgiApplicationEngine app; boost::function sn = boost::bind(&CgiEnvInput::getenv, this, "SERVER_NAME"); OptionsSource::loadSources(boost::bind(&CgiApplicationEngine::derivedPlatform, sn)); @@ -80,11 +79,11 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput { optStore()["QUERY_STRING"] = StrPtr(new std::string()); } app.process(std::cout, this, *this); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIteration, _1)); } - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onPeriodic, _1)); } - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIdle, _1)); } INITOPTIONS; diff --git a/project2/common/componentLoader.cpp b/project2/common/componentLoader.cpp deleted file mode 100644 index 5506ed2..0000000 --- a/project2/common/componentLoader.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "componentLoader.h" -#include - -ComponentLoader::~ComponentLoader() -{ -} - -void -ComponentLoader::onBegin() -{ -} - -void -ComponentLoader::onBefore() -{ -} - -void -ComponentLoader::onIdle() -{ -} - -void -ComponentLoader::onIteration() -{ -} - -void -ComponentLoader::onPeriodic() -{ -} - -void -ComponentLoader::onConfigLoad() -{ -} - -INSTANTIATEPLUGINOF(ComponentLoader); - diff --git a/project2/common/componentLoader.h b/project2/common/componentLoader.h deleted file mode 100644 index d3cff99..0000000 --- a/project2/common/componentLoader.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef COMPONENTLOADER_H -#define COMPONENTLOADER_H - -#include - -/// Helper for loading and maintaining Project2 components -class ComponentLoader : public virtual AdHoc::AbstractPluginImplementation { - public: - virtual ~ComponentLoader() = 0; - virtual void onBegin(); // App engine start up (before settings are processed) - virtual void onBefore(); // Before the app engine processes a request (after settings are processed) - virtual void onIdle(); // When the app engine goes idle - virtual void onIteration(); // When the app engine has completed an iteration - virtual void onPeriodic(); // When the app engine feels like it - virtual void onConfigLoad(); // When the environment reloads the configuration - virtual bool cacheable() const { return true; } // The component can be cached for next run -}; -typedef AdHoc::PluginOf LifeCycleComponentPlugin; - -#endif - diff --git a/project2/common/library.cpp b/project2/common/library.cpp index ce753bd..136e9d4 100644 --- a/project2/common/library.cpp +++ b/project2/common/library.cpp @@ -23,7 +23,7 @@ Library::~Library() } STORAGEOF(Library) libraries; -class LibraryLoader : public ScriptNodeFactory::For, public ComponentLoader { +class LibraryLoader : public ScriptNodeFactory::For, public LifeCycle { public: void onIteration() override { diff --git a/project2/common/lifeCycle.cpp b/project2/common/lifeCycle.cpp new file mode 100644 index 0000000..60ed172 --- /dev/null +++ b/project2/common/lifeCycle.cpp @@ -0,0 +1,50 @@ +#include "lifeCycle.h" +#include +#include + +LifeCycle::~LifeCycle() +{ +} + +void +LifeCycle::onBegin() +{ +} + +void +LifeCycle::onBefore() +{ +} + +void +LifeCycle::onIdle() +{ +} + +void +LifeCycle::onIteration() +{ +} + +void +LifeCycle::onPeriodic() +{ +} + +void +LifeCycle::onConfigLoad() +{ +} + +void +LifeCycle::onAllComponents(const boost::function & func) +{ + for(auto p : AdHoc::PluginManager::getDefault()->getAll()) { + if (auto c = dynamic_cast(p->implementation())) { + func(c); + } + } +} + +INSTANTIATEPLUGINOF(LifeCycle); + diff --git a/project2/common/lifeCycle.h b/project2/common/lifeCycle.h new file mode 100644 index 0000000..2a6b5b2 --- /dev/null +++ b/project2/common/lifeCycle.h @@ -0,0 +1,25 @@ +#ifndef LIFECYCLE_H +#define LIFECYCLE_H + +#include +#include + +/// Helper for loading and maintaining Project2 components +class LifeCycle : public virtual AdHoc::AbstractPluginImplementation { + public: + virtual ~LifeCycle() = 0; + + virtual void onBegin(); // App engine start up (before settings are processed) + virtual void onBefore(); // Before the app engine processes a request (after settings are processed) + virtual void onIdle(); // When the app engine goes idle + virtual void onIteration(); // When the app engine has completed an iteration + virtual void onPeriodic(); // When the app engine feels like it + virtual void onConfigLoad(); // When the environment reloads the configuration + virtual bool cacheable() const { return true; } // The component can be cached for next run + + static void onAllComponents(const boost::function & func); +}; +typedef AdHoc::PluginOf LifeCycleComponentPlugin; + +#endif + diff --git a/project2/common/logger.h b/project2/common/logger.h index cc4409f..9b7d868 100644 --- a/project2/common/logger.h +++ b/project2/common/logger.h @@ -8,9 +8,9 @@ #include #include #include "intrusivePtrBase.h" -#include "componentLoader.h" #include #include +#include "lifeCycle.h" /// Base class for classes providing a logging facility class LogDriverBase : public virtual IntrusivePtrBase { @@ -69,7 +69,7 @@ class Logger { }; template -class LogDriverFactoryImpl : public LogDriverFactory, public ComponentLoader { +class LogDriverFactoryImpl : public LogDriverFactory, public LifeCycle { public: LogDriverFactoryImpl() : level(LoggerType::level) diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index f10ff4f..56e983c 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -1,7 +1,6 @@ #include "optionsSource.h" #include "logger.h" #include -#include class DefaultConfigConsumer : public ConfigConsumer { public: @@ -43,7 +42,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) } } } - Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onConfigLoad, _1)); loadedTime = boost::posix_time::microsec_clock::universal_time(); Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); @@ -59,7 +58,7 @@ OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSour DefaultConfigConsumer dcc; opts->loadInto(dcc, platform); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onConfigLoad, _1)); loadedTime = boost::posix_time::microsec_clock::universal_time(); Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); diff --git a/project2/common/plugable.cpp b/project2/common/plugable.cpp deleted file mode 100644 index deb7910..0000000 --- a/project2/common/plugable.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "plugable.h" -#include "componentLoader.h" -#include - -void -Plugable::onAllComponents(const boost::function & func) -{ - for(auto p : AdHoc::PluginManager::getDefault()->getAll()) { - if (auto c = dynamic_cast(p->implementation())) { - func(c); - } - } -} - diff --git a/project2/common/plugable.h b/project2/common/plugable.h deleted file mode 100644 index 8e3889f..0000000 --- a/project2/common/plugable.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PLUGABLE_H -#define PLUGABLE_H - -#include - -class ComponentLoader; - -class Plugable { - public: - static void onAllComponents(const boost::function & func); -}; - -#endif - diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index 17ebd19..e3abd86 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -8,9 +8,6 @@ #include "appInstance.h" #include -typedef std::map > ElementLoaderMap; -typedef std::set > ComponentLoaderSet; - LoaderBase::LoaderBase() : recursive(true) { diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index 032d6c7..fed7cef 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -12,7 +12,6 @@ #include #include -class ComponentLoader; class CommonObjects; class Storer; class ScriptReader; diff --git a/project2/common/scriptStorage.h b/project2/common/scriptStorage.h index 9947633..c4155f2 100644 --- a/project2/common/scriptStorage.h +++ b/project2/common/scriptStorage.h @@ -5,6 +5,7 @@ #include "scriptLoader.h" #include "exceptions.h" #include "scripts.h" +#include "lifeCycle.h" #include #include #include @@ -54,7 +55,7 @@ class StorerBase : public Storer { } bool cacheable(ScriptNodePtr p) const { auto f = AdHoc::PluginManager::getDefault()->get(p->get_name()); - if (auto c = dynamic_cast(f->implementation())) { + if (auto c = dynamic_cast(f->implementation())) { return c->cacheable(); } return true; diff --git a/project2/common/scripts.h b/project2/common/scripts.h index e3fab9c..2442558 100644 --- a/project2/common/scripts.h +++ b/project2/common/scripts.h @@ -11,7 +11,6 @@ #include "exceptions.h" #include "variableType.h" #include "options.h" -#include "componentLoader.h" #include SimpleMessageException(ValueNotFound); diff --git a/project2/compression/decompressStream.cpp b/project2/compression/decompressStream.cpp index 68f8869..7d4023b 100644 --- a/project2/compression/decompressStream.cpp +++ b/project2/compression/decompressStream.cpp @@ -1,5 +1,4 @@ #include "stream.h" -#include "componentLoader.h" #include "decompressor.h" #include "scripts.h" #include "variables.h" diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 41bf14c..df7010f 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -12,7 +12,6 @@ #include #include #include -#include StaticMessageException(InvalidScriptName, "Script name should be group/name"); SimpleMessageException(UnknownPlatformAlias); @@ -107,14 +106,14 @@ void ConsoleApplicationEngine::process() { for (const auto & todo : todolist) { - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBefore, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBefore, _1)); Logger()->messagebf(LOG_DEBUG, "%s: Beginning script '%s/%s'", __FUNCTION__, todo.get<0>(), todo.get<1>()); Logger()->messagef(LOG_DEBUG, "%s: Processing file", __FUNCTION__); process(ScriptReader::resolveScript(todo.get<0>(), todo.get<1>(), false)); Logger()->messagef(LOG_DEBUG, "%s: Complete", __FUNCTION__); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIteration, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIteration, _1)); } } diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index 03771f0..3c86600 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -2,21 +2,20 @@ #include #include "claOptions.h" #include "consoleAppEngine.h" -#include int main(int argc, char ** argv) { AdHoc::PluginManager::getDefault()->add( new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript), "", __FILE__, __LINE__); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBegin, _1)); ConsoleApplicationEngine app; OptionsSource::loadSources([] { return ConsoleApplicationEngine::reqPlatform;} ); app.process(); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onPeriodic, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIdle, _1)); } diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp index 6d07201..27dff10 100644 --- a/project2/daemon/p2daemonAppEngine.cpp +++ b/project2/daemon/p2daemonAppEngine.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "pidfile.h" #include "tempPrivs.h" @@ -124,7 +123,7 @@ bool DaemonAppEngine::periodicCallback() { Logger()->messagebf(LOG_DEBUG, "%s: firing component periodics.", __PRETTY_FUNCTION__); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onPeriodic, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onPeriodic, _1)); return true; } diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp index e65f941..21eb748 100644 --- a/project2/daemon/p2daemonMain.cpp +++ b/project2/daemon/p2daemonMain.cpp @@ -5,7 +5,6 @@ #include #include #include -#include SimpleMessageException(UnsupportedArguments); @@ -45,7 +44,7 @@ daemonize() int main(int argc, char ** argv) { - Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onBegin, _1)); AdHoc::PluginManager::getDefault()->add( new CommandLineArguments(argc, argv, [](const char * a) { throw UnsupportedArguments(a); }), "_2", __FILE__, __LINE__); @@ -57,6 +56,6 @@ main(int argc, char ** argv) } dae.process(); - Plugable::onAllComponents(boost::bind(&ComponentLoader::onIdle, _1)); + LifeCycle::onAllComponents(boost::bind(&LifeCycle::onIdle, _1)); } diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 87d1223..4066058 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -247,7 +247,7 @@ DECLARE_OPTIONS(FilePresenterCache, "File Presenter Cache options") "The name of the component used to provide a unique request ID") END_OPTIONS(FilePresenterCache) -class FilePresenterCacheLoader : public ComponentLoader { +class FilePresenterCacheLoader : public LifeCycle { public: FilePresenterCacheLoader() { diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index cf1c446..e6769b5 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -24,7 +24,7 @@ std::string IceDaemon::viewRoot; std::string IceDaemon::taskRoot; IceBase::Libs IceDaemon::libs; -class IceDaemonFactory : public DaemonFactory::For, public ComponentLoader { +class IceDaemonFactory : public DaemonFactory::For, public LifeCycle { public: void onConfigLoad() override { IceBase::FinaliseLoad(IceDaemon::libs); diff --git a/project2/ice/iceDataSource.cpp b/project2/ice/iceDataSource.cpp index 734eedc..8c15173 100644 --- a/project2/ice/iceDataSource.cpp +++ b/project2/ice/iceDataSource.cpp @@ -44,7 +44,7 @@ IceDataSource::ClearSlice() libs.clear(); } -class IceDataSourceLoader : public DataSourceFactory::For, public ComponentLoader { +class IceDataSourceLoader : public DataSourceFactory::For, public LifeCycle { public: void onConfigLoad() override { IceBase::FinaliseLoad(IceDataSource::libs); diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 9b295d3..aa5bee4 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -8,7 +8,7 @@ #define LOCK(l) std::lock_guard _lock##l(l) /// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections -class RdbmsDataSourceLoader : public ComponentLoader { +class RdbmsDataSourceLoader : public LifeCycle { public: void onIdle() override { diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index 6e5bd20..24a6b80 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -264,7 +264,7 @@ std::string SqlCache::DataSource; std::string SqlCache::HeaderTable; time_t SqlCache::CacheLife; -class CustomSqlCacheLoader : public RowSetCacheFactory::For, public ComponentLoader { +class CustomSqlCacheLoader : public RowSetCacheFactory::For, public LifeCycle { public: void onIdle() override { diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index c92fe85..403e91a 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -10,7 +10,7 @@ #include "options.h" #include "logger.h" -class CustomSessionContainerFactoryXml : public SessionContainerFactory::For, public ComponentLoader { +class CustomSessionContainerFactoryXml : public SessionContainerFactory::For, public LifeCycle { public: void onPeriodic() override { diff --git a/project2/xml/xmlCache.cpp b/project2/xml/xmlCache.cpp index 6104730..40adec9 100644 --- a/project2/xml/xmlCache.cpp +++ b/project2/xml/xmlCache.cpp @@ -84,7 +84,7 @@ boost::filesystem::path XmlCache::Store; std::string XmlCache::FileName; time_t XmlCache::CacheLife; -class CustomXmlCacheFactory : public AdHoc::Factory::For, public ComponentLoader { +class CustomXmlCacheFactory : public AdHoc::Factory::For, public LifeCycle { public: void onIdle() override { diff --git a/project2/xml/xmlDocumentCache.cpp b/project2/xml/xmlDocumentCache.cpp index f37924d..98e4993 100644 --- a/project2/xml/xmlDocumentCache.cpp +++ b/project2/xml/xmlDocumentCache.cpp @@ -58,7 +58,7 @@ XmlDocumentCache::queue(const Glib::ustring & url, const char *, ExecContext *) } } -class XmlDocumentCacheClearer : public ComponentLoader { +class XmlDocumentCacheClearer : public LifeCycle { public: typedef bool KeyType; @@ -69,5 +69,5 @@ class XmlDocumentCacheClearer : public ComponentLoader { Logger()->messagef(LOG_DEBUG, "%s: Cleared XML document cache", __PRETTY_FUNCTION__); } }; -NAMEDPLUGIN("XmlDocumentCacheClearer", XmlDocumentCacheClearer, ComponentLoader); +NAMEDPLUGIN("XmlDocumentCacheClearer", XmlDocumentCacheClearer, LifeCycle); -- cgit v1.2.3 From 5116ce6918721ae244c810a9144ed42e1560ac19 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Oct 2015 21:15:43 +0100 Subject: Rename some of the things badly named Loader --- project2/basics/caches/memoryCache.cpp | 10 +++++----- project2/cgi/cgiContentNegotiate.cpp | 10 +++++----- project2/common/variables/config.cpp | 8 ++++---- project2/files/presenterCache.cpp | 6 +++--- project2/ice/iceDataSource.cpp | 4 ++-- project2/mail/sendmailTask.h | 1 - project2/sql/rdbmsDataSource.cpp | 4 ++-- project2/sql/rdbmsDataSource.h | 2 +- project2/sql/sqlCache.cpp | 6 +++--- project2/xml/xmlScriptParser.cpp | 4 ++-- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/project2/basics/caches/memoryCache.cpp b/project2/basics/caches/memoryCache.cpp index 0f3ddf6..8aaa019 100644 --- a/project2/basics/caches/memoryCache.cpp +++ b/project2/basics/caches/memoryCache.cpp @@ -138,14 +138,14 @@ class MemoryCache : public RowSetCache { CachedRowSetPtr cur; - friend class CustomMemoryCacheLoader; + friend class CustomMemoryCacheFactory; static time_t CacheLife; static CacheStore Store; }; time_t MemoryCache::CacheLife; MemoryCache::CacheStore MemoryCache::Store; -class CustomMemoryCacheLoader : public RowSetCacheFactory::For, public LifeCycle { +class CustomMemoryCacheFactory : public RowSetCacheFactory::For, public LifeCycle { public: void onPeriodic() override { typedef MemoryCache::CacheStore::index::type::iterator iter; @@ -156,10 +156,10 @@ class CustomMemoryCacheLoader : public RowSetCacheFactory::For, pub INITOPTIONS; }; -NAMEDPLUGIN("memorycache", CustomMemoryCacheLoader, RowSetCacheFactory); +NAMEDPLUGIN("memorycache", CustomMemoryCacheFactory, RowSetCacheFactory); -DECLARE_OPTIONS(CustomMemoryCacheLoader, "Memory Cache options") +DECLARE_OPTIONS(CustomMemoryCacheFactory, "Memory Cache options") ("cache.memory.life", Options::value(&MemoryCache::CacheLife, 3600), "The age of cache entries after which they are removed (seconds)") -END_OPTIONS(CustomMemoryCacheLoader); +END_OPTIONS(CustomMemoryCacheFactory); diff --git a/project2/cgi/cgiContentNegotiate.cpp b/project2/cgi/cgiContentNegotiate.cpp index 929159f..0d1bbaf 100644 --- a/project2/cgi/cgiContentNegotiate.cpp +++ b/project2/cgi/cgiContentNegotiate.cpp @@ -3,7 +3,7 @@ #include #include -class ContentNegotiateLoader : public PresenterFactory { +class ContentNegotiateFactory : public PresenterFactory { public: MultiRowSetPresenter * create(const ScriptNodePtr & s, const ObjectSource & os, ExecContext * const & ec) const { @@ -44,14 +44,14 @@ class ContentNegotiateLoader : public PresenterFactory { bool cacheable() const { return false; } }; -ContentNegotiateLoader::MappedTypes ContentNegotiateLoader::mappedTypes; +ContentNegotiateFactory::MappedTypes ContentNegotiateFactory::mappedTypes; -NAMEDPLUGIN("contentnegotiate", ContentNegotiateLoader, PresenterFactory); +NAMEDPLUGIN("contentnegotiate", ContentNegotiateFactory, PresenterFactory); -DECLARE_OPTIONS(ContentNegotiateLoader, "Content negotiation options") +DECLARE_OPTIONS(ContentNegotiateFactory, "Content negotiation options") ("cgi.contentnegotiation.mappedtype", Options::functions( [](const VariableType & v) { mappedTypes.push_back(new MappedType(v)); }, boost::bind(&MappedTypes::clear, &mappedTypes)), "mimetype=presenter list of types to negotiate") -END_OPTIONS(ContentNegotiateLoader) +END_OPTIONS(ContentNegotiateFactory) diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp index 1696f43..9ac3dd0 100644 --- a/project2/common/variables/config.cpp +++ b/project2/common/variables/config.cpp @@ -32,7 +32,7 @@ class VariableConfig : public VariableImplDyn { const Glib::ustring name; }; -class VariableConfigLoader : public VariableFactory::For { +class VariableConfigFactory : public VariableFactory::For { public: class AppSettings : public Options::Option { public: @@ -68,14 +68,14 @@ class VariableConfigLoader : public VariableFactory::For { return "Load settings into the client application"; } }; - VariableConfigLoader() : + VariableConfigFactory() : opts(new Options("Variables - ModConfig options")) { (*opts)(new AppSettings()); AdHoc::PluginManager::getDefault()->add(opts, typeid(AppSettings).name(), __FILE__, __LINE__); } - ~VariableConfigLoader() + ~VariableConfigFactory() { AdHoc::PluginManager::getDefault()->remove(typeid(AppSettings).name()); } @@ -88,5 +88,5 @@ class VariableConfigLoader : public VariableFactory::For { Options * opts; }; -NAMEDPLUGIN("config", VariableConfigLoader, VariableFactory); +NAMEDPLUGIN("config", VariableConfigFactory, VariableFactory); diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp index 4066058..9651c20 100644 --- a/project2/files/presenterCache.cpp +++ b/project2/files/presenterCache.cpp @@ -228,7 +228,7 @@ class FilePresenterCache : public PresenterCache { static std::string FileName; static std::string Provider; static time_t CacheLife; - friend class FilePresenterCacheLoader; + friend class FilePresenterCacheFactory; }; FilePresenterCache::OpenCaches FilePresenterCache::openCaches; boost::filesystem::path FilePresenterCache::Store; @@ -247,9 +247,9 @@ DECLARE_OPTIONS(FilePresenterCache, "File Presenter Cache options") "The name of the component used to provide a unique request ID") END_OPTIONS(FilePresenterCache) -class FilePresenterCacheLoader : public LifeCycle { +class FilePresenterCacheFactory : public LifeCycle { public: - FilePresenterCacheLoader() + FilePresenterCacheFactory() { gcry_check_version(GCRYPT_VERSION); } diff --git a/project2/ice/iceDataSource.cpp b/project2/ice/iceDataSource.cpp index 8c15173..cce2dd8 100644 --- a/project2/ice/iceDataSource.cpp +++ b/project2/ice/iceDataSource.cpp @@ -44,12 +44,12 @@ IceDataSource::ClearSlice() libs.clear(); } -class IceDataSourceLoader : public DataSourceFactory::For, public LifeCycle { +class IceDataSourceFactory : public DataSourceFactory::For, public LifeCycle { public: void onConfigLoad() override { IceBase::FinaliseLoad(IceDataSource::libs); } }; -NAMEDPLUGIN("icedatasource", IceDataSourceLoader, DataSourceFactory); +NAMEDPLUGIN("icedatasource", IceDataSourceFactory, DataSourceFactory); diff --git a/project2/mail/sendmailTask.h b/project2/mail/sendmailTask.h index 035fe2b..e09b871 100644 --- a/project2/mail/sendmailTask.h +++ b/project2/mail/sendmailTask.h @@ -49,7 +49,6 @@ class SendMailTask : public Task { PresenterPtr createDefaultPresenter(ScriptNodePtr n) const; // Configurables - friend class CustomSendMailTaskLoader; friend class TransformWritableContentToEmail; static std::string defaultMailServer; static std::string defaultMailEncoding; diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index aa5bee4..46e97a8 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -7,8 +7,8 @@ #define LOCK(l) std::lock_guard _lock##l(l) -/// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections -class RdbmsDataSourceLoader : public LifeCycle { +/// Life cycle component for handling closure of persistent DB connections +class RdbmsDataSourceFactory : public LifeCycle { public: void onIdle() override { diff --git a/project2/sql/rdbmsDataSource.h b/project2/sql/rdbmsDataSource.h index 4b7763f..979cec6 100644 --- a/project2/sql/rdbmsDataSource.h +++ b/project2/sql/rdbmsDataSource.h @@ -94,7 +94,7 @@ class RdbmsDataSource : public DataSource { typedef std::set ChangedDSNs; static ChangedDSNs changedDSNs; - friend class RdbmsDataSourceLoader; + friend class RdbmsDataSourceFactory; }; #endif diff --git a/project2/sql/sqlCache.cpp b/project2/sql/sqlCache.cpp index 24a6b80..d20a8fc 100644 --- a/project2/sql/sqlCache.cpp +++ b/project2/sql/sqlCache.cpp @@ -253,7 +253,7 @@ class SqlCache : public RowSetCache { INITOPTIONS; private: - friend class CustomSqlCacheLoader; + friend class CustomSqlCacheFactory; const RdbmsDataSource * db; static std::string DataSource; static std::string HeaderTable; @@ -264,7 +264,7 @@ std::string SqlCache::DataSource; std::string SqlCache::HeaderTable; time_t SqlCache::CacheLife; -class CustomSqlCacheLoader : public RowSetCacheFactory::For, public LifeCycle { +class CustomSqlCacheFactory : public RowSetCacheFactory::For, public LifeCycle { public: void onIdle() override { @@ -284,7 +284,7 @@ class CustomSqlCacheLoader : public RowSetCacheFactory::For, public Li } } }; -NAMEDPLUGIN("sqlcache", CustomSqlCacheLoader, RowSetCacheFactory); +NAMEDPLUGIN("sqlcache", CustomSqlCacheFactory, RowSetCacheFactory); DECLARE_OPTIONS(SqlCache, "SQL Cache options") ("cache.sql.dataSource", Options::value(&DataSource), diff --git a/project2/xml/xmlScriptParser.cpp b/project2/xml/xmlScriptParser.cpp index c86f8c0..33b464e 100644 --- a/project2/xml/xmlScriptParser.cpp +++ b/project2/xml/xmlScriptParser.cpp @@ -90,7 +90,7 @@ XmlScriptParser::isCurrent() const return true; } -class XmlScriptReaderLoader : public ScriptReaderFactory { +class XmlScriptReaderFactory : public ScriptReaderFactory { public: XmlScriptParser * create(const std::string & group, const std::string & name) const { boost::filesystem::path script(boost::filesystem::path(group) / (name + ".xml")); @@ -248,5 +248,5 @@ XmlScriptNode::composeWithCallbacks(const LiteralCallback & lcb, const NodeCallb } } -NAMEDPLUGIN("xmlScriptReader", XmlScriptReaderLoader, ScriptReaderFactory); +NAMEDPLUGIN("xmlScriptReader", XmlScriptReaderFactory, ScriptReaderFactory); -- cgit v1.2.3 From 67451c1f7d64ab82e0e92f199d7883833cc07d4d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 1 Oct 2015 21:38:29 +0100 Subject: Big tidy up of loggers and logger factories --- project2/basics/loggers/consoleLog.cpp | 6 ++--- project2/basics/loggers/syslogLog.cpp | 6 ++--- project2/common/logger.cpp | 13 +-------- project2/common/logger.h | 49 +++------------------------------- project2/common/loggerFactory.cpp | 14 ++++++++++ project2/common/loggerFactory.h | 38 ++++++++++++++++++++++++++ project2/common/loggerFactory.impl.h | 43 +++++++++++++++++++++++++++++ project2/files/fileLog.cpp | 6 ++--- project2/ut/butf_logger.cpp | 6 ++--- 9 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 project2/common/loggerFactory.cpp create mode 100644 project2/common/loggerFactory.h create mode 100644 project2/common/loggerFactory.impl.h diff --git a/project2/basics/loggers/consoleLog.cpp b/project2/basics/loggers/consoleLog.cpp index de45245..a88e6b2 100644 --- a/project2/basics/loggers/consoleLog.cpp +++ b/project2/basics/loggers/consoleLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include +#include /// Logger that writes to the console class ConsoleLogDriver : public LogDriverBase { @@ -25,5 +25,5 @@ END_OPTIONS(ConsoleLogDriver); int ConsoleLogDriver::level; -DECLARE_LOGGER_LOADER("console", ConsoleLogDriver); +DECLARE_LOGGER("console", ConsoleLogDriver); diff --git a/project2/basics/loggers/syslogLog.cpp b/project2/basics/loggers/syslogLog.cpp index 8e58326..cb026c6 100644 --- a/project2/basics/loggers/syslogLog.cpp +++ b/project2/basics/loggers/syslogLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include +#include /// Logger that writes to syslog class SyslogLogDriver : public LogDriverBase { @@ -35,5 +35,5 @@ END_OPTIONS(SyslogLogDriver); int SyslogLogDriver::level; std::string SyslogLogDriver::ident; -DECLARE_LOGGER_LOADER("syslog", SyslogLogDriver); +DECLARE_LOGGER("syslog", SyslogLogDriver); diff --git a/project2/common/logger.cpp b/project2/common/logger.cpp index 64df516..f21bd40 100644 --- a/project2/common/logger.cpp +++ b/project2/common/logger.cpp @@ -2,7 +2,7 @@ #define SYSLOG_NAMES 1 // Enables the definition of names in syslog.h #include "logger.h" -#include +#include "loggerFactory.h" Log Logger::log; @@ -94,14 +94,3 @@ Logger::operator->() const return &log; } -LogDriverBase::LogDriverBase() -{ -} - -LogDriverBase::~LogDriverBase() -{ -} - -template class AdHoc::Factory; -INSTANTIATEPLUGINOF(LogDriverFactory) - diff --git a/project2/common/logger.h b/project2/common/logger.h index 9b7d868..8d8b6de 100644 --- a/project2/common/logger.h +++ b/project2/common/logger.h @@ -3,29 +3,15 @@ #include #include -#include #include // Pulled in for easy client lookups of LOG_* priorties #include -#include +#include #include "intrusivePtrBase.h" -#include #include #include "lifeCycle.h" -/// Base class for classes providing a logging facility -class LogDriverBase : public virtual IntrusivePtrBase { - public: - LogDriverBase(); - virtual ~LogDriverBase(); - - virtual void message(int priority, const char * msg) const = 0; -}; - -class LogDriverFactory : public AdHoc::Factory { - public: - virtual int loggerLevel() const = 0; -}; - +class LogDriverBase; +class LogDriverFactory; class Log { public: typedef boost::intrusive_ptr LogDriverBasePtr; @@ -68,34 +54,5 @@ class Logger { static Log log; }; -template -class LogDriverFactoryImpl : public LogDriverFactory, public LifeCycle { - public: - LogDriverFactoryImpl() : - level(LoggerType::level) - { - } - virtual void onConfigLoad() override { - Logger()->setLoggerAt(this, level); - if (level == -1) { - instance.reset(); - } - } - inline LoggerType * create() const { - if (!instance) { - instance = new LoggerType(); - } - return instance.get(); - } - int loggerLevel() const { - return level; - } - const int & level; - private: - mutable boost::intrusive_ptr instance; -}; -#define DECLARE_LOGGER_LOADER(N, T) \ - NAMEDPLUGIN(N, LogDriverFactoryImpl, LogDriverFactory) - #endif diff --git a/project2/common/loggerFactory.cpp b/project2/common/loggerFactory.cpp new file mode 100644 index 0000000..b1d75d1 --- /dev/null +++ b/project2/common/loggerFactory.cpp @@ -0,0 +1,14 @@ +#include "loggerFactory.h" +#include + +LogDriverBase::LogDriverBase() +{ +} + +LogDriverBase::~LogDriverBase() +{ +} + +template class AdHoc::Factory; +INSTANTIATEPLUGINOF(LogDriverFactory) + diff --git a/project2/common/loggerFactory.h b/project2/common/loggerFactory.h new file mode 100644 index 0000000..056f5e3 --- /dev/null +++ b/project2/common/loggerFactory.h @@ -0,0 +1,38 @@ +#ifndef LOGGERFACTORY_H +#define LOGGERFACTORY_H + +#include +#include "lifeCycle.h" +#include "intrusivePtrBase.h" +#include "logger.h" + +/// Base class for classes providing a logging facility +class LogDriverBase : public virtual IntrusivePtrBase { + public: + LogDriverBase(); + virtual ~LogDriverBase(); + + virtual void message(int priority, const char * msg) const = 0; +}; + +class LogDriverFactory : public AdHoc::Factory { + public: + virtual int loggerLevel() const = 0; +}; + +template +class LogDriverFactoryImpl : public LogDriverFactory, public LifeCycle { + public: + LogDriverFactoryImpl(); + + virtual void onConfigLoad() override; + inline LoggerType * create() const override; + int loggerLevel() const override; + + const int & level; + private: + mutable boost::intrusive_ptr instance; +}; + +#endif + diff --git a/project2/common/loggerFactory.impl.h b/project2/common/loggerFactory.impl.h new file mode 100644 index 0000000..61711fd --- /dev/null +++ b/project2/common/loggerFactory.impl.h @@ -0,0 +1,43 @@ +#ifndef LOGGERFACTORY_IMPL_H +#define LOGGERFACTORY_IMPL_H + +#include "loggerFactory.h" + +template +LogDriverFactoryImpl::LogDriverFactoryImpl() : + level(T::level) +{ +} + +template +void +LogDriverFactoryImpl::onConfigLoad() +{ + Logger()->setLoggerAt(this, level); + if (level == -1) { + instance.reset(); + } +} + +template +T * +LogDriverFactoryImpl::create() const +{ + if (!instance) { + instance = new T(); + } + return instance.get(); +} + +template +int +LogDriverFactoryImpl::loggerLevel() const +{ + return level; +} + +#define DECLARE_LOGGER(N, T) \ + NAMEDPLUGIN(N, LogDriverFactoryImpl, LogDriverFactory) + +#endif + diff --git a/project2/files/fileLog.cpp b/project2/files/fileLog.cpp index 078e00b..8a56f6d 100644 --- a/project2/files/fileLog.cpp +++ b/project2/files/fileLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include +#include /// Logger that writes to a file class FileLogDriver : public LogDriverBase { @@ -47,5 +47,5 @@ int FileLogDriver::level; std::string FileLogDriver::path; std::string FileLogDriver::openmode; -DECLARE_LOGGER_LOADER("file", FileLogDriver); +DECLARE_LOGGER("file", FileLogDriver); diff --git a/project2/ut/butf_logger.cpp b/project2/ut/butf_logger.cpp index c5f45b4..42afd41 100644 --- a/project2/ut/butf_logger.cpp +++ b/project2/ut/butf_logger.cpp @@ -1,6 +1,6 @@ #include -#include "logger.h" -#include "options.h" +#include +#include /// Logger that writes Boost Unit Test Framework messages class BoostUTFLogDriver : public LogDriverBase { @@ -17,5 +17,5 @@ class BoostUTFLogDriver : public LogDriverBase { int BoostUTFLogDriver::level = LOG_DEBUG; -DECLARE_LOGGER_LOADER("boostutf", BoostUTFLogDriver); +DECLARE_LOGGER("boostutf", BoostUTFLogDriver); -- cgit v1.2.3