diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-24 04:58:10 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-24 04:58:10 +0000 |
commit | dc9963e3d6519f6d1118e8e06e3a28e90bf80c91 (patch) | |
tree | ee282227211bdea2abc4837115d3b22b1cfd49d7 | |
parent | Initial WIP commit of MythFS (diff) | |
download | mythfs-dc9963e3d6519f6d1118e8e06e3a28e90bf80c91.tar.bz2 mythfs-dc9963e3d6519f6d1118e8e06e3a28e90bf80c91.tar.xz mythfs-dc9963e3d6519f6d1118e8e06e3a28e90bf80c91.zip |
Add service and models for reading from database
-rw-r--r-- | mythfs/service/Jamfile.jam | 29 | ||||
-rw-r--r-- | mythfs/service/dbimpl.cpp | 16 | ||||
-rw-r--r-- | mythfs/service/dbimpl.h | 18 | ||||
-rw-r--r-- | mythfs/service/embed.cpp.m4 | 12 | ||||
-rw-r--r-- | mythfs/service/embed.h.m4 | 12 | ||||
-rw-r--r-- | mythfs/service/main.cpp | 4 | ||||
-rw-r--r-- | mythfs/service/myth-db.ice | 13 | ||||
-rw-r--r-- | mythfs/service/myth-models.ice | 28 | ||||
-rw-r--r-- | mythfs/service/recordingsVolume.cpp | 5 | ||||
-rw-r--r-- | mythfs/service/recordingsVolume.h | 7 | ||||
-rw-r--r-- | mythfs/service/sql/getRecorded.sql | 4 | ||||
-rw-r--r-- | mythfs/unittests/Jamfile.jam | 5 | ||||
-rw-r--r-- | mythfs/unittests/mockDefs.cpp | 1 | ||||
-rw-r--r-- | mythfs/unittests/mockDefs.h | 2 | ||||
-rw-r--r-- | mythfs/unittests/testMain.cpp | 6 |
15 files changed, 148 insertions, 14 deletions
diff --git a/mythfs/service/Jamfile.jam b/mythfs/service/Jamfile.jam index 25225f9..aa79386 100644 --- a/mythfs/service/Jamfile.jam +++ b/mythfs/service/Jamfile.jam @@ -1,15 +1,21 @@ +import generators ; +import type ; + lib mythfs : - [ glob *.cpp ] + [ glob *.cpp *.ice sql/*.sql ] : + <slicer>yes <library>..//netfsComms <library>..//adhocutil <library>..//dbppcore <library>..//boost_system + <library>..//boost_date_time <library>..//Ice <library>..//IceBox <library>..//IceUtil <library>..//pthread <library>..//icetray + <library>..//slicer <library>..//slicer-db <library>../..//glibmm : : @@ -17,3 +23,24 @@ lib mythfs : <library>..//netfsComms <library>..//icetray ; + +path-constant root : . ; +type.register SQL : sql ; +type.register HEX : hex ; +generators.register-standard sql.embed.hex : SQL : HEX ; +generators.register-standard sql.embed : HEX : CPP H ; + +actions sql.embed +{ + m4 -DNAME="$(2[1]:B)" "$(root)/embed.h.m4" > "$(1[2])" + m4 -DNAME="$(2[1]:B)" "$(root)/embed.cpp.m4" > "$(1[1])" +} + +actions sql.embed.hex +{ + xxd -i "$(2)" - | grep , > "$(1[1])" +} + +IMPORT $(__name__) : sql.embed : : sql.embed ; +IMPORT $(__name__) : sql.embed.hex : : sql.embed.hex ; + diff --git a/mythfs/service/dbimpl.cpp b/mythfs/service/dbimpl.cpp new file mode 100644 index 0000000..4a53790 --- /dev/null +++ b/mythfs/service/dbimpl.cpp @@ -0,0 +1,16 @@ +#include "dbimpl.h" +#include <sql/getRecorded.h> + +namespace MythFS { + DBImpl::DBImpl(boost::shared_ptr<AdHoc::ResourcePool<::DB::Connection>> d) : + IceTray::AbstractDatabaseClient(d) + { + } + + Recordeds + DBImpl::getRecorded(const Ice::Current &) + { + return fetch<Recordeds, sql::getRecorded>(); + } +} + diff --git a/mythfs/service/dbimpl.h b/mythfs/service/dbimpl.h new file mode 100644 index 0000000..429d921 --- /dev/null +++ b/mythfs/service/dbimpl.h @@ -0,0 +1,18 @@ +#ifndef MYTHFS_DB_H +#define MYTHFS_DB_H + +#include <myth-db.h> +#include <abstractDatabaseClient.h> +#include <connectionPool.h> + +namespace MythFS { + class DBImpl : public DB, ::IceTray::AbstractDatabaseClient { + public: + DBImpl(boost::shared_ptr<AdHoc::ResourcePool<::DB::Connection>>); + + Recordeds getRecorded(const Ice::Current &); + }; +} + +#endif + diff --git a/mythfs/service/embed.cpp.m4 b/mythfs/service/embed.cpp.m4 new file mode 100644 index 0000000..43901dd --- /dev/null +++ b/mythfs/service/embed.cpp.m4 @@ -0,0 +1,12 @@ +define(`name', NAME) +define(`incl', `#include "'NAME`.h"') +define(`inclhex', `#include "'NAME`.hex"') +incl + +namespace sql { + const std::string name::sql({ + inclhex + , 0x00}); + const std::size_t name::hash(std::hash<std::string>()(sql)); +} + diff --git a/mythfs/service/embed.h.m4 b/mythfs/service/embed.h.m4 new file mode 100644 index 0000000..a08a1c5 --- /dev/null +++ b/mythfs/service/embed.h.m4 @@ -0,0 +1,12 @@ +define(`name', NAME) +#include <functional> +#include <string> + +namespace sql { + class name { + public: + static const std::string sql; + static const std::size_t hash; + }; +} + diff --git a/mythfs/service/main.cpp b/mythfs/service/main.cpp index f12472d..145cf71 100644 --- a/mythfs/service/main.cpp +++ b/mythfs/service/main.cpp @@ -3,6 +3,7 @@ #include <icetrayService.h> #include "service.h" #include "recordingsVolume.h" +#include "dbimpl.h" class Api : public IceTray::Service { public: @@ -10,7 +11,8 @@ class Api : public IceTray::Service { { auto db = getConnectionPool(ic, "mysql", "mythconverg"); adp->add(new MythFS::Service(), ic->stringToIdentity("service")); - adp->add(new MythFS::RecordingsVolume(db), ic->stringToIdentity("recordings")); + adp->add(new MythFS::DBImpl(db), ic->stringToIdentity("db")); + adp->add(new MythFS::RecordingsVolume(), ic->stringToIdentity("recordings")); } }; diff --git a/mythfs/service/myth-db.ice b/mythfs/service/myth-db.ice new file mode 100644 index 0000000..8164297 --- /dev/null +++ b/mythfs/service/myth-db.ice @@ -0,0 +1,13 @@ +#ifndef MYTHFS_DB +#define MYTHFS_DB + +#include "myth-models.ice" + +module MythFS { + interface DB { + idempotent Recordeds getRecorded(); + }; +}; + +#endif + diff --git a/mythfs/service/myth-models.ice b/mythfs/service/myth-models.ice new file mode 100644 index 0000000..b3fc853 --- /dev/null +++ b/mythfs/service/myth-models.ice @@ -0,0 +1,28 @@ +#ifndef MYTHFS_MODELS +#define MYTHFS_MODELS + +[["cpp:include:boost/date_time/posix_time/posix_time.hpp"]] + +module MythFS { + class Recorded { + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + string startTime; + [ "slicer:conversion:boost.posix_time.ptime:boost.posix_time.to_iso_extended_string:boost.posix_time.time_from_string:nodeclare" ] + string endTime; + string title; + string subtitle; + string description; + short season; + short episode; + string category; + string recgroup; + string seriesId; + string programId; + long fileSize; + string basename; + }; + sequence<Recorded> Recordeds; +}; + +#endif + diff --git a/mythfs/service/recordingsVolume.cpp b/mythfs/service/recordingsVolume.cpp index 4a6f437..cfebe46 100644 --- a/mythfs/service/recordingsVolume.cpp +++ b/mythfs/service/recordingsVolume.cpp @@ -1,11 +1,6 @@ #include "recordingsVolume.h" namespace MythFS { - RecordingsVolume::RecordingsVolume(boost::shared_ptr<AdHoc::ResourcePool<DB::Connection>> d) : - IceTray::AbstractDatabaseClient(d) - { - } - NetFS::DirectoryPrx RecordingsVolume::opendir(const NetFS::ReqEnv &, const std::string &, const Ice::Current&) { diff --git a/mythfs/service/recordingsVolume.h b/mythfs/service/recordingsVolume.h index a1e2573..65357ca 100644 --- a/mythfs/service/recordingsVolume.h +++ b/mythfs/service/recordingsVolume.h @@ -1,16 +1,11 @@ #ifndef MYTHFS_RECORDINGS_VOLUME_H #define MYTHFS_RECORDINGS_VOLUME_H -#include <resourcePool.h> -#include <visibility.h> #include <volume.h> -#include <abstractDatabaseClient.h> namespace MythFS { - class DLL_PUBLIC RecordingsVolume : public ::NetFS::Volume, ::IceTray::AbstractDatabaseClient { + class RecordingsVolume : public ::NetFS::Volume { public: - RecordingsVolume(boost::shared_ptr<AdHoc::ResourcePool<DB::Connection>>); - virtual NetFS::DirectoryPrx opendir(const NetFS::ReqEnv &, const std::string & path, const Ice::Current&) override; virtual void mkdir(const NetFS::ReqEnv &, const std::string & path, Ice::Int id, const Ice::Current&) override; diff --git a/mythfs/service/sql/getRecorded.sql b/mythfs/service/sql/getRecorded.sql new file mode 100644 index 0000000..7471831 --- /dev/null +++ b/mythfs/service/sql/getRecorded.sql @@ -0,0 +1,4 @@ +SELECT startTime, endTime, title, subtitle, description, season, episode, category, recgroup, seriesId, programId, fileSize, basename +FROM recorded +WHERE deletepending = 0 +ORDER BY chanId, startTime diff --git a/mythfs/unittests/Jamfile.jam b/mythfs/unittests/Jamfile.jam index 8ae546c..af84969 100644 --- a/mythfs/unittests/Jamfile.jam +++ b/mythfs/unittests/Jamfile.jam @@ -26,6 +26,8 @@ lib testCommon : <library>..//IceBox <library>..//pthread <library>dryice + <library>../service//mythfs + <implicit-dependency>../service//mythfs : : <library>dryice <library>..//dbppcore @@ -34,6 +36,8 @@ lib testCommon : <library>..//Ice <library>..//IceBox <library>..//pthread + <library>../service//mythfs + <implicit-dependency>../service//mythfs ; run @@ -41,7 +45,6 @@ run : : : <define>BOOST_TEST_DYN_LINK - <library>../service//mythfs <library>..//boost_system <library>..//boost_filesystem <library>testCommon diff --git a/mythfs/unittests/mockDefs.cpp b/mythfs/unittests/mockDefs.cpp index 389ca3f..b061c64 100644 --- a/mythfs/unittests/mockDefs.cpp +++ b/mythfs/unittests/mockDefs.cpp @@ -10,6 +10,7 @@ Service::Service() : } TestClient::TestClient() : + db(MythFS::DBPrx::checkedCast(ic->stringToProxy("db:tcp -p 9002"))), s(NetFS::ServicePrx::checkedCast(ic->stringToProxy("service:tcp -p 9002"))) { } diff --git a/mythfs/unittests/mockDefs.h b/mythfs/unittests/mockDefs.h index 05884c5..6619068 100644 --- a/mythfs/unittests/mockDefs.h +++ b/mythfs/unittests/mockDefs.h @@ -5,6 +5,7 @@ #include <visibility.h> #include <dryice.h> #include <service.h> +#include <myth-db.h> class DLL_PUBLIC Service : public IceTray::DryIce, MySQL::Mock { public: @@ -15,6 +16,7 @@ class DLL_PUBLIC TestClient : public IceTray::DryIceClient { public: TestClient(); + MythFS::DBPrx db; NetFS::ServicePrx s; }; diff --git a/mythfs/unittests/testMain.cpp b/mythfs/unittests/testMain.cpp index 067596f..8c18647 100644 --- a/mythfs/unittests/testMain.cpp +++ b/mythfs/unittests/testMain.cpp @@ -29,5 +29,11 @@ BOOST_AUTO_TEST_CASE( recordingsVolume ) rv->disconnect(); } +BOOST_AUTO_TEST_CASE( getRecorded ) +{ + auto r = db->getRecorded(); + BOOST_REQUIRE_EQUAL(11, r.size()); +} + BOOST_AUTO_TEST_SUITE_END(); |