From e16e5330de6738dbf76864dba0bbebafe108a614 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 24 Dec 2015 04:58:10 +0000 Subject: Add service and models for reading from database --- mythfs/service/Jamfile.jam | 29 ++++++++++++++++++++++++++++- mythfs/service/dbimpl.cpp | 16 ++++++++++++++++ mythfs/service/dbimpl.h | 18 ++++++++++++++++++ mythfs/service/embed.cpp.m4 | 12 ++++++++++++ mythfs/service/embed.h.m4 | 12 ++++++++++++ mythfs/service/main.cpp | 4 +++- mythfs/service/myth-db.ice | 13 +++++++++++++ mythfs/service/myth-models.ice | 28 ++++++++++++++++++++++++++++ mythfs/service/recordingsVolume.cpp | 5 ----- mythfs/service/recordingsVolume.h | 7 +------ mythfs/service/sql/getRecorded.sql | 4 ++++ mythfs/unittests/Jamfile.jam | 5 ++++- mythfs/unittests/mockDefs.cpp | 1 + mythfs/unittests/mockDefs.h | 2 ++ mythfs/unittests/testMain.cpp | 6 ++++++ 15 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 mythfs/service/dbimpl.cpp create mode 100644 mythfs/service/dbimpl.h create mode 100644 mythfs/service/embed.cpp.m4 create mode 100644 mythfs/service/embed.h.m4 create mode 100644 mythfs/service/myth-db.ice create mode 100644 mythfs/service/myth-models.ice create mode 100644 mythfs/service/sql/getRecorded.sql 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 ] : + yes ..//netfsComms ..//adhocutil ..//dbppcore ..//boost_system + ..//boost_date_time ..//Ice ..//IceBox ..//IceUtil ..//pthread ..//icetray + ..//slicer ..//slicer-db ../..//glibmm : : @@ -17,3 +23,24 @@ lib mythfs : ..//netfsComms ..//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 + +namespace MythFS { + DBImpl::DBImpl(boost::shared_ptr> d) : + IceTray::AbstractDatabaseClient(d) + { + } + + Recordeds + DBImpl::getRecorded(const Ice::Current &) + { + return fetch(); + } +} + 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 +#include +#include + +namespace MythFS { + class DBImpl : public DB, ::IceTray::AbstractDatabaseClient { + public: + DBImpl(boost::shared_ptr>); + + 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()(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 +#include + +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 #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 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> 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 -#include #include -#include namespace MythFS { - class DLL_PUBLIC RecordingsVolume : public ::NetFS::Volume, ::IceTray::AbstractDatabaseClient { + class RecordingsVolume : public ::NetFS::Volume { public: - RecordingsVolume(boost::shared_ptr>); - 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 : ..//IceBox ..//pthread dryice + ../service//mythfs + ../service//mythfs : : dryice ..//dbppcore @@ -34,6 +36,8 @@ lib testCommon : ..//Ice ..//IceBox ..//pthread + ../service//mythfs + ../service//mythfs ; run @@ -41,7 +45,6 @@ run : : : BOOST_TEST_DYN_LINK - ../service//mythfs ..//boost_system ..//boost_filesystem 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 #include #include +#include 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(); -- cgit v1.2.3