From 791e4c53cd04aeae6470b493d2081674c1ad4167 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 3 Jan 2016 21:19:42 +0000 Subject: Restructure files into sensible subfolders --- icetray/Jamfile.jam | 52 ++-------------------- icetray/abstractCachingDatabaseClient.cpp | 18 -------- icetray/abstractCachingDatabaseClient.h | 54 ----------------------- icetray/abstractDatabaseClient.cpp | 28 ------------ icetray/abstractDatabaseClient.h | 43 ------------------ icetray/database.h | 13 ------ icetray/defaultPool.cpp | 16 ------- icetray/defaultPool.h | 15 ------- icetray/dryice.cpp | 49 -------------------- icetray/dryice.h | 32 -------------- icetray/dryice/Jamfile.jam | 22 +++++++++ icetray/dryice/dryice.cpp | 49 ++++++++++++++++++++ icetray/dryice/dryice.h | 32 ++++++++++++++ icetray/dryice/mockPool.cpp | 21 +++++++++ icetray/dryice/mockPool.h | 20 +++++++++ icetray/embed.sql.cpp.m4 | 7 --- icetray/embed.sql.h.m4 | 15 ------- icetray/icetray.jam | 34 -------------- icetray/icetray/Jamfile.jam | 31 +++++++++++++ icetray/icetray/abstractCachingDatabaseClient.cpp | 18 ++++++++ icetray/icetray/abstractCachingDatabaseClient.h | 54 +++++++++++++++++++++++ icetray/icetray/abstractDatabaseClient.cpp | 28 ++++++++++++ icetray/icetray/abstractDatabaseClient.h | 43 ++++++++++++++++++ icetray/icetray/database.h | 13 ++++++ icetray/icetray/defaultPool.cpp | 16 +++++++ icetray/icetray/defaultPool.h | 15 +++++++ icetray/icetray/icetrayService.cpp | 40 +++++++++++++++++ icetray/icetray/icetrayService.h | 28 ++++++++++++ icetray/icetrayService.cpp | 40 ----------------- icetray/icetrayService.h | 28 ------------ icetray/mockPool.cpp | 21 --------- icetray/mockPool.h | 20 --------- icetray/tool/Jamfile.jam | 4 ++ icetray/tool/embed.sql.cpp.m4 | 7 +++ icetray/tool/embed.sql.h.m4 | 15 +++++++ icetray/tool/icetray.jam | 34 ++++++++++++++ icetray/unittests/Jamfile.jam | 2 +- 37 files changed, 494 insertions(+), 483 deletions(-) delete mode 100644 icetray/abstractCachingDatabaseClient.cpp delete mode 100644 icetray/abstractCachingDatabaseClient.h delete mode 100644 icetray/abstractDatabaseClient.cpp delete mode 100644 icetray/abstractDatabaseClient.h delete mode 100644 icetray/database.h delete mode 100644 icetray/defaultPool.cpp delete mode 100644 icetray/defaultPool.h delete mode 100644 icetray/dryice.cpp delete mode 100644 icetray/dryice.h create mode 100644 icetray/dryice/Jamfile.jam create mode 100644 icetray/dryice/dryice.cpp create mode 100644 icetray/dryice/dryice.h create mode 100644 icetray/dryice/mockPool.cpp create mode 100644 icetray/dryice/mockPool.h delete mode 100644 icetray/embed.sql.cpp.m4 delete mode 100644 icetray/embed.sql.h.m4 delete mode 100644 icetray/icetray.jam create mode 100644 icetray/icetray/Jamfile.jam create mode 100644 icetray/icetray/abstractCachingDatabaseClient.cpp create mode 100644 icetray/icetray/abstractCachingDatabaseClient.h create mode 100644 icetray/icetray/abstractDatabaseClient.cpp create mode 100644 icetray/icetray/abstractDatabaseClient.h create mode 100644 icetray/icetray/database.h create mode 100644 icetray/icetray/defaultPool.cpp create mode 100644 icetray/icetray/defaultPool.h create mode 100644 icetray/icetray/icetrayService.cpp create mode 100644 icetray/icetray/icetrayService.h delete mode 100644 icetray/icetrayService.cpp delete mode 100644 icetray/icetrayService.h delete mode 100644 icetray/mockPool.cpp delete mode 100644 icetray/mockPool.h create mode 100644 icetray/tool/Jamfile.jam create mode 100644 icetray/tool/embed.sql.cpp.m4 create mode 100644 icetray/tool/embed.sql.h.m4 create mode 100644 icetray/tool/icetray.jam diff --git a/icetray/Jamfile.jam b/icetray/Jamfile.jam index 9058895..f499586 100644 --- a/icetray/Jamfile.jam +++ b/icetray/Jamfile.jam @@ -13,53 +13,7 @@ lib boost_system ; lib boost_thread ; build-project unittests ; - -lib icetray : - abstractDatabaseClient.cpp - abstractCachingDatabaseClient.cpp - defaultPool.cpp - icetrayService.cpp - : - adhocutil - dbppcore - Ice - IceUtil - IceBox - pthread - slicer - slicer-db - boost_system - boost_thread - ..//glibmm - -fvisibility=hidden - : : - . - dbppcore - adhocutil - slicer - slicer-db - boost_thread - ; - -lib dryice : - dryice.cpp - mockPool.cpp - : - adhocutil - icetray - Ice - IceUtil - IceBox - pthread - boost_system - boost_thread - dl - -fvisibility=hidden - : : - . - ; - -package.install install-main : . : : icetray : abstractDatabaseClient.h icetrayService.h ; -package.install-data install-tools : boost-build/tools : icetray.jam [ glob embed.*.m4 ] ; -package.install install-dryice : . : : dryice : dryice.h ; +build-project icetray ; +build-project dryice ; +build-project tool ; diff --git a/icetray/abstractCachingDatabaseClient.cpp b/icetray/abstractCachingDatabaseClient.cpp deleted file mode 100644 index 2c97ac6..0000000 --- a/icetray/abstractCachingDatabaseClient.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "abstractCachingDatabaseClient.h" -#include - -template DLL_PUBLIC void AdHoc::Cache::add(const IceTray::AbstractCachingDatabaseClient::CacheKey &, const IceTray::AbstractCachingDatabaseClient::CacheItem &, time_t); -template DLL_PUBLIC const IceTray::AbstractCachingDatabaseClient::CacheItem * AdHoc::Cache::get(const IceTray::AbstractCachingDatabaseClient::CacheKey &) const; - -namespace IceTray { - AbstractCachingDatabaseClient::AbstractCachingDatabaseClient(DatabasePoolPtr d) : - AbstractDatabaseClient(d) - { - } - - void - AbstractCachingDatabaseClient::keyPushParams(CacheKey &) - { - } -} - diff --git a/icetray/abstractCachingDatabaseClient.h b/icetray/abstractCachingDatabaseClient.h deleted file mode 100644 index bb1d070..0000000 --- a/icetray/abstractCachingDatabaseClient.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef ICETRAY_ABSTRACTCACHINGDATABASECLIENT_H -#define ICETRAY_ABSTRACTCACHINGDATABASECLIENT_H - -#include "abstractDatabaseClient.h" -#include -#include -#include - -namespace IceTray { - class DLL_PUBLIC AbstractCachingDatabaseClient : public AbstractDatabaseClient { - private: - typedef std::vector CacheKey; - typedef boost::shared_ptr CacheItem; - - public: - AbstractCachingDatabaseClient(boost::shared_ptr> d); - - template - inline - Domain - fetchCache(time_t cacheTime, const Params & ... params) - { - CacheKey key; - key.reserve(sizeof...(Params) + 2); - key.push_back(Sql::hash); - key.push_back(typeid(Domain).hash_code()); - keyPushParams(key, params...); - if (auto cached = cache.get(key)) { - auto d = boost::any_cast(cached->get()); - if (d) { - return *d; - } - } - auto d(fetch(params...)); - cache.add(key, CacheItem(new boost::any(d)), time(NULL) + cacheTime); - return d; - } - - private: - template - static void inline keyPushParams(CacheKey & k, const Param & p, const Params & ... params) - { - k.push_back(std::hash()(p)); - keyPushParams(k, params...); - } - - static void keyPushParams(CacheKey &); - - AdHoc::Cache cache; - }; -} - -#endif - diff --git a/icetray/abstractDatabaseClient.cpp b/icetray/abstractDatabaseClient.cpp deleted file mode 100644 index e5e3026..0000000 --- a/icetray/abstractDatabaseClient.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "abstractDatabaseClient.h" - -namespace IceTray { - AbstractDatabaseClient::AbstractDatabaseClient(DatabasePoolPtr d) : - db(d) - { - } - - template<> - void - AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const std::string & p) - { - cmd->bindParamS(o, p); - } - - template<> - void - AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const int & p) - { - cmd->bindParamI(o, p); - } - - void - AbstractDatabaseClient::bind(int, DB::Command *) - { - } -} - diff --git a/icetray/abstractDatabaseClient.h b/icetray/abstractDatabaseClient.h deleted file mode 100644 index aac9151..0000000 --- a/icetray/abstractDatabaseClient.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef ICETRAY_ABSTRACTDATABASECLIENT_H -#define ICETRAY_ABSTRACTDATABASECLIENT_H - -#include "database.h" -#include -#include -#include - -namespace IceTray { - class DLL_PUBLIC AbstractDatabaseClient { - public: - AbstractDatabaseClient(DatabasePoolPtr d); - - template - inline - Domain - fetch(const Params & ... params) - { - auto c = db->get(); - auto s = DB::SelectCommandPtr(c->newSelectCommand(Sql::sql)); - bind(0, s.get(), params...); - return Slicer::DeserializeAny(*s); - } - - private: - template - static void inline bind(int offset, DB::Command * cmd, const Param & p, const Params & ... params) - { - bind1(offset, cmd, p); - bind(offset + 1, cmd, params...); - } - - static void bind(int offset, DB::Command * cmd); - - template - static void bind1(int offset, DB::Command * cmd, const Param & p); - - DatabasePoolPtr db; - }; -} - -#endif - diff --git a/icetray/database.h b/icetray/database.h deleted file mode 100644 index 23ad7fe..0000000 --- a/icetray/database.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ICETRAY_DATABASE_H -#define ICETRAY_DATABASE_H - -#include -#include - -namespace IceTray { - typedef AdHoc::ResourcePool DatabasePool; - typedef boost::shared_ptr DatabasePoolPtr; -} - -#endif - diff --git a/icetray/defaultPool.cpp b/icetray/defaultPool.cpp deleted file mode 100644 index c3f7e50..0000000 --- a/icetray/defaultPool.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "defaultPool.h" -#include "icetrayService.h" - -namespace IceTray { - DefaultPool::DefaultPool(const std::string & name, const std::string & type, Ice::PropertiesPtr p) : - DB::ConnectionPool( - p->getPropertyAsIntWithDefault(name + ".Database.PoolMax", 10), - p->getPropertyAsIntWithDefault(name + ".Database.PoolKeep", 2), - p->getPropertyWithDefault(name + ".Database.Type", type), - p->getProperty(name + ".Database.ConnectionString")) - { - } - - FACTORY(DefaultPool, PoolProvider); -} - diff --git a/icetray/defaultPool.h b/icetray/defaultPool.h deleted file mode 100644 index 5b06ea2..0000000 --- a/icetray/defaultPool.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ICETRAY_DEFAULTPOOL_H -#define ICETRAY_DEFAULTPOOL_H - -#include -#include - -namespace IceTray { - class DefaultPool : public DB::ConnectionPool { - public: - DefaultPool(const std::string & name, const std::string & type, Ice::PropertiesPtr p); - }; -} - -#endif - diff --git a/icetray/dryice.cpp b/icetray/dryice.cpp deleted file mode 100644 index 50f85cb..0000000 --- a/icetray/dryice.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "dryice.h" -#include -#include -#include -#include - -namespace IceTray { - typedef IceBox::Service *(* SetupFunction)(Ice::CommunicatorPtr); - - DryIce::DryIce(const Ice::StringSeq & cmdline) - { - void * i = dlsym(NULL, "createIceTrayService"); - BOOST_VERIFY(i); - auto sf = (SetupFunction)i; - BOOST_VERIFY(sf); - Ice::StringSeq args; - Ice::InitializationData id; - id.properties = Ice::createProperties(); - id.properties->setProperty("DryIce.Endpoints", "tcp -p 9002"); - id.properties->setProperty("DryIce.PoolProvider", "MockPool"); - id.properties->parseCommandLineOptions("", cmdline); - ic = Ice::initialize(args, id); - s = sf(nullptr); - s->start("DryIce", ic, {}); - } - - DryIce::~DryIce() - { - if (s) { - s->stop(); - s = NULL; - } - if (ic) { - ic->destroy(); - ic = NULL; - } - } - - DryIceClient::DryIceClient() - { - ic = Ice::initialize(); - } - - DryIceClient::~DryIceClient() - { - ic->destroy(); - } -} - diff --git a/icetray/dryice.h b/icetray/dryice.h deleted file mode 100644 index f81a48c..0000000 --- a/icetray/dryice.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ICETRAY_TESTSETUP_H -#define ICETRAY_TESTSETUP_H - -#include -#include -#include - -namespace IceTray { - class DLL_PUBLIC DryIce { - public: - DryIce(const Ice::StringSeq & = Ice::StringSeq()); - DryIce(const DryIce &) = delete; - virtual ~DryIce(); - - void operator=(const DryIce &) = delete; - - protected: - Ice::CommunicatorPtr ic; - IceBox::ServicePtr s; - }; - - class DLL_PUBLIC DryIceClient { - public: - DryIceClient(); - virtual ~DryIceClient(); - - Ice::CommunicatorPtr ic; - }; -} - -#endif - diff --git a/icetray/dryice/Jamfile.jam b/icetray/dryice/Jamfile.jam new file mode 100644 index 0000000..3f8751b --- /dev/null +++ b/icetray/dryice/Jamfile.jam @@ -0,0 +1,22 @@ +import package ; + +lib dryice : + dryice.cpp + mockPool.cpp + : + ..//adhocutil + ../icetray//icetray + ..//Ice + ..//IceUtil + ..//IceBox + ..//pthread + ..//boost_system + ..//boost_thread + ..//dl + -fvisibility=hidden + : : + . + ; + +package.install install-dryice : . : : dryice : [ glob *.h : mockPool.h ] ; + diff --git a/icetray/dryice/dryice.cpp b/icetray/dryice/dryice.cpp new file mode 100644 index 0000000..50f85cb --- /dev/null +++ b/icetray/dryice/dryice.cpp @@ -0,0 +1,49 @@ +#include "dryice.h" +#include +#include +#include +#include + +namespace IceTray { + typedef IceBox::Service *(* SetupFunction)(Ice::CommunicatorPtr); + + DryIce::DryIce(const Ice::StringSeq & cmdline) + { + void * i = dlsym(NULL, "createIceTrayService"); + BOOST_VERIFY(i); + auto sf = (SetupFunction)i; + BOOST_VERIFY(sf); + Ice::StringSeq args; + Ice::InitializationData id; + id.properties = Ice::createProperties(); + id.properties->setProperty("DryIce.Endpoints", "tcp -p 9002"); + id.properties->setProperty("DryIce.PoolProvider", "MockPool"); + id.properties->parseCommandLineOptions("", cmdline); + ic = Ice::initialize(args, id); + s = sf(nullptr); + s->start("DryIce", ic, {}); + } + + DryIce::~DryIce() + { + if (s) { + s->stop(); + s = NULL; + } + if (ic) { + ic->destroy(); + ic = NULL; + } + } + + DryIceClient::DryIceClient() + { + ic = Ice::initialize(); + } + + DryIceClient::~DryIceClient() + { + ic->destroy(); + } +} + diff --git a/icetray/dryice/dryice.h b/icetray/dryice/dryice.h new file mode 100644 index 0000000..f81a48c --- /dev/null +++ b/icetray/dryice/dryice.h @@ -0,0 +1,32 @@ +#ifndef ICETRAY_TESTSETUP_H +#define ICETRAY_TESTSETUP_H + +#include +#include +#include + +namespace IceTray { + class DLL_PUBLIC DryIce { + public: + DryIce(const Ice::StringSeq & = Ice::StringSeq()); + DryIce(const DryIce &) = delete; + virtual ~DryIce(); + + void operator=(const DryIce &) = delete; + + protected: + Ice::CommunicatorPtr ic; + IceBox::ServicePtr s; + }; + + class DLL_PUBLIC DryIceClient { + public: + DryIceClient(); + virtual ~DryIceClient(); + + Ice::CommunicatorPtr ic; + }; +} + +#endif + diff --git a/icetray/dryice/mockPool.cpp b/icetray/dryice/mockPool.cpp new file mode 100644 index 0000000..43e7c0c --- /dev/null +++ b/icetray/dryice/mockPool.cpp @@ -0,0 +1,21 @@ +#include "mockPool.h" +#include "icetrayService.h" +#include + +namespace IceTray { + MockPool::MockPool(const std::string & name, const std::string &, Ice::PropertiesPtr p) : + DatabasePool( + p->getPropertyAsIntWithDefault(name + ".Database.PoolMax", 10), + p->getPropertyAsIntWithDefault(name + ".Database.PoolKeep", 2)), + name(name) + { + } + + DB::Connection * MockPool::createResource() const + { + return DB::MockDatabase::openConnectionTo(name); + } + + FACTORY(MockPool, PoolProvider); +}; + diff --git a/icetray/dryice/mockPool.h b/icetray/dryice/mockPool.h new file mode 100644 index 0000000..8936cb2 --- /dev/null +++ b/icetray/dryice/mockPool.h @@ -0,0 +1,20 @@ +#ifndef ICETRAY_MOCKPOOL_H +#define ICETRAY_MOCKPOOL_H + +#include "database.h" +#include +#include + +namespace IceTray { + class MockPool : public DatabasePool { + public: + MockPool(const std::string & name, const std::string &, Ice::PropertiesPtr p); + + DB::Connection * createResource() const override; + + const std::string name; + }; +} + +#endif + diff --git a/icetray/embed.sql.cpp.m4 b/icetray/embed.sql.cpp.m4 deleted file mode 100644 index 7043f78..0000000 --- a/icetray/embed.sql.cpp.m4 +++ /dev/null @@ -1,7 +0,0 @@ -changecom(`@@') -#include "NAME.sql.h" - -const std::string NAMESPACE::NAME::sql({ -patsubst(esyscmd(`xxd -p -c 12 ' SQL), `\(..\)', `0x\1, ')0x00}); -const std::size_t NAMESPACE::NAME::hash(std::hash()(sql)); - diff --git a/icetray/embed.sql.h.m4 b/icetray/embed.sql.h.m4 deleted file mode 100644 index fbabf62..0000000 --- a/icetray/embed.sql.h.m4 +++ /dev/null @@ -1,15 +0,0 @@ -define(`foreach',`ifelse(eval($#>2),1, - `pushdef(`$1',`$3')$2`'popdef(`$1') - `'ifelse(eval($#>3),1,`$0(`$1',`$2',shift(shift(shift($@))))')')') -define(NAMESPACEC,`patsubst(NAMESPACE,`::', `,')') -#include -#include - -foreach(`ns', `namespace ns { ', NAMESPACEC) - class NAME { - public: - static const std::string sql; - static const std::size_t hash; - }; -foreach(`ns', `}', NAMESPACEC) - diff --git a/icetray/icetray.jam b/icetray/icetray.jam deleted file mode 100644 index f999e2d..0000000 --- a/icetray/icetray.jam +++ /dev/null @@ -1,34 +0,0 @@ -import generators ; -import feature ; -import type ; -import path ; -import property ; -import project ; -import regex ; - -project.initialize $(__name__) ; -project icetray ; - -feature.feature icetray.sql.namespace : : free ; -type.register SQL : sql ; -generators.register-standard icetray.c++.sql : SQL : CPP(%.sql) H(%.sql) ; - -path-constant icetray-root : . ; - -rule icetray.c++.sql ( cpp h : sql : properties * ) -{ - local namespace = [ property.select icetray.sql.namespace : $(properties) ] ; - local relpath = [ path.relative-to . $(sql:D) ] ; - namespace = [ regex.replace $(namespace:G=)/$(relpath) "\\/\\." "" ] ; - namespace = [ regex.replace $(namespace) "\\/" "::" ] ; - NAMESPACE on $(<) = -DNAMESPACE=\"$(namespace)\" ; -} - -actions icetray.c++.sql -{ - m4 $(NAMESPACE) -DNAME="$(2:B)" -DSQL="$(2[1])" "$(icetray-root)/embed.sql.cpp.m4" > "$(1[1])" - m4 $(NAMESPACE) -DNAME="$(2:B)" "$(icetray-root)/embed.sql.h.m4" > "$(1[2])" -} - -IMPORT $(__name__) : icetray.c++.sql : : icetray.c++.sql ; - diff --git a/icetray/icetray/Jamfile.jam b/icetray/icetray/Jamfile.jam new file mode 100644 index 0000000..65cd528 --- /dev/null +++ b/icetray/icetray/Jamfile.jam @@ -0,0 +1,31 @@ +import package ; + +lib icetray : + abstractDatabaseClient.cpp + abstractCachingDatabaseClient.cpp + defaultPool.cpp + icetrayService.cpp + : + ..//adhocutil + ..//dbppcore + ..//Ice + ..//IceUtil + ..//IceBox + ..//pthread + ..//slicer + ..//slicer-db + ..//boost_system + ..//boost_thread + ../..//glibmm + -fvisibility=hidden + : : + . + ..//dbppcore + ..//adhocutil + ..//slicer + ..//slicer-db + ..//boost_thread + ; + +package.install install-main : . : : icetray : [ glob *.h : defaultPool.h ] ; + diff --git a/icetray/icetray/abstractCachingDatabaseClient.cpp b/icetray/icetray/abstractCachingDatabaseClient.cpp new file mode 100644 index 0000000..2c97ac6 --- /dev/null +++ b/icetray/icetray/abstractCachingDatabaseClient.cpp @@ -0,0 +1,18 @@ +#include "abstractCachingDatabaseClient.h" +#include + +template DLL_PUBLIC void AdHoc::Cache::add(const IceTray::AbstractCachingDatabaseClient::CacheKey &, const IceTray::AbstractCachingDatabaseClient::CacheItem &, time_t); +template DLL_PUBLIC const IceTray::AbstractCachingDatabaseClient::CacheItem * AdHoc::Cache::get(const IceTray::AbstractCachingDatabaseClient::CacheKey &) const; + +namespace IceTray { + AbstractCachingDatabaseClient::AbstractCachingDatabaseClient(DatabasePoolPtr d) : + AbstractDatabaseClient(d) + { + } + + void + AbstractCachingDatabaseClient::keyPushParams(CacheKey &) + { + } +} + diff --git a/icetray/icetray/abstractCachingDatabaseClient.h b/icetray/icetray/abstractCachingDatabaseClient.h new file mode 100644 index 0000000..bb1d070 --- /dev/null +++ b/icetray/icetray/abstractCachingDatabaseClient.h @@ -0,0 +1,54 @@ +#ifndef ICETRAY_ABSTRACTCACHINGDATABASECLIENT_H +#define ICETRAY_ABSTRACTCACHINGDATABASECLIENT_H + +#include "abstractDatabaseClient.h" +#include +#include +#include + +namespace IceTray { + class DLL_PUBLIC AbstractCachingDatabaseClient : public AbstractDatabaseClient { + private: + typedef std::vector CacheKey; + typedef boost::shared_ptr CacheItem; + + public: + AbstractCachingDatabaseClient(boost::shared_ptr> d); + + template + inline + Domain + fetchCache(time_t cacheTime, const Params & ... params) + { + CacheKey key; + key.reserve(sizeof...(Params) + 2); + key.push_back(Sql::hash); + key.push_back(typeid(Domain).hash_code()); + keyPushParams(key, params...); + if (auto cached = cache.get(key)) { + auto d = boost::any_cast(cached->get()); + if (d) { + return *d; + } + } + auto d(fetch(params...)); + cache.add(key, CacheItem(new boost::any(d)), time(NULL) + cacheTime); + return d; + } + + private: + template + static void inline keyPushParams(CacheKey & k, const Param & p, const Params & ... params) + { + k.push_back(std::hash()(p)); + keyPushParams(k, params...); + } + + static void keyPushParams(CacheKey &); + + AdHoc::Cache cache; + }; +} + +#endif + diff --git a/icetray/icetray/abstractDatabaseClient.cpp b/icetray/icetray/abstractDatabaseClient.cpp new file mode 100644 index 0000000..e5e3026 --- /dev/null +++ b/icetray/icetray/abstractDatabaseClient.cpp @@ -0,0 +1,28 @@ +#include "abstractDatabaseClient.h" + +namespace IceTray { + AbstractDatabaseClient::AbstractDatabaseClient(DatabasePoolPtr d) : + db(d) + { + } + + template<> + void + AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const std::string & p) + { + cmd->bindParamS(o, p); + } + + template<> + void + AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const int & p) + { + cmd->bindParamI(o, p); + } + + void + AbstractDatabaseClient::bind(int, DB::Command *) + { + } +} + diff --git a/icetray/icetray/abstractDatabaseClient.h b/icetray/icetray/abstractDatabaseClient.h new file mode 100644 index 0000000..aac9151 --- /dev/null +++ b/icetray/icetray/abstractDatabaseClient.h @@ -0,0 +1,43 @@ +#ifndef ICETRAY_ABSTRACTDATABASECLIENT_H +#define ICETRAY_ABSTRACTDATABASECLIENT_H + +#include "database.h" +#include +#include +#include + +namespace IceTray { + class DLL_PUBLIC AbstractDatabaseClient { + public: + AbstractDatabaseClient(DatabasePoolPtr d); + + template + inline + Domain + fetch(const Params & ... params) + { + auto c = db->get(); + auto s = DB::SelectCommandPtr(c->newSelectCommand(Sql::sql)); + bind(0, s.get(), params...); + return Slicer::DeserializeAny(*s); + } + + private: + template + static void inline bind(int offset, DB::Command * cmd, const Param & p, const Params & ... params) + { + bind1(offset, cmd, p); + bind(offset + 1, cmd, params...); + } + + static void bind(int offset, DB::Command * cmd); + + template + static void bind1(int offset, DB::Command * cmd, const Param & p); + + DatabasePoolPtr db; + }; +} + +#endif + diff --git a/icetray/icetray/database.h b/icetray/icetray/database.h new file mode 100644 index 0000000..23ad7fe --- /dev/null +++ b/icetray/icetray/database.h @@ -0,0 +1,13 @@ +#ifndef ICETRAY_DATABASE_H +#define ICETRAY_DATABASE_H + +#include +#include + +namespace IceTray { + typedef AdHoc::ResourcePool DatabasePool; + typedef boost::shared_ptr DatabasePoolPtr; +} + +#endif + diff --git a/icetray/icetray/defaultPool.cpp b/icetray/icetray/defaultPool.cpp new file mode 100644 index 0000000..c3f7e50 --- /dev/null +++ b/icetray/icetray/defaultPool.cpp @@ -0,0 +1,16 @@ +#include "defaultPool.h" +#include "icetrayService.h" + +namespace IceTray { + DefaultPool::DefaultPool(const std::string & name, const std::string & type, Ice::PropertiesPtr p) : + DB::ConnectionPool( + p->getPropertyAsIntWithDefault(name + ".Database.PoolMax", 10), + p->getPropertyAsIntWithDefault(name + ".Database.PoolKeep", 2), + p->getPropertyWithDefault(name + ".Database.Type", type), + p->getProperty(name + ".Database.ConnectionString")) + { + } + + FACTORY(DefaultPool, PoolProvider); +} + diff --git a/icetray/icetray/defaultPool.h b/icetray/icetray/defaultPool.h new file mode 100644 index 0000000..5b06ea2 --- /dev/null +++ b/icetray/icetray/defaultPool.h @@ -0,0 +1,15 @@ +#ifndef ICETRAY_DEFAULTPOOL_H +#define ICETRAY_DEFAULTPOOL_H + +#include +#include + +namespace IceTray { + class DefaultPool : public DB::ConnectionPool { + public: + DefaultPool(const std::string & name, const std::string & type, Ice::PropertiesPtr p); + }; +} + +#endif + diff --git a/icetray/icetray/icetrayService.cpp b/icetray/icetray/icetrayService.cpp new file mode 100644 index 0000000..aff6a8a --- /dev/null +++ b/icetray/icetray/icetrayService.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include "icetrayService.h" + +namespace IceTray { + void Service::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) + { + adp = ic->createObjectAdapter(name); + addObjects(name, ic, args, adp); + adp->activate(); + } + + void Service::stop() + { + adp->deactivate(); + adp->destroy(); + } + + DatabasePoolPtr Service::getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & name) + { + auto p = ic->getProperties(); + return DatabasePoolPtr(PoolProvider::createNew( + p->getPropertyWithDefault("DryIce.PoolProvider", "DefaultPool"), + name, type, p)); + } +} + +extern "C" { + DLL_PUBLIC + IceBox::Service * + createIceTrayService(Ice::CommunicatorPtr) + { + return IceTray::ServiceFactory::createNew("default"); + } +} + +INSTANTIATEVOIDFACTORY(IceTray::Service); +INSTANTIATEFACTORY(IceTray::DatabasePool, const std::string &, const std::string &, Ice::PropertiesPtr); + diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h new file mode 100644 index 0000000..8f35519 --- /dev/null +++ b/icetray/icetray/icetrayService.h @@ -0,0 +1,28 @@ +#ifndef ICETRAY_SERVICE_H +#define ICETRAY_SERVICE_H + +#include +#include +#include +#include "database.h" + +namespace IceTray { + class DLL_PUBLIC Service : public IceBox::Service, public AdHoc::AbstractPluginImplementation { + public: + virtual void addObjects(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr &) = 0; + + void start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) override; + + void stop() override; + + DatabasePoolPtr getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); + + Ice::ObjectAdapterPtr adp; + }; + + typedef AdHoc::Factory ServiceFactory; + typedef AdHoc::Factory PoolProvider; +} + +#endif + diff --git a/icetray/icetrayService.cpp b/icetray/icetrayService.cpp deleted file mode 100644 index aff6a8a..0000000 --- a/icetray/icetrayService.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include "icetrayService.h" - -namespace IceTray { - void Service::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) - { - adp = ic->createObjectAdapter(name); - addObjects(name, ic, args, adp); - adp->activate(); - } - - void Service::stop() - { - adp->deactivate(); - adp->destroy(); - } - - DatabasePoolPtr Service::getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & name) - { - auto p = ic->getProperties(); - return DatabasePoolPtr(PoolProvider::createNew( - p->getPropertyWithDefault("DryIce.PoolProvider", "DefaultPool"), - name, type, p)); - } -} - -extern "C" { - DLL_PUBLIC - IceBox::Service * - createIceTrayService(Ice::CommunicatorPtr) - { - return IceTray::ServiceFactory::createNew("default"); - } -} - -INSTANTIATEVOIDFACTORY(IceTray::Service); -INSTANTIATEFACTORY(IceTray::DatabasePool, const std::string &, const std::string &, Ice::PropertiesPtr); - diff --git a/icetray/icetrayService.h b/icetray/icetrayService.h deleted file mode 100644 index 8f35519..0000000 --- a/icetray/icetrayService.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef ICETRAY_SERVICE_H -#define ICETRAY_SERVICE_H - -#include -#include -#include -#include "database.h" - -namespace IceTray { - class DLL_PUBLIC Service : public IceBox::Service, public AdHoc::AbstractPluginImplementation { - public: - virtual void addObjects(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr &) = 0; - - void start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) override; - - void stop() override; - - DatabasePoolPtr getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); - - Ice::ObjectAdapterPtr adp; - }; - - typedef AdHoc::Factory ServiceFactory; - typedef AdHoc::Factory PoolProvider; -} - -#endif - diff --git a/icetray/mockPool.cpp b/icetray/mockPool.cpp deleted file mode 100644 index 43e7c0c..0000000 --- a/icetray/mockPool.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "mockPool.h" -#include "icetrayService.h" -#include - -namespace IceTray { - MockPool::MockPool(const std::string & name, const std::string &, Ice::PropertiesPtr p) : - DatabasePool( - p->getPropertyAsIntWithDefault(name + ".Database.PoolMax", 10), - p->getPropertyAsIntWithDefault(name + ".Database.PoolKeep", 2)), - name(name) - { - } - - DB::Connection * MockPool::createResource() const - { - return DB::MockDatabase::openConnectionTo(name); - } - - FACTORY(MockPool, PoolProvider); -}; - diff --git a/icetray/mockPool.h b/icetray/mockPool.h deleted file mode 100644 index 8936cb2..0000000 --- a/icetray/mockPool.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ICETRAY_MOCKPOOL_H -#define ICETRAY_MOCKPOOL_H - -#include "database.h" -#include -#include - -namespace IceTray { - class MockPool : public DatabasePool { - public: - MockPool(const std::string & name, const std::string &, Ice::PropertiesPtr p); - - DB::Connection * createResource() const override; - - const std::string name; - }; -} - -#endif - diff --git a/icetray/tool/Jamfile.jam b/icetray/tool/Jamfile.jam new file mode 100644 index 0000000..f24c409 --- /dev/null +++ b/icetray/tool/Jamfile.jam @@ -0,0 +1,4 @@ +import package ; + +package.install-data install-tools : boost-build/tools : icetray.jam [ glob embed.*.m4 ] ; + diff --git a/icetray/tool/embed.sql.cpp.m4 b/icetray/tool/embed.sql.cpp.m4 new file mode 100644 index 0000000..7043f78 --- /dev/null +++ b/icetray/tool/embed.sql.cpp.m4 @@ -0,0 +1,7 @@ +changecom(`@@') +#include "NAME.sql.h" + +const std::string NAMESPACE::NAME::sql({ +patsubst(esyscmd(`xxd -p -c 12 ' SQL), `\(..\)', `0x\1, ')0x00}); +const std::size_t NAMESPACE::NAME::hash(std::hash()(sql)); + diff --git a/icetray/tool/embed.sql.h.m4 b/icetray/tool/embed.sql.h.m4 new file mode 100644 index 0000000..fbabf62 --- /dev/null +++ b/icetray/tool/embed.sql.h.m4 @@ -0,0 +1,15 @@ +define(`foreach',`ifelse(eval($#>2),1, + `pushdef(`$1',`$3')$2`'popdef(`$1') + `'ifelse(eval($#>3),1,`$0(`$1',`$2',shift(shift(shift($@))))')')') +define(NAMESPACEC,`patsubst(NAMESPACE,`::', `,')') +#include +#include + +foreach(`ns', `namespace ns { ', NAMESPACEC) + class NAME { + public: + static const std::string sql; + static const std::size_t hash; + }; +foreach(`ns', `}', NAMESPACEC) + diff --git a/icetray/tool/icetray.jam b/icetray/tool/icetray.jam new file mode 100644 index 0000000..f999e2d --- /dev/null +++ b/icetray/tool/icetray.jam @@ -0,0 +1,34 @@ +import generators ; +import feature ; +import type ; +import path ; +import property ; +import project ; +import regex ; + +project.initialize $(__name__) ; +project icetray ; + +feature.feature icetray.sql.namespace : : free ; +type.register SQL : sql ; +generators.register-standard icetray.c++.sql : SQL : CPP(%.sql) H(%.sql) ; + +path-constant icetray-root : . ; + +rule icetray.c++.sql ( cpp h : sql : properties * ) +{ + local namespace = [ property.select icetray.sql.namespace : $(properties) ] ; + local relpath = [ path.relative-to . $(sql:D) ] ; + namespace = [ regex.replace $(namespace:G=)/$(relpath) "\\/\\." "" ] ; + namespace = [ regex.replace $(namespace) "\\/" "::" ] ; + NAMESPACE on $(<) = -DNAMESPACE=\"$(namespace)\" ; +} + +actions icetray.c++.sql +{ + m4 $(NAMESPACE) -DNAME="$(2:B)" -DSQL="$(2[1])" "$(icetray-root)/embed.sql.cpp.m4" > "$(1[1])" + m4 $(NAMESPACE) -DNAME="$(2:B)" "$(icetray-root)/embed.sql.h.m4" > "$(1[2])" +} + +IMPORT $(__name__) : icetray.c++.sql : : icetray.c++.sql ; + diff --git a/icetray/unittests/Jamfile.jam b/icetray/unittests/Jamfile.jam index 459f103..4cd0977 100644 --- a/icetray/unittests/Jamfile.jam +++ b/icetray/unittests/Jamfile.jam @@ -1,5 +1,5 @@ import testing ; -import ../icetray ; +import ../tool/icetray ; lib boost_utf : : boost_unit_test_framework ; lib boost_filesystem ; -- cgit v1.2.3