From add5644f64c86b635b62d560187c993aa7072b76 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 30 Jul 2017 00:15:33 +0100 Subject: BIG migration from Project2 based to IceTray/Slicer :D --- libtmdb/testCallMockApi.cpp | 7 +- p2pvr/.p2config | 8 - p2pvr/Jamfile.jam | 58 +----- p2pvr/carddaemon/Jamfile.jam | 3 +- p2pvr/carddaemon/carddaemon.cpp | 16 +- p2pvr/daemon/Jamfile.jam | 23 +-- p2pvr/daemon/containerIterator.h | 40 ---- p2pvr/daemon/daemon.cpp | 61 +++--- p2pvr/daemon/dbClient.cpp | 56 ------ p2pvr/daemon/dbClient.h | 111 ----------- p2pvr/daemon/globalDevices.cpp | 29 +-- p2pvr/daemon/globalDevices.h | 12 +- p2pvr/daemon/maintenance.cpp | 90 ++++----- p2pvr/daemon/maintenance.h | 26 ++- p2pvr/daemon/maintenance/events.cpp | 118 +++++------ p2pvr/daemon/maintenance/network.cpp | 80 ++++---- p2pvr/daemon/maintenance/services.cpp | 48 ++--- p2pvr/daemon/muxedFileSink.cpp | 12 +- p2pvr/daemon/muxedFileSink.h | 3 + p2pvr/daemon/objectRowState.cpp | 89 --------- p2pvr/daemon/objectRowState.h | 48 ----- p2pvr/daemon/p2pvr-int.ice | 4 + p2pvr/daemon/pch.hpp | 20 -- p2pvr/daemon/privateExecContext.cpp | 14 -- p2pvr/daemon/privateExecContext.h | 13 -- p2pvr/daemon/recorder.cpp | 44 ++-- p2pvr/daemon/recorder.h | 17 +- p2pvr/daemon/recordings.cpp | 49 ++--- p2pvr/daemon/recordings.h | 10 +- p2pvr/daemon/resources.h | 12 -- p2pvr/daemon/schedulers/bitDumbScheduler.cpp | 1 - p2pvr/daemon/schedules.cpp | 111 ++++++----- p2pvr/daemon/schedules.h | 21 +- p2pvr/daemon/si.cpp | 122 ++++++------ p2pvr/daemon/si.h | 9 +- p2pvr/daemon/storage.cpp | 40 ++-- p2pvr/daemon/storage.h | 19 +- p2pvr/daemon/unittests/Jamfile.jam | 221 +++++---------------- p2pvr/daemon/unittests/datasources/postgres.xml | 4 - p2pvr/daemon/unittests/dummySelect.sql | 1 - p2pvr/daemon/unittests/mockDefs.cpp | 12 ++ p2pvr/daemon/unittests/mockDefs.h | 18 +- p2pvr/daemon/unittests/mockDevices.h | 3 +- p2pvr/daemon/unittests/mockRecorder.h | 3 +- p2pvr/daemon/unittests/mockScheduler.h | 3 +- p2pvr/daemon/unittests/testEmbedding.cpp | 14 -- p2pvr/daemon/unittests/testErrorHandling.cpp | 66 ++---- p2pvr/daemon/unittests/testMaint.cpp | 115 ++++------- p2pvr/daemon/unittests/testRecording.cpp | 54 +---- p2pvr/daemon/unittests/testRecordings.cpp | 48 +---- p2pvr/daemon/unittests/testSched.cpp | 53 ++--- p2pvr/daemon/unittests/testSi.cpp | 34 +--- .../daemon/unittests/testSqlSelectDeserializer.cpp | 86 -------- p2pvr/daemon/unittests/testStorage.cpp | 69 +++---- p2pvr/daemonbase/Jamfile.jam | 23 --- p2pvr/daemonbase/daemonBase.cpp | 64 ------ p2pvr/daemonbase/daemonBase.h | 32 --- p2pvr/daemonbase/fileSink.cpp | 27 --- p2pvr/daemonbase/fileSink.h | 22 -- p2pvr/daemonbase/p2LoggerWrapper.cpp | 45 ----- p2pvr/daemonbase/p2LoggerWrapper.h | 25 --- p2pvr/daemonbase/pch.hpp | 9 - p2pvr/datasources/postgres.xml | 4 - p2pvr/devices/Jamfile.jam | 25 +-- p2pvr/devices/frontend.cpp | 9 +- p2pvr/devices/frontend.h | 4 +- p2pvr/devices/frontends/ofdm.cpp | 29 +-- p2pvr/devices/localDevices.cpp | 56 +++--- p2pvr/devices/localDevices.h | 13 +- p2pvr/devices/mockTuner.cpp | 27 ++- p2pvr/devices/mockTuner.h | 4 + p2pvr/devices/pch.hpp | 20 -- p2pvr/devices/sampleSiData/events1.datxz | Bin 1112856 -> 1112857 bytes p2pvr/devices/tuner.cpp | 95 ++++----- p2pvr/devices/tuner.h | 27 ++- p2pvr/devices/tunerSendSi.cpp | 13 +- p2pvr/devices/tunerSendSi.h | 2 + p2pvr/devices/tunerSendTs.cpp | 5 +- p2pvr/devices/tunerSendTs.h | 2 + p2pvr/dvb/Jamfile.jam | 6 +- p2pvr/dvb/bindDataHandler.h | 3 +- p2pvr/dvb/pch.hpp | 22 -- p2pvr/dvb/siParsers/event.cpp | 1 - p2pvr/dvb/siParsers/network.cpp | 24 ++- p2pvr/dvb/siParsers/programAssociation.cpp | 1 - p2pvr/dvb/siParsers/programMap.cpp | 2 - p2pvr/dvb/siParsers/service.cpp | 1 - p2pvr/dvb/siParsers/table.cpp | 10 - p2pvr/dvb/siParsers/table.h | 4 +- p2pvr/dvb/unittests/Jamfile.jam | 3 +- p2pvr/dvb/unittests/createBroadcast.cpp | 2 - p2pvr/dvb/unittests/createSamples.cpp | 2 +- p2pvr/etc/init.d/p2pvrcardd | 26 --- p2pvr/etc/init.d/p2pvrd | 26 --- p2pvr/etc/p2config | 8 - p2pvr/etc/p2pvrcd/icebox.config | 7 + p2pvr/etc/p2pvrd/icebox.config | 11 + p2pvr/etc/systemd/p2pvrcardd.service | 10 - p2pvr/etc/systemd/p2pvrd.service | 12 +- p2pvr/ice/Jamfile.jam | 2 - p2pvr/ice/converters.cpp | 30 --- p2pvr/ice/dvb.ice | 3 +- p2pvr/ice/dvbsi.ice | 40 ++-- p2pvr/ice/p2pvr.ice | 26 +-- p2pvr/lib/Jamfile.jam | 11 +- p2pvr/lib/bindTimerTask.cpp | 1 - p2pvr/lib/fileHandle.cpp | 1 - p2pvr/lib/fileSink.cpp | 26 +++ p2pvr/lib/fileSink.h | 22 ++ p2pvr/lib/muxer.cpp | 12 +- p2pvr/lib/muxer.h | 3 + p2pvr/lib/p2Helpers.cpp | 43 ---- p2pvr/lib/p2Helpers.h | 81 -------- p2pvr/lib/pch.hpp | 20 -- p2pvr/lib/serviceStreamer.cpp | 8 - p2pvr/lib/serviceStreamer.h | 1 - p2pvr/lib/serviceStreamerCore.cpp | 7 +- p2pvr/lib/serviceStreamerCore.h | 3 + 118 files changed, 1037 insertions(+), 2314 deletions(-) delete mode 100644 p2pvr/.p2config delete mode 100644 p2pvr/daemon/containerIterator.h delete mode 100644 p2pvr/daemon/dbClient.cpp delete mode 100644 p2pvr/daemon/dbClient.h delete mode 100644 p2pvr/daemon/objectRowState.cpp delete mode 100644 p2pvr/daemon/objectRowState.h delete mode 100644 p2pvr/daemon/pch.hpp delete mode 100644 p2pvr/daemon/privateExecContext.cpp delete mode 100644 p2pvr/daemon/privateExecContext.h delete mode 100644 p2pvr/daemon/resources.h delete mode 100644 p2pvr/daemon/unittests/datasources/postgres.xml delete mode 100644 p2pvr/daemon/unittests/dummySelect.sql delete mode 100644 p2pvr/daemon/unittests/testEmbedding.cpp delete mode 100644 p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp delete mode 100644 p2pvr/daemonbase/Jamfile.jam delete mode 100644 p2pvr/daemonbase/daemonBase.cpp delete mode 100644 p2pvr/daemonbase/daemonBase.h delete mode 100644 p2pvr/daemonbase/fileSink.cpp delete mode 100644 p2pvr/daemonbase/fileSink.h delete mode 100644 p2pvr/daemonbase/p2LoggerWrapper.cpp delete mode 100644 p2pvr/daemonbase/p2LoggerWrapper.h delete mode 100644 p2pvr/daemonbase/pch.hpp delete mode 100644 p2pvr/datasources/postgres.xml delete mode 100644 p2pvr/devices/pch.hpp delete mode 100644 p2pvr/dvb/pch.hpp delete mode 100755 p2pvr/etc/init.d/p2pvrcardd delete mode 100755 p2pvr/etc/init.d/p2pvrd delete mode 100644 p2pvr/etc/p2config create mode 100644 p2pvr/etc/p2pvrcd/icebox.config create mode 100644 p2pvr/etc/p2pvrd/icebox.config create mode 100644 p2pvr/lib/fileSink.cpp create mode 100644 p2pvr/lib/fileSink.h delete mode 100644 p2pvr/lib/p2Helpers.cpp delete mode 100644 p2pvr/lib/p2Helpers.h delete mode 100644 p2pvr/lib/pch.hpp diff --git a/libtmdb/testCallMockApi.cpp b/libtmdb/testCallMockApi.cpp index cb06791..9386793 100644 --- a/libtmdb/testCallMockApi.cpp +++ b/libtmdb/testCallMockApi.cpp @@ -10,11 +10,8 @@ BOOST_AUTO_TEST_CASE( search_tmdb ) { TMDb::Proxy test(MockBase, ApiKey); auto resp = test.SearchMulti("breaking bad", 1, Ice::Current()); - BOOST_REQUIRE_EQUAL(3, resp->Results.size()); - BOOST_REQUIRE_EQUAL(3, resp->TotalResults); - BOOST_REQUIRE_EQUAL(1396, resp->Results[0]->Id); - BOOST_REQUIRE_EQUAL(239459, resp->Results[1]->Id); - BOOST_REQUIRE_EQUAL(19050, resp->Results[2]->Id); + BOOST_REQUIRE(!resp->Results.empty()); + BOOST_REQUIRE(resp->TotalResults); } BOOST_AUTO_TEST_CASE( get_movie ) diff --git a/p2pvr/.p2config b/p2pvr/.p2config deleted file mode 100644 index 8e215ad..0000000 --- a/p2pvr/.p2config +++ /dev/null @@ -1,8 +0,0 @@ -library = libp2pvrdaemon.so -daemon.type = p2pvrdaemon -common.filelog.level = 9 -common.filelog.path = /tmp/p2daemon.log -common.filelog.openmode = w -common.consolelogLevel = 9 -p2pvr.globaldevices.carddaemon = Devices:default -h defiant -p 10000 -p2pvr.storage.root = /var/store/p2pvr/recordings diff --git a/p2pvr/Jamfile.jam b/p2pvr/Jamfile.jam index a74d82c..b084b3b 100644 --- a/p2pvr/Jamfile.jam +++ b/p2pvr/Jamfile.jam @@ -1,70 +1,22 @@ import package ; -import type ; -import generators ; lib boost_utf : : boost_unit_test_framework ; lib adhocutil : : : : /usr/include/adhocutil ; +lib icetray : : : : /usr/include/dbpp /usr/include/adhocutil /usr/include/icetray ; +lib IceBox ; -alias p2common : ..//glibmm : : : - /usr/include/project2/common - /usr/include/project2/lib - "-lp2common" -; -alias p2cgi : ..//glibmm : : : - /usr/include/project2/cgi - "-lp2cgicommon" -; -alias p2xml : ..//glibmm : : : - /usr/include/project2/xml - "-lp2xml" -; -alias p2sql : ..//glibmm : : : - /usr/include/dbpp - /usr/include/project2/sql - /usr/include/project2/basics - "-lp2sql -ldbppcore" -; -alias p2streams : ..//glibmm : : : - /usr/include/project2/streams - "-lp2streams" -; -alias p2ut : ..//glibmm : : : - /usr/include/project2/ut - "-lp2ut -lp2ut" -; -alias p2basics : ..//glibmm : : : - /usr/include/project2/basics - "-lp2basics" -; -alias p2ice : ..//glibmm : : : - /usr/include/project2/ice - "-lp2ice -lp2iceclient" -; -alias p2daemonlib : ..//glibmm : : : - "-I /usr/include/project2/daemon/lib" - "-lp2daemonlib" -; build-project daemon ; build-project carddaemon ; +build-project dvb/unittests ; + explicit debuginstall ; -install debuginstall : dvb//p2pvrdvb devices//p2pvrdevices lib//p2pvrlib carddaemon//p2pvrcarddaemon daemonbase//p2pvrdaemonbase daemon//p2pvrdaemon ice//p2pvrice ../libtmdb//tmdb : ./testing ; +install debuginstall : dvb//p2pvrdvb devices//p2pvrdevices lib//p2pvrlib carddaemon//p2pvrcarddaemon daemon//p2pvrdaemon ice//p2pvrice ../libtmdb//tmdb : ./testing ; alias finallib : carddaemon//p2pvrcarddaemon daemon//p2pvrdaemon ; package.install install : : : finallib ; -type.register SQL : sql ; - -generators.register-standard sql.embed.asm : SQL : ASM ; - path-constant root : . ; -actions sql.embed.asm -{ - m4 -DNAME="sql_$(2:B)" -DPATH="$(2)" "$(root)/embed.m4" > "$(1)" -} - -IMPORT $(__name__) : sql.embed.asm : : sql.embed.asm ; - diff --git a/p2pvr/carddaemon/Jamfile.jam b/p2pvr/carddaemon/Jamfile.jam index 7088966..d85f365 100644 --- a/p2pvr/carddaemon/Jamfile.jam +++ b/p2pvr/carddaemon/Jamfile.jam @@ -3,6 +3,7 @@ lib p2pvrcarddaemon : : ..//adhocutil ../ice//p2pvrice + ..//icetray + ..//IceBox ../devices//p2pvrdevices - ../daemonbase//p2pvrdaemonbase ; diff --git a/p2pvr/carddaemon/carddaemon.cpp b/p2pvr/carddaemon/carddaemon.cpp index 0b234e5..d48bb0c 100644 --- a/p2pvr/carddaemon/carddaemon.cpp +++ b/p2pvr/carddaemon/carddaemon.cpp @@ -1,19 +1,17 @@ -#include +#include #include "localDevices.h" #include +#include +#include -class P2PvrCardDaemon : public DaemonBase { +class P2PvrCardDaemon : public IceTray::Service { public: - P2PvrCardDaemon(int argc, char ** argv) : - DaemonBase(argc, argv) - { - } - - void addServants(const Ice::ObjectAdapterPtr & adapter, const IceUtil::TimerPtr & timer) const + void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adapter) override { + IceUtil::TimerPtr timer = new IceUtil::Timer(); adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity("Devices")); } }; -NAMEDFACTORY("p2pvrcarddaemon", P2PvrCardDaemon, DaemonFactory); +FACTORY(P2PvrCardDaemon, IceTray::ServiceFactory); diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam index 369e714..318a585 100644 --- a/p2pvr/daemon/Jamfile.jam +++ b/p2pvr/daemon/Jamfile.jam @@ -1,33 +1,32 @@ +import icetray ; + lib slicer : : slicer : : /usr/include/slicer ; lib slicer-db : : slicer-db : : /usr/include/slicer ; +lib boost_program_options ; +lib dbppcore ; -cpp-pch pch : pch.hpp : - ../ice//p2pvrice - ../lib//p2pvrlib - ../dvb//p2pvrdvb - ..//p2sql - ../devices//p2pvrdevices - ../daemonbase//p2pvrdaemonbase - yes -; +path-constant me : . ; lib p2pvrdaemon : - pch [ glob-tree *.ice *.cpp *.sql : bin unittests ] : ../ice//p2pvrice ../lib//p2pvrlib ../dvb//p2pvrdvb ../../libtmdb//tmdb - ..//p2sql ../devices//p2pvrdevices - ../daemonbase//p2pvrdaemonbase + boost_program_options + dbppcore ..//adhocutil + ..//icetray + ..//IceBox ../../libtmdb//tmdb slicer slicer-db yes . + $(me) + P2PVR : : . ../ice//p2pvrice diff --git a/p2pvr/daemon/containerIterator.h b/p2pvr/daemon/containerIterator.h deleted file mode 100644 index 88976af..0000000 --- a/p2pvr/daemon/containerIterator.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CONTAINERITERATOR_H -#define CONTAINERITERATOR_H - -#include -#include "objectRowState.h" - -template -class ContainerIterator : public IHaveSubTasks { - public: - ContainerIterator(const T * con, const SelectedColumns & sc) : - SourceObject(__PRETTY_FUNCTION__), - IHaveSubTasks(NULL), - binder(boost::bind(&BindColumns, _1, sc, _2)), - container(con) - { - } - - void execute(ExecContext * ec) const - { - ObjectRowStateTmpl rs; - for (const auto & i : *container) { - binder(rs, i); - rs.process(ec, boost::bind(&ContainerIterator::executeChildren, this, ec)); - } - } - - private: - boost::function binder; - const T * container; - - void executeChildren(ExecContext * ec) const - { - for (const Tasks::value_type & sq : normal) { - sq->execute(ec); - } - } -}; - -#endif - diff --git a/p2pvr/daemon/daemon.cpp b/p2pvr/daemon/daemon.cpp index 874ea3b..6a62457 100644 --- a/p2pvr/daemon/daemon.cpp +++ b/p2pvr/daemon/daemon.cpp @@ -1,5 +1,3 @@ -#include -#include #include "localDevices.h" #include "globalDevices.h" #include "maintenance.h" @@ -10,44 +8,51 @@ #include "recordings.h" #include #include +#include // These configure external components and so they live here -class P2PVRTMDb { +class P2PVRTMDb : public IceTray::Options { public: - static std::string apikey; - static std::string baseUrl; - INITOPTIONS; + P2PVRTMDb() : IceTray::Options("P2PVR TMDb configuration") { } + + std::string apikey; + std::string baseUrl; + + ICETRAY_OPTIONS_DECLARE; }; -std::string P2PVRTMDb::apikey; -std::string P2PVRTMDb::baseUrl; -DECLARE_OPTIONS(P2PVRTMDb, "P2PVR TMDb configuration") -("p2pvr.tmdb.apikey", Options::value(&P2PVRTMDb::apikey, "48b32823d2b60c5c1085af36daed03fa"), - "The Movie Database API key") -("p2pvr.tmdb.baseurl", Options::value(&P2PVRTMDb::baseUrl, "http://private-5513-themoviedb.apiary-mock.com/3"), - "The Movie Database API base URL") -END_OPTIONS(P2PVRTMDb); +ICETRAY_OPTIONS(P2PVRTMDb, + ("p2pvr.tmdb.apikey", boost::program_options::value(&apikey)->default_value("48b32823d2b60c5c1085af36daed03fa"), + "The Movie Database API key") + ("p2pvr.tmdb.baseurl", boost::program_options::value(&baseUrl)->default_value("http://private-5513-themoviedb.apiary-mock.com/3"), + "The Movie Database API base URL") +); -class P2PvrDaemon : public DaemonBase { +class P2PvrDaemon : public IceTray::Service { public: - P2PvrDaemon(int argc, char ** argv) : - DaemonBase(argc, argv) + void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adapter) override { + IceTray::OptionsResolver tmdbOpts; + + IceUtil::TimerPtr timer = new IceUtil::Timer(); + auto db = getConnectionPool(ic, "postgresql", "postgres"); + auto localDevices = add(ic, adapter, new LocalDevices(adapter, timer), "Devices"); + auto globalDevices = add(ic, adapter, new GlobalDevices(), "GlobalDevices"); + auto maintenance = add(ic, adapter, new Maintenance(db, adapter, timer), "Maintenance"); + auto si = add(ic, adapter, new SI(db), "SI"); + auto schedules = add(ic, adapter, new Schedules(db), "Schedules"); + auto storage = add(ic, adapter, new Storage(), "Storage"); + auto recorder = add(ic, adapter, new Recorder(adapter, timer), "Recorder"); + auto recordings = add(ic, adapter, new Recordings(db), "Recordings"); + auto tmdb = add(ic, adapter, new TMDb::Proxy(tmdbOpts->baseUrl, tmdbOpts->apikey), "TMDb"); } - void addServants(const Ice::ObjectAdapterPtr & adapter, const IceUtil::TimerPtr & timer) const + template + typename Object::ProxyType add(const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & adapter, const IceUtil::Handle & object, const std::string & name) const { - adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity("Devices")); - adapter->add(new GlobalDevices(), ic->stringToIdentity("GlobalDevices")); - adapter->add(new Maintenance(adapter, timer), ic->stringToIdentity("Maintenance")); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->add(new Schedules(), ic->stringToIdentity("Schedules")); - adapter->add(new Storage(), ic->stringToIdentity("Storage")); - adapter->add(new Recorder(adapter, timer), ic->stringToIdentity("Recorder")); - adapter->add(new Recordings(), ic->stringToIdentity("Recordings")); - adapter->add(new TMDb::Proxy(P2PVRTMDb::baseUrl, P2PVRTMDb::apikey), ic->stringToIdentity("TMDb")); + return Object::ProxyType::uncheckedCast(adapter->add(object, ic->stringToIdentity(name))); } }; -NAMEDFACTORY("p2pvrdaemon", P2PvrDaemon, DaemonFactory); +FACTORY(P2PvrDaemon, IceTray::ServiceFactory); diff --git a/p2pvr/daemon/dbClient.cpp b/p2pvr/daemon/dbClient.cpp deleted file mode 100644 index de4b926..0000000 --- a/p2pvr/daemon/dbClient.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include "dbClient.h" -#include - -void -DatabaseClient::SqlMergeColumnsInserter(SqlMergeTask * merge, const std::string & name, bool key) -{ - merge->cols.insert(new SqlMergeTask::TargetColumn(name, key)); - if (key) { - merge->keys.insert(name); - } -} - -void -DatabaseClient::onAllDatasources(const DataSourceCall & call) const -{ - for (const CommonObjects::DataSources::value_type & ds : CommonObjects::datasources) { - call(ds.second); - } -} - -DatabaseClient::TxHelper::TxHelper(const DatabaseClient * dbc) : - client(dbc), - so(NULL, - boost::bind(&DatabaseClient::onAllDatasources, dbc, DataSourceCall(boost::bind(&DataSource::commit, _1))), - boost::bind(&DatabaseClient::onAllDatasources, dbc, DataSourceCall(boost::bind(&DataSource::rollback, _1)))) -{ -} - -void -DatabaseClient::TxHelper::Commit() const -{ - client->onAllDatasources(boost::bind(&DataSource::commit, _1)); -} - -DatabaseClient::NoRowsFoundException::NoRowsFoundException() : - std::runtime_error("No rows found") -{ -} - -VariableType -operator/(const DatabaseClient::SelectPtr & cmd, unsigned int col) -{ - HandleAsVariableType vt; - (*cmd)[col].apply(vt); - return vt.variable; -} - -VariableType -operator/(const DatabaseClient::SelectPtr & cmd, const std::string & col) -{ - HandleAsVariableType vt; - (*cmd)[col].apply(vt); - return vt.variable; -} - diff --git a/p2pvr/daemon/dbClient.h b/p2pvr/daemon/dbClient.h deleted file mode 100644 index 1fc12e8..0000000 --- a/p2pvr/daemon/dbClient.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef DBCLIENT_H -#define DBCLIENT_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "p2Helpers.h" -#include - -class SqlMergeTask; - -class DatabaseClient : public virtual CommonObjects { - public: - typedef boost::shared_ptr SelectPtr; - typedef boost::shared_ptr ModifyPtr; - - static void SqlMergeColumnsInserter(SqlMergeTask * merge, const std::string & name, bool key); - - class TxHelper { - public: - TxHelper(const DatabaseClient *); - void Commit() const; - - private: - const DatabaseClient * client; - AdHoc::ScopeExit so; - }; - - template - std::pair Modify(const std::string & sql, const Args & ... args) const - { - auto db = dataSource("postgres")->getWritable(); - auto cmd = ModifyPtr(db->newModifyCommand(sql)); - Bind(cmd.get(), 0, args...); - return {db, cmd}; - } - - template - void Store(const Obj & o, const ExtraArgs & ... ea) const - { - auto db = dataSource("postgres")->getWritable(); - Slicer::SerializeAny(o, db.get(), ea...); - } - - template - std::pair Select(const std::string & sql, const Args & ... args) const - { - auto db = dataSource("postgres")->getReadonly(); - auto cmd = SelectPtr(db->newSelectCommand(sql)); - Bind(cmd.get(), 0, args...); - return {db, cmd}; - } - - class NoRowsFoundException : public std::runtime_error { - public: - NoRowsFoundException(); - }; - - template - Rtn SelectScalar(const std::string & sql, const Args & ... args) const - { - auto db = dataSource("postgres"); - auto cmd = SelectPtr(db->getReadonly()->newSelectCommand(sql)); - Bind(cmd.get(), 0, args...); - while (cmd->fetch()) { - HandleAsVariableType h; - (*cmd)[0].apply(h); - Rtn r; - h.variable >> r; - return r; - } - throw NoRowsFoundException(); - } - - private: - static void Bind(DB::Command *, unsigned int) { } - - template - static void Bind(DB::Command * cmd, unsigned int offset, const Arg & arg) - { - VariableType v; - v << arg; - boost::apply_visitor(SqlVariableBinder(cmd, offset), v); - } - - template - static void Bind(DB::Command * cmd, unsigned int offset, const Arg & arg, const Args & ... args) - { - Bind(cmd, offset, arg); - Bind(cmd, offset + 1, args...); - } - - friend class TxHelper; - typedef boost::function DataSourceCall; - void onAllDatasources(const DataSourceCall &) const; -}; - -VariableType -operator/(const DatabaseClient::SelectPtr & cmd, unsigned int col); - -VariableType -operator/(const DatabaseClient::SelectPtr & cmd, const std::string & col); - -#endif - diff --git a/p2pvr/daemon/globalDevices.cpp b/p2pvr/daemon/globalDevices.cpp index 3f0c485..4557fc6 100644 --- a/p2pvr/daemon/globalDevices.cpp +++ b/p2pvr/daemon/globalDevices.cpp @@ -1,22 +1,23 @@ -#include #include "globalDevices.h" #include -std::vector GlobalDevices::Devices; +namespace po = boost::program_options; -DECLARE_OPTIONS(GlobalDevices, "P2PVR Devices") -("p2pvr.globaldevices.carddaemon", - Options::functions( - [](const VariableType & df) { Devices.push_back(df); }, - []{ Devices.clear(); }), - "ICE address of remote device pools (:)") -END_OPTIONS(GlobalDevices); +GlobalDevices::Options::Options() : + IceTray::Options("P2PVR Devices") +{ +} + +ICETRAY_OPTIONS(GlobalDevices::Options, + ("p2pvr.globaldevices.carddaemon", po::value(&Devices), + "ICE address of remote device pools (:)") +) P2PVR::TunerPrx GlobalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); - for (const auto & pool : Devices) { + for (const auto & pool : options->Devices) { try { auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetTunerSpecific(delivery); @@ -31,7 +32,7 @@ P2PVR::TunerPrx GlobalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); - for (const auto & pool : Devices) { + for (const auto & pool : options->Devices) { try { auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetTunerAny(delivery); @@ -46,7 +47,7 @@ P2PVR::PrivateTunerPrx GlobalDevices::GetPrivateTuner(short type, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); - for (const auto & pool : Devices) { + for (const auto & pool : options->Devices) { try { auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetPrivateTuner(type); @@ -61,7 +62,7 @@ void GlobalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); - for (const auto & pool : Devices) { + for (const auto & pool : options->Devices) { auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); poolprx->ReleaseTuner(tuner); } @@ -72,7 +73,7 @@ GlobalDevices::TunerCount(const Ice::Current & ice) { int total = 0; auto ic = ice.adapter->getCommunicator(); - for (const auto & pool : Devices) { + for (const auto & pool : options->Devices) { try { auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); total += poolprx->TunerCount(); diff --git a/p2pvr/daemon/globalDevices.h b/p2pvr/daemon/globalDevices.h index 86d80c5..cffb491 100644 --- a/p2pvr/daemon/globalDevices.h +++ b/p2pvr/daemon/globalDevices.h @@ -10,15 +10,23 @@ class DLL_PUBLIC GlobalDevices : public P2PVR::Devices { public: + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + std::vector Devices; + }; + P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &); P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr &, const Ice::Current &); P2PVR::PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &); void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); int TunerCount(const Ice::Current &); - INITOPTIONS; private: - static std::vector Devices; + IceTray::OptionsResolver options; }; #endif diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp index f6878ec..23eef15 100644 --- a/p2pvr/daemon/maintenance.cpp +++ b/p2pvr/daemon/maintenance.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "maintenance.h" @@ -6,24 +5,26 @@ #include "bindTimerTask.h" #include #include +#include -time_t Maintenance::periodUpdateNetwork; -time_t Maintenance::periodUpdateServices; -time_t Maintenance::periodUpdateEvents; -bool Maintenance::scanOnStart; +namespace po = boost::program_options; -DECLARE_OPTIONS(Maintenance, "P2PVR Maintenance options") -("p2pvr.maintenance.periodUpdateNetwork", Options::value(&periodUpdateNetwork, 86400 * 7), - "Period between automated updates of DVB network (1 week)") -("p2pvr.maintenance.periodUpdateServices", Options::value(&periodUpdateServices, 86400 * 7), - "Period between automated updates of DVB services (1 week)") -("p2pvr.maintenance.periodUpdateEvents", Options::value(&periodUpdateEvents, 3600 * 12), - "Period between automated updates of DVB events (12 hours)") -("p2pvr.maintenance.scanOnStart", Options::value(&scanOnStart, false), - "Perform the maintenance circle on start-up (false)") -END_OPTIONS(Maintenance); +Maintenance::Options::Options() : IceTray::Options("P2PVR Maintenance options") { } +ICETRAY_OPTIONS(Maintenance::Options, + ("p2pvr.maintenance.periodUpdateNetwork", po::value(&periodUpdateNetwork)->default_value(86400 * 7), + "Period between automated updates of DVB network (1 week)") + ("p2pvr.maintenance.periodUpdateServices", po::value(&periodUpdateServices)->default_value(86400 * 7), + "Period between automated updates of DVB services (1 week)") + ("p2pvr.maintenance.periodUpdateEvents", po::value(&periodUpdateEvents)->default_value(3600 * 12), + "Period between automated updates of DVB events (12 hours)") + ("p2pvr.maintenance.scanOnStart", po::value(&scanOnStart)->default_value(false), + "Perform the maintenance circle on start-up (false)") +); -Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : +IceTray::Logging::LoggerPtr Maintenance::logger(LOGMANAGER()->getLogger()); + +Maintenance::Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : + IceTray::AbstractDatabaseClient(db), adapter(a), timer(t), clientCheck(new BindTimerTask(boost::bind(&Maintenance::ScheduledUpdate, this))), @@ -35,7 +36,7 @@ Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : if (timer) { timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(5 * 60)); } - if (scanOnStart) { + if (options->scanOnStart) { ScheduledUpdate(); } } @@ -60,40 +61,39 @@ Maintenance::UpdateAll(short type, const Ice::Current & ice) void Maintenance::ScheduledUpdate() { - Logger()->messagebf(LOG_DEBUG, "%s: triggered", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: triggered", __PRETTY_FUNCTION__); if (!updateRunning) { std::thread update([this] { - try { + try { AdHoc::ScopeExit notRunning([this]{ updateRunning = false; }); - updateRunning = true; - auto si = P2PVR::MaintenancePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Maintenance"))); - time_t now = time(NULL); - if (lastUpdateNetwork < now - periodUpdateNetwork) { - Logger()->messagebf(LOG_INFO, "%s: updating network", __PRETTY_FUNCTION__); - si->UpdateNetwork(FE_OFDM); - time(&lastUpdateNetwork); - } - if (lastUpdateServices < now - periodUpdateServices) { - Logger()->messagebf(LOG_INFO, "%s: updating services", __PRETTY_FUNCTION__); - si->UpdateServices(); - time(&lastUpdateServices); - } - if (lastUpdateEvents < now - periodUpdateEvents) { - Logger()->messagebf(LOG_INFO, "%s: updating events", __PRETTY_FUNCTION__); - si->UpdateEvents(); - time(&lastUpdateEvents); - } - Logger()->messagebf(LOG_DEBUG, "%s: completed", __PRETTY_FUNCTION__); + updateRunning = true; + time_t now = time(NULL); + if (lastUpdateNetwork < now - options->periodUpdateNetwork) { + logger->messagebf(LOG::INFO, "%s: updating network", __PRETTY_FUNCTION__); + this->UpdateNetwork(FE_OFDM, Ice::Current()); + time(&lastUpdateNetwork); } - catch (const std::exception & ex) { - char * buf = __cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL); - Logger()->messagebf(LOG_ERR, "%s: failed %s: %s", __PRETTY_FUNCTION__, buf, ex.what()); - free(buf); + if (lastUpdateServices < now - options->periodUpdateServices) { + logger->messagebf(LOG::INFO, "%s: updating services", __PRETTY_FUNCTION__); + this->UpdateServices(Ice::Current()); + time(&lastUpdateServices); } - catch (...) { - Logger()->messagebf(LOG_ERR, "%s: failed (unknown exception)", __PRETTY_FUNCTION__); + if (lastUpdateEvents < now - options->periodUpdateEvents) { + logger->messagebf(LOG::INFO, "%s: updating events", __PRETTY_FUNCTION__); + this->UpdateEvents(Ice::Current()); + time(&lastUpdateEvents); } - }); + logger->messagebf(LOG::DEBUG, "%s: completed", __PRETTY_FUNCTION__); + } + catch (const std::exception & ex) { + char * buf = __cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL); + logger->messagebf(LOG::ERR, "%s: failed %s: %s", __PRETTY_FUNCTION__, buf, ex.what()); + free(buf); + } + catch (...) { + logger->messagebf(LOG::ERR, "%s: failed (unknown exception)", __PRETTY_FUNCTION__); + } + }); update.detach(); } } diff --git a/p2pvr/daemon/maintenance.h b/p2pvr/daemon/maintenance.h index 7c3e9b3..c941d06 100644 --- a/p2pvr/daemon/maintenance.h +++ b/p2pvr/daemon/maintenance.h @@ -3,12 +3,24 @@ #include #include -#include "dbClient.h" +#include +#include +#include #include -class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public DatabaseClient { +class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public IceTray::AbstractDatabaseClient { public: - Maintenance(Ice::ObjectAdapterPtr, IceUtil::TimerPtr); + class Options : public IceTray::Options { + public: + Options(); + ICETRAY_OPTIONS_DECLARE; + time_t periodUpdateNetwork; + time_t periodUpdateServices; + time_t periodUpdateEvents; + bool scanOnStart; + }; + + Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr, IceUtil::TimerPtr); void UpdateAll(const Ice::Current &); void UpdateAll(short type, const Ice::Current &); @@ -16,8 +28,6 @@ class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public DatabaseClient void UpdateServices(const Ice::Current &); void UpdateEvents(const Ice::Current &); - INITOPTIONS; - private: DLL_PRIVATE void ScheduledUpdate(); @@ -30,10 +40,8 @@ class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public DatabaseClient time_t lastUpdateEvents; bool updateRunning; - static time_t periodUpdateNetwork; - static time_t periodUpdateServices; - static time_t periodUpdateEvents; - static bool scanOnStart; + IceTray::OptionsResolver options; + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/maintenance/events.cpp b/p2pvr/daemon/maintenance/events.cpp index c8fee58..b4b3c92 100644 --- a/p2pvr/daemon/maintenance/events.cpp +++ b/p2pvr/daemon/maintenance/events.cpp @@ -1,104 +1,92 @@ -#include #include "../maintenance.h" #include -#include #include -#include -#include #include #include -#include -#include +#include +#include +#include +#include +#include "sql/Maint_pruneEvents.sql.h" -ResourceString(Maint_pruneEvents, sql_Maint_pruneEvents); +class SiEventsStream : public Slicer::Stream { + private: + class SiEventsHandler : public SiEpgParser { + public: + SiEventsHandler(const Consumer & c, IceTray::Logging::LoggerPtr l) : + consumer(c), + logger(l) + { + } -class SiEventsHandler : public SiEpgParser { - public: - SiEventsHandler(const RowProcessorCallback & cb, ExecContext * e, const SelectedColumns & sc) : - ecs(sc), - callBack(cb), - ec(e) - { - } + bool HandleTable(DVBSI::EventPtr e) override + { + logger->messagebf(LOG::DEBUG, "Service Id: %d Program Id: %d Title: %s Time: %s - %s", + e->ServiceId, e->EventId, e->Title, e->StartTime, e->StopTime); + consumer(e); + return false; + } - bool HandleTable(DVBSI::EventPtr e) - { - Logger()->messagebf(LOG_DEBUG, "Service Id: %d Program Id: %d Title: %s Time: %s - %s", - e->ServiceId, e->EventId, e->Title, e->StartTime, e->StopTime); - BindColumns(rowState, ecs, e); - rowState.process(ec, callBack); - return false; - } + private: + const Consumer & consumer; + const IceTray::Logging::LoggerPtr logger; + }; - private: - ObjectRowStateTmpl rowState; - const SelectedColumns & ecs; - const RowProcessorCallback callBack; - ExecContext * ec; -}; - -class SiEventsMerger : public IHaveSubTasks { public: - SiEventsMerger(const Ice::Current & i, const SelectedColumns & sc) : - SourceObject(__PRETTY_FUNCTION__), - IHaveSubTasks(NULL), - ecs(sc), - ice(i) { } + SiEventsStream(const Ice::Current & i, IceTray::Logging::LoggerPtr l) : + ice(i), + logger(l) + { + } - void execute(ExecContext * ec) const + void Produce(const Consumer & ch) override { auto ic = ice.adapter->getCommunicator(); auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); - if (!devs || !si) { throw std::runtime_error("bad proxy(s)"); } - TemporaryIceAdapterObject parser(ice.adapter, - new SiEventsHandler(boost::bind(&SiEventsMerger::executeChildren, this, ec), ec, ecs)); - auto delivery = si->GetDeliveryForSi(); if (!delivery) { throw std::runtime_error("no delivery methods"); } - - Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); auto tuner = devs->GetTunerAny(delivery); - Logger()->messagebf(LOG_DEBUG, "%s: Fetching events", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Fetching events", __PRETTY_FUNCTION__); + TemporaryIceAdapterObject parser(ice.adapter, new SiEventsHandler(ch, logger)); + tuner->SendEventInformation(parser); devs->ReleaseTuner(tuner); } private: - const SelectedColumns & ecs; const Ice::Current & ice; - - void executeChildren(ExecContext * ec) const - { - for (const Tasks::value_type & sq : normal) { - sq->execute(ec); - } - } + const IceTray::Logging::LoggerPtr logger; }; +MODELPARTFORSTREAM(SiEventsStream); + void Maintenance::UpdateEvents(const Ice::Current & ice) { - TxHelper tx(this); - PrivateExecContext ec; - SqlMergeTask mergeEvents("postgres", "events"); - auto ecs = CreateColumns(boost::bind(SqlMergeColumnsInserter, &mergeEvents, _1, _2)); - mergeEvents.sources.insert(new SiEventsMerger(ice, ecs)); - mergeEvents.insteadOfDelete = new DynamicSql::SqlText("current = false"); - mergeEvents.updateWhere = new DynamicSql::SqlText("a.current"); - mergeEvents.loadComplete(this); - mergeEvents.execute(&ec); - Modify(Maint_pruneEvents).second->execute(); - tx.Commit(); - Logger()->messagebf(LOG_INFO, "%s: Updated events", __PRETTY_FUNCTION__); - + auto dbc = db->get(); auto ic = ice.adapter->getCommunicator(); + + SiEventsStream stream(ice, logger); + + DB::TransactionScope tx(dbc.get()); + DB::TablePatch tp; + tp.dest = "events"; + tp.insteadOfDelete = new DB::StaticSqlWriter("current = false"); + tp.where = new DB::StaticSqlWriter("a.current"); + Slicer::SerializeAny(stream, dbc.get(), tp); + + + P2PVR::sql::Maint_pruneEvents.modify(dbc.get())->execute(); + logger->messagebf(LOG::INFO, "%s: Updated events", __PRETTY_FUNCTION__); + auto sch = P2PVR::SchedulesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("Schedules"))); sch->DoReschedule(); } diff --git a/p2pvr/daemon/maintenance/network.cpp b/p2pvr/daemon/maintenance/network.cpp index fdf2c8e..4b03f6d 100644 --- a/p2pvr/daemon/maintenance/network.cpp +++ b/p2pvr/daemon/maintenance/network.cpp @@ -1,88 +1,90 @@ -#include #include "../maintenance.h" #include -#include #include -#include -#include #include -#include +#include +#include +#include -class SiNetworkInformationMerger : public SiNetworkInformationParser, public PrivateExecContext { +class SiNetworkInformationMerger : public SiNetworkInformationParser { public: - SiNetworkInformationMerger(DatabaseClient * co) : commonObjects(co) { } + SiNetworkInformationMerger(DB::Connection * d, IceTray::Logging::LoggerPtr l) : + dbc(d), + logger(l) + { + } bool HandleTable(DVBSI::NetworkPtr n) { - Logger()->messagebf(LOG_DEBUG, "Network Id: %d Name: %s", n->NetworkId, *n->Name); + logger->messagebf(LOG::DEBUG, "Network Id: %d Name: %s", n->NetworkId, *n->Name); for (const auto & ts : n->TransportStreams) { - Logger()->messagebf(LOG_DEBUG, "\tTransport Stream Id: %d Original Network Id: %d", ts->TransportStreamId, ts->OriginalNetworkId); + logger->messagebf(LOG::DEBUG, "\tTransport Stream Id: %d Original Network Id: %d", ts->TransportStreamId, ts->OriginalNetworkId); for (const auto & s : ts->Services) { - Logger()->messagebf(LOG_DEBUG, "\t\tService Id: %d Service Type: %d", s.ServiceId, s.Type); + logger->messagebf(LOG::DEBUG, "\t\tService Id: %d Service Type: %d", s.ServiceId, s.Type); } if (ts->Terrestrial) { - Logger()->messagebf(LOG_DEBUG, "\t\tDVB-T: Frequency: %d", ts->Terrestrial->Frequency); + logger->messagebf(LOG::DEBUG, "\t\tDVB-T: Frequency: %d", ts->Terrestrial->Frequency); } } - DatabaseClient::TxHelper tx(commonObjects); - SqlMergeTask mergeNetwork("postgres", "networks"); - auto ncs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2)); - std::vector networks = { n }; - mergeNetwork.sources.insert(new ContainerIterator>(&networks, ncs)); - mergeNetwork.loadComplete(commonObjects); - mergeNetwork.execute(this); + DB::TablePatch mergeNetwork; + mergeNetwork.dest = "networks"; + Slicer::SerializeAny(n, dbc, mergeNetwork); - SqlMergeTask mergeTransports("postgres", "transportstreams"); - auto tscs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2)); - mergeTransports.sources.insert(new ContainerIterator(&n->TransportStreams, tscs)); - mergeTransports.loadComplete(commonObjects); - mergeTransports.execute(this); + DB::TablePatch mergeTransportStreams; + mergeTransportStreams.dest = "transportstreams"; + Slicer::SerializeAny(n->TransportStreams, dbc, mergeTransportStreams); mergeDelivery("delivery_dvbt", n); mergeDelivery("delivery_dvbs", n); mergeDelivery("delivery_dvbc", n); - SqlMergeTask mergeServices("postgres", "services"); - auto scs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); - for (const auto & s : n->TransportStreams) { - mergeServices.sources.insert(new ContainerIterator(&s->Services, scs)); + DVBSI::NetworkServiceList services; + for (const auto & ts : n->TransportStreams) { + for (const auto & s : ts->Services) { + services.push_back(s); + } } - mergeServices.loadComplete(commonObjects); - mergeServices.execute(this); + DB::TablePatch mergeServices; + mergeServices.dest = "services"; + Slicer::SerializeAny(services, dbc, mergeServices); + return false; } private: template void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n) { - SqlMergeTask merge("postgres", table); - auto dcs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2)); + DB::TablePatch tp; + tp.dest = table; std::vector dels; for (const auto & s : n->TransportStreams) { if (auto d = s.get()->*member) { dels.push_back(d); } } - merge.sources.insert(new ContainerIterator(&dels, dcs)); - merge.loadComplete(commonObjects); - merge.execute(this); + Slicer::SerializeAny(dels, dbc, tp); } - DatabaseClient * commonObjects; + DB::Connection * dbc; + IceTray::Logging::LoggerPtr logger; }; void Maintenance::UpdateNetwork(short type, const Ice::Current & ice) { + auto dbc = db->get(); auto ic = ice.adapter->getCommunicator(); auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); - auto siparser = new SiNetworkInformationMerger(this); + auto siparser = new SiNetworkInformationMerger(dbc.get(), logger); TemporaryIceAdapterObject parser(ice.adapter, siparser); if (!devs) { throw std::runtime_error("bad proxy(s)"); } + + DB::TransactionScope tx(dbc.get()); + auto transport = si->GetDeliveryForSi(); if (transport) { P2PVR::TunerPrx tuner; @@ -93,16 +95,16 @@ Maintenance::UpdateNetwork(short type, const Ice::Current & ice) return; } catch (const P2PVR::NoSuitableDeviceAvailable &) { - Logger()->messagebf(LOG_WARNING, "%s: Failed to get a suitable tuner", __PRETTY_FUNCTION__); + logger->messagebf(LOG::WARNING, "%s: Failed to get a suitable tuner", __PRETTY_FUNCTION__); throw; } catch (const std::exception & ex) { - Logger()->messagebf(LOG_WARNING, "%s: Failed to fetch network information: %s", __PRETTY_FUNCTION__, ex.what()); + logger->messagebf(LOG::WARNING, "%s: Failed to fetch network information: %s", __PRETTY_FUNCTION__, ex.what()); devs->ReleaseTuner(tuner); throw; } catch (...) { - Logger()->messagebf(LOG_WARNING, "%s: Failed to fetch network information", __PRETTY_FUNCTION__); + logger->messagebf(LOG::WARNING, "%s: Failed to fetch network information", __PRETTY_FUNCTION__); devs->ReleaseTuner(tuner); throw; } diff --git a/p2pvr/daemon/maintenance/services.cpp b/p2pvr/daemon/maintenance/services.cpp index e5edbc5..315ca0e 100644 --- a/p2pvr/daemon/maintenance/services.cpp +++ b/p2pvr/daemon/maintenance/services.cpp @@ -1,41 +1,41 @@ -#include #include "../maintenance.h" #include -#include +#include #include -#include -#include #include -#include +#include +#include +#include -class SiServicesMerger : public SiServicesParser, public PrivateExecContext { +class SiServicesMerger : public SiServicesParser { public: - SiServicesMerger(DatabaseClient * co) : commonObjects(co) { } + SiServicesMerger(IceTray::Logging::LoggerPtr l, DB::Connection * d) : + logger(l), + dbc(d) + { + } bool HandleTable(DVBSI::TransportStreamPtr ts) { - Logger()->messagebf(LOG_DEBUG, "Transport Stream Id: %d Original Network Id: %s", ts->TransportStreamId, ts->OriginalNetworkId); + logger->messagebf(LOG::DEBUG, "Transport Stream Id: %d Original Network Id: %s", ts->TransportStreamId, ts->OriginalNetworkId); for (const auto & s : ts->Services) { - Logger()->messagebf(LOG_DEBUG, "\tService Id: %d Name: %s Type: %d, Provider: %s, DefaultAuthority: %s, RunningStatus %d FreeCaMode %d", + logger->messagebf(LOG::DEBUG, "\tService Id: %d Name: %s Type: %d, Provider: %s, DefaultAuthority: %s, RunningStatus %d FreeCaMode %d", s->ServiceId, (s->Name ? *s->Name : "?"), (s->Type ? *s->Type : -1), (s->ProviderName ? *s->ProviderName : "?"), (s->DefaultAuthority ? *s->DefaultAuthority : "?"), s->RunningStatus, s->FreeCaMode); } - DatabaseClient::TxHelper tx(commonObjects); - SqlMergeTask mergeServices("postgres", "services"); - auto scs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); - // Don't change the list of services available from the network - mergeServices.doDelete = VariableType(false); - mergeServices.doInsert = VariableType(false); - mergeServices.sources.insert(new ContainerIterator(&ts->Services, scs)); - mergeServices.loadComplete(commonObjects); - mergeServices.execute(this); + DB::TablePatch mergeServices; + mergeServices.dest = "services"; + mergeServices.doDeletes = false; + mergeServices.doInserts = false; + Slicer::SerializeAny(ts->Services, dbc, mergeServices); return false; } private: - DatabaseClient * commonObjects; + IceTray::Logging::LoggerPtr logger; + DB::Connection * dbc; }; void @@ -49,7 +49,8 @@ Maintenance::UpdateServices(const Ice::Current & ice) throw std::runtime_error("bad proxy(s)"); } - auto siparser = new SiServicesMerger(this); + auto dbc = db->get(); + auto siparser = new SiServicesMerger(logger, dbc.get()); TemporaryIceAdapterObject parser(ice.adapter, siparser); auto delivery = si->GetDeliveryForSi(); @@ -57,11 +58,12 @@ Maintenance::UpdateServices(const Ice::Current & ice) throw std::runtime_error("no delivery methods"); } - Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); + DB::TransactionScope tx(dbc.get()); + logger->messagebf(LOG::DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); auto tuner = devs->GetTunerAny(delivery); - Logger()->messagebf(LOG_DEBUG, "%s: Fetching service list", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Fetching service list", __PRETTY_FUNCTION__); tuner->SendServiceDescriptions(parser); - Logger()->messagebf(LOG_INFO, "%s: Updated service list", __PRETTY_FUNCTION__); + logger->messagebf(LOG::INFO, "%s: Updated service list", __PRETTY_FUNCTION__); devs->ReleaseTuner(tuner); } diff --git a/p2pvr/daemon/muxedFileSink.cpp b/p2pvr/daemon/muxedFileSink.cpp index 16a3588..ff6ec35 100644 --- a/p2pvr/daemon/muxedFileSink.cpp +++ b/p2pvr/daemon/muxedFileSink.cpp @@ -1,4 +1,3 @@ -#include #include "muxedFileSink.h" #include #include @@ -9,7 +8,8 @@ class MuxerFailure : public P2PVR::DataHandlingException { }; -MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::string & cmd) +MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::string & cmd) : + logger(LOGMANAGER()->getLogger()) { std::vector params; boost::algorithm::split(params, cmd, isspace, boost::algorithm::token_compress_on); @@ -20,7 +20,7 @@ MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::strin } fds = ProcessPipesPtr(new AdHoc::System::ProcessPipes(params, true, true, true)); fcntl(fds->fdIn(), F_SETFL, O_NONBLOCK); - Logger()->messagebf(LOG_INFO, "Muxer::%p started with command '%s' for %s", this, cmd, t); + logger->messagebf(LOG::INFO, "Muxer::%p started with command '%s' for %s", this, cmd, t); } MuxedFileSink::~MuxedFileSink() @@ -30,7 +30,7 @@ MuxedFileSink::~MuxedFileSink() while (waitpid(fds->pid(), &status, WNOHANG) == 0) { ReadMuxer(5); } - Logger()->messagebf(LOG_INFO, "Muxer::%p finished with status %d", this, status); + logger->messagebf(LOG::INFO, "Muxer::%p finished with status %d", this, status); } bool @@ -44,7 +44,7 @@ MuxedFileSink::NewData(const P2PVR::Data & data, const Ice::Current &) // Send some input auto w = write(fds->fdIn(), &data[off], data.size() - off); if (w == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { - Logger()->messagebf(LOG_ERR, "Muxer::%p write failed (%d:%s)", this, errno, strerror(errno)); + logger->messagebf(LOG::ERR, "Muxer::%p write failed (%d:%s)", this, errno, strerror(errno)); throw MuxerFailure(); } off += w; @@ -115,7 +115,7 @@ MuxedFileSink::ReadMuxer(int waitTime) const boost::algorithm::split(lines, buf, boost::algorithm::is_any_of("\r\n\f"), boost::algorithm::token_compress_on); for (const auto & line : lines) { if (line.empty()) continue; - Logger()->messagebf(LOG_INFO, "Muxer::%p > %s", this, line); + logger->messagebf(LOG::INFO, "Muxer::%p > %s", this, line); } } } diff --git a/p2pvr/daemon/muxedFileSink.h b/p2pvr/daemon/muxedFileSink.h index ec22a62..d252372 100644 --- a/p2pvr/daemon/muxedFileSink.h +++ b/p2pvr/daemon/muxedFileSink.h @@ -6,6 +6,7 @@ #include #include #include +#include class MuxedFileSink : public P2PVR::RawDataClient { public: @@ -21,6 +22,8 @@ class MuxedFileSink : public P2PVR::RawDataClient { typedef boost::shared_ptr ProcessPipesPtr; ProcessPipesPtr fds; mutable std::mutex lock; + + IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/objectRowState.cpp b/p2pvr/daemon/objectRowState.cpp deleted file mode 100644 index 89e5ac8..0000000 --- a/p2pvr/daemon/objectRowState.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "objectRowState.h" -#include - -const std::string md_mergeKey("merge:key"); -const std::string md_mergeOmit("merge:omit"); - -bool -mdHasFlag(const std::list & md, const std::string & flag) -{ - return std::find(md.begin(), md.end(), flag) != md.end(); -} - -SelectedColumns -CreateColumns(Slicer::ModelPartPtr mp, const ColumnCreator & cc) -{ - SelectedColumns cols; - mp->OnEachChild([cc,&cols](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { - auto & md = h->GetMetadata(); - auto omitted = mdHasFlag(md, md_mergeOmit); - cols.push_back(!omitted); - if (omitted) return; - cc(name, mdHasFlag(md, md_mergeKey)); - }); - return cols; -} - -class SqlTarget : public Slicer::ValueTarget, - public Slicer::TValueTarget, - public Slicer::TValueTarget { - public: - SqlTarget(VariableType & v) : vt(v) {} - -#define BIND(Type) \ - virtual void get(const Type & t) const override { vt = t; } - BIND(bool); - BIND(::Ice::Byte); - BIND(::Ice::Short); - BIND(::Ice::Int); - BIND(::Ice::Long); - BIND(::Ice::Float); - BIND(::Ice::Double); - BIND(::std::string); - BIND(boost::posix_time::ptime); - BIND(boost::posix_time::time_duration); - - private: - VariableType & vt; -}; -typedef IceUtil::Handle SqlTargetPtr; - -void -BindColumns(Slicer::ModelPartPtr mp, const SelectedColumns & sc, RowState & rs) -{ - unsigned int field = 0; - mp->OnEachChild([&rs,&field,&sc](const std::string &, Slicer::ModelPartPtr mp, Slicer::HookCommonPtr) { - if (!sc[field]) return; - if (mp && mp->HasValue()) { - SqlTargetPtr st = new SqlTarget(rs.fields[field++]); - mp->GetValue(st); - } - else { - rs.fields[field++] = Null(); - } - }); -} - -ObjectRowState::ObjectRowState(const ColumnSpecifier & cs) : - columns(ColumnCreatorHelper(cs)) -{ - fields.resize(columns.size()); -} - -const Columns & -ObjectRowState::getColumns() const -{ - return columns; -} - -Columns -ObjectRowState::ColumnCreatorHelper(const ColumnSpecifier & cs) -{ - int index = 0; - Columns columns; - cs([&columns, &index](const std::string & name, bool) { - columns.insert(new Column(index++, name)); - }); - return columns; -} - diff --git a/p2pvr/daemon/objectRowState.h b/p2pvr/daemon/objectRowState.h deleted file mode 100644 index 252a411..0000000 --- a/p2pvr/daemon/objectRowState.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef OBJECT_ROW_STATE_H -#define OBJECT_ROW_STATE_H - -#include -#include -#include -#include - -typedef boost::function ColumnCreator; -typedef boost::function ColumnSpecifier; -typedef std::vector SelectedColumns; - -void BindColumns(Slicer::ModelPartPtr, const SelectedColumns &, RowState &); - -template -void BindColumns(RowState & rs, const SelectedColumns & sc, const V & v) -{ - BindColumns(Slicer::ModelPart::CreateFor(const_cast(v)), sc, rs); -} - -SelectedColumns CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); - -template -SelectedColumns CreateColumns(const ColumnCreator & cc) -{ - V v; - return CreateColumns(Slicer::ModelPart::CreateFor(v), cc); -} - -class ObjectRowState : public RowState { - public: - ObjectRowState(const ColumnSpecifier & cs); - const Columns & getColumns() const; - - private: - static Columns ColumnCreatorHelper(const ColumnSpecifier & cs); - - Columns columns; -}; - -template -class ObjectRowStateTmpl : public ObjectRowState { - public: - ObjectRowStateTmpl(const ColumnSpecifier & cs = CreateColumns) : ObjectRowState(cs) {} -}; - -#endif - diff --git a/p2pvr/daemon/p2pvr-int.ice b/p2pvr/daemon/p2pvr-int.ice index 1dfaf17..a4f2311 100644 --- a/p2pvr/daemon/p2pvr-int.ice +++ b/p2pvr/daemon/p2pvr-int.ice @@ -1,4 +1,5 @@ #include +#include module P2PVR { class ScheduleCandidate { @@ -12,5 +13,8 @@ module P2PVR { }; sequence ScheduleCandidates; + sequence SatelliteDeliverySeq; + sequence CableDeliverySeq; + sequence TerrestrialDeliverySeq; }; diff --git a/p2pvr/daemon/pch.hpp b/p2pvr/daemon/pch.hpp deleted file mode 100644 index 7c96f52..0000000 --- a/p2pvr/daemon/pch.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef BOOST_BUILD_PCH_ENABLED -#ifndef P2PVRLIB_PCH -#define P2PVRLIB_PCH - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#endif -#endif - diff --git a/p2pvr/daemon/privateExecContext.cpp b/p2pvr/daemon/privateExecContext.cpp deleted file mode 100644 index 47c5773..0000000 --- a/p2pvr/daemon/privateExecContext.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "privateExecContext.h" - -VariableType -PrivateExecContext::getParameter(const VariableType &) const -{ - throw NotSupported(__PRETTY_FUNCTION__); -} - -SessionPtr -PrivateExecContext::getSession() const -{ - throw NotSupported(__PRETTY_FUNCTION__); -} - diff --git a/p2pvr/daemon/privateExecContext.h b/p2pvr/daemon/privateExecContext.h deleted file mode 100644 index 1d336b0..0000000 --- a/p2pvr/daemon/privateExecContext.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PRIVATEEXECCONTENT_H -#define PRIVATEEXECCONTENT_H - -#include - -class PrivateExecContext : public ExecContext { - public: - VariableType getParameter(const VariableType & key) const; - SessionPtr getSession() const; -}; - -#endif - diff --git a/p2pvr/daemon/recorder.cpp b/p2pvr/daemon/recorder.cpp index e965253..548ad11 100644 --- a/p2pvr/daemon/recorder.cpp +++ b/p2pvr/daemon/recorder.cpp @@ -1,4 +1,3 @@ -#include #include "recorder.h" #include "bindTimerTask.h" #include @@ -10,22 +9,29 @@ #include "muxer.h" #include #include +#include -std::string Recorder::extension; -std::string Recorder::muxerCommand; +namespace po = boost::program_options; -DECLARE_OPTIONS(Recorder, "P2PVR Recorder options") -("p2pvr.recorder.extension", Options::value(&extension, "mp4"), - "File extension to save with (default: mp4)") -("p2pvr.recorder.muxercommand", Options::value(&muxerCommand, "/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -"), - "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -')") -END_OPTIONS(Recorder); +Recorder::Options::Options() : + IceTray::Options("P2PVR Recorder options") +{ +} + +ICETRAY_OPTIONS(Recorder::Options, + ("p2pvr.recorder.extension", po::value(&extension)->default_value("mp4"), + "File extension to save with (default: mp4)") + ("p2pvr.recorder.muxercommand", po::value(&muxerCommand)->default_value("/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -"), + "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -')") +); + +IceTray::Logging::LoggerPtr Recorder::logger(LOGMANAGER()->getLogger()); Recorder::Recorder(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : adapter(a), timer(t) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); RefreshSchedules(Ice::Current()); } @@ -53,7 +59,7 @@ Recorder::RefreshSchedules(const Ice::Current &) IceUtil::TimerTaskPtr startTimer = new BindTimerTask(boost::bind(&Recorder::StartRecording, this, schedule, service, event)); timer->schedule(startTimer, IceUtil::Time::seconds(startIn)); pendingRecordings.push_back(startTimer); - Logger()->messagebf(LOG_DEBUG, "Recording %s scheduled for %s seconds", event->Title, startIn); + logger->messagebf(LOG::DEBUG, "Recording %s scheduled for %s seconds", event->Title, startIn); } } @@ -63,21 +69,23 @@ Recorder::StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, std::lock_guard g(lock); auto storage = P2PVR::StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); auto recordings = P2PVR::RecordingsPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Recordings"))); + auto devices = P2PVR::DevicesPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("GlobalDevices"))); + auto si = P2PVR::SIPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("SI"))); auto id = boost::lexical_cast(boost::uuids::random_generator()()); auto store = storage->OpenForWrite(id); AdHoc::ScopeExit _store(NULL, NULL, [this,&store,&storage,&id]() { storage->Close(store); storage->Delete(id); }); auto target = store; P2PVR::RawDataClientPrx muxer; - if (!muxerCommand.empty()) { - muxer = P2PVR::RawDataClientPrx::checkedCast(adapter->addWithUUID(new Muxer(store, muxerCommand))); + if (!options->muxerCommand.empty()) { + muxer = P2PVR::RawDataClientPrx::checkedCast(adapter->addWithUUID(new Muxer(store, options->muxerCommand))); target = muxer; } AdHoc::ScopeExit _muxer(NULL, NULL, [this,&muxer]() { if (muxer) adapter->remove(muxer->ice_getIdentity()); }); - auto ss = ServiceStreamerPtr(new ServiceStreamer(service->ServiceId, target, adapter->getCommunicator(), adapter)); + auto ss = ServiceStreamerPtr(new ServiceStreamer(service->ServiceId, target, devices, si, adapter)); ss->Start(); - Logger()->messagebf(LOG_INFO, "Started recording %s (%s - %s) on %s (%d)", + logger->messagebf(LOG::INFO, "Started recording %s (%s - %s) on %s (%d)", event->Title, event->StartTime, event->StopTime, service->Name ? *service->Name : "", service->ServiceId); @@ -88,14 +96,14 @@ Recorder::StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, auto stopIn = (*event->StopTime + *schedule->Late - boost::posix_time::second_clock::universal_time()).total_seconds(); newCurrent->stopTimer = new BindTimerTask(boost::bind(&Recorder::StopRecording, this, newCurrent)); timer->schedule(newCurrent->stopTimer, IceUtil::Time::seconds(stopIn)); - Logger()->messagebf(LOG_DEBUG, "Recording %s scheduled stop in %s seconds", event->Title, stopIn); + logger->messagebf(LOG::DEBUG, "Recording %s scheduled stop in %s seconds", event->Title, stopIn); } void Recorder::StopRecording(CurrentPtr c) { std::lock_guard g(lock); - Logger()->messagebf(LOG_DEBUG, "Stopping %s", c->event->Title); + logger->messagebf(LOG::DEBUG, "Stopping %s", c->event->Title); c->stream->Stop(); if (c->muxer) { adapter->remove(c->muxer->ice_getIdentity()); @@ -103,6 +111,6 @@ Recorder::StopRecording(CurrentPtr c) currentRecordings.erase(c); auto storage = P2PVR::StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); storage->Close(c->store); - Logger()->messagebf(LOG_DEBUG, "Stopped %s", c->event->Title); + logger->messagebf(LOG::DEBUG, "Stopped %s", c->event->Title); } diff --git a/p2pvr/daemon/recorder.h b/p2pvr/daemon/recorder.h index 6a6940e..e6ff42a 100644 --- a/p2pvr/daemon/recorder.h +++ b/p2pvr/daemon/recorder.h @@ -8,9 +8,20 @@ #include #include "serviceStreamer.h" #include +#include class DLL_PUBLIC Recorder : public P2PVR::Recorder { public: + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + std::string extension; + std::string muxerCommand; + }; + typedef std::vector Pendings; class Current { @@ -30,8 +41,6 @@ class DLL_PUBLIC Recorder : public P2PVR::Recorder { void RefreshSchedules(const Ice::Current &); - INITOPTIONS; - private: DLL_PRIVATE void StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, P2PVR::EventPtr event); DLL_PRIVATE void StopRecording(CurrentPtr); @@ -43,8 +52,8 @@ class DLL_PUBLIC Recorder : public P2PVR::Recorder { Pendings pendingRecordings; std::mutex lock; - static std::string extension; - static std::string muxerCommand; + IceTray::OptionsResolver options; + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp index ac8f27a..7c5125b 100644 --- a/p2pvr/daemon/recordings.cpp +++ b/p2pvr/daemon/recordings.cpp @@ -1,50 +1,45 @@ -#include #include "recordings.h" -#include "resources.h" #include #include #include #include #include +#include +#include +#include -ResourceString(Recording_Delete, sql_Recordings_delete); -ResourceString(Recording_GetStorage, sql_Recordings_getStorage); -ResourceString(Recording_GetAll, sql_Recordings_getAll); +IceTray::Logging::LoggerPtr Recordings::logger(LOGMANAGER()->getLogger()); + +Recordings::Recordings(IceTray::DatabasePoolPtr db) : + IceTray::AbstractDatabaseClient(db) +{ +} Ice::Int Recordings::NewRecording(const P2PVR::RecordingPtr & r, const Ice::Current &) { - Logger()->messagebf(LOG_INFO, "%s: Creating new recording %s at %s", __PRETTY_FUNCTION__, r->Guid, r->StorageAddress); - TxHelper tx(this); - Store(r, "recordings"); - Logger()->messagebf(LOG_INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId); + auto dbc = db->get(); + logger->messagebf(LOG::INFO, "%s: Creating new recording %s at %s", __PRETTY_FUNCTION__, r->Guid, r->StorageAddress); + DB::TransactionScope tx(dbc.get()); + Slicer::SerializeAny(r, dbc.get(), "recordings"); + logger->messagebf(LOG::INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId); return r->RecordingId; } void -Recordings::DeleteRecording(int id, const Ice::Current & ice) +Recordings::DeleteRecording(int id, const Ice::Current &) { - Logger()->messagebf(LOG_INFO, "%s: Deleting recording Id: %d", __PRETTY_FUNCTION__, id); - auto ic = ice.adapter->getCommunicator(); - TxHelper tx(this); - auto recordingStorages = Select(Recording_GetStorage, id); - while (recordingStorages.second->fetch()) { - std::string addr = recordingStorages.second / "storageaddress"; - std::string guid = recordingStorages.second / "guid"; - auto storage = P2PVR::StoragePrx::checkedCast(ic->stringToProxy(addr)); - if (storage) { - storage->Delete(guid); - Logger()->messagebf(LOG_DEBUG, "%s: Delete %s from StorageAddress %s", __PRETTY_FUNCTION__, guid, addr); - } - } - Modify(Recording_Delete, id).second->execute(); + auto dbc = db->get(); + logger->messagebf(LOG::INFO, "%s: Deleting recording Id: %d", __PRETTY_FUNCTION__, id); + auto del = P2PVR::sql::Recordings_delete.modify(dbc.get()); + del->bindParamI(0, id); + del->execute(); } P2PVR::RecordingList Recordings::GetRecordings(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(Recording_GetAll).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::Recordings_getAll); } diff --git a/p2pvr/daemon/recordings.h b/p2pvr/daemon/recordings.h index 482ce23..1182ff6 100644 --- a/p2pvr/daemon/recordings.h +++ b/p2pvr/daemon/recordings.h @@ -3,14 +3,20 @@ #include #include -#include "dbClient.h" #include +#include +#include -class DLL_PUBLIC Recordings : public DatabaseClient, public P2PVR::Recordings { +class DLL_PUBLIC Recordings : public P2PVR::Recordings, public IceTray::AbstractDatabaseClient { public: + Recordings(IceTray::DatabasePoolPtr db); + Ice::Int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &); void DeleteRecording(int recordingId, const Ice::Current &); P2PVR::RecordingList GetRecordings(const Ice::Current &); + + private: + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/resources.h b/p2pvr/daemon/resources.h deleted file mode 100644 index 18b1de2..0000000 --- a/p2pvr/daemon/resources.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef RESOURCES_H -#define RESOURCES_H - -#define ResourceString(name, resource) \ -extern "C" { \ - extern char resource##_start, resource##_end;\ - extern unsigned int resource##_len; \ -} \ -static const std::string name(&resource##_start, &resource##_end); - -#endif - diff --git a/p2pvr/daemon/schedulers/bitDumbScheduler.cpp b/p2pvr/daemon/schedulers/bitDumbScheduler.cpp index 1681103..10955e5 100644 --- a/p2pvr/daemon/schedulers/bitDumbScheduler.cpp +++ b/p2pvr/daemon/schedulers/bitDumbScheduler.cpp @@ -1,4 +1,3 @@ -#include #include "../schedules.h" class TheBitDumbScheduler : public EpisodeGroup { diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 90a42a9..f343e91 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -1,34 +1,35 @@ -#include #include "schedules.h" -#include #include #include -#include -#include -#include "p2Helpers.h" #include "commonHelpers.h" -#include "containerIterator.h" -#include "resources.h" #include #include #include #include #include +#include +#include #include -#include -ResourceString(Schedules_getCandidates, sql_Schedules_getCandidates); -ResourceString(Schedules_delete, sql_Schedules_delete); -ResourceString(Schedules_selectAll, sql_Schedules_selectAll); -ResourceString(Schedules_selectById, sql_Schedules_selectById); -ResourceString(Schedules_scheduledToRecord, sql_Schedules_scheduledToRecord); +#include "sql/Schedules_getCandidates.sql.h" +#include "sql/Schedules_delete.sql.h" +#include "sql/Schedules_selectAll.sql.h" +#include "sql/Schedules_selectById.sql.h" +#include "sql/Schedules_scheduledToRecord.sql.h" -std::string Schedules::SchedulerAlgorithm; +namespace po = boost::program_options; -DECLARE_OPTIONS(Schedules, "P2PVR Scheduler options") -("p2pvr.scheduler.algorithm", Options::value(&SchedulerAlgorithm, "BitDumb"), - "Implementation of episode group scheduler problem solver") -END_OPTIONS() +IceTray::Logging::LoggerPtr Schedules::logger(LOGMANAGER()->getLogger()); + +Schedules::Options::Options() : + IceTray::Options("P2PVR Scheduler options") +{ +} + +ICETRAY_OPTIONS(Schedules::Options, + ("p2pvr.scheduler.algorithm", po::value(&SchedulerAlgorithm)->default_value("BitDumb"), + "Implementation of episode group scheduler problem solver") +) Showing::Showing(unsigned int e, unsigned int t, unsigned int sc, datetime start, datetime stop, int p, const Episode * ep) : episode(ep), @@ -162,6 +163,11 @@ EpisodeGroup::SuggestWithFeedback(const Showings & showings) } } +Schedules::Schedules(IceTray::DatabasePoolPtr db) : + IceTray::AbstractDatabaseClient(db) +{ +} + void Schedules::GetEpisodeIntersects(Episodes & all, Episodes & grouped) { @@ -171,7 +177,7 @@ Schedules::GetEpisodeIntersects(Episodes & all, Episodes & grouped) for (const auto & gs : ge->showings) { for (const auto & as : ae->showings) { if (gs->period.intersects(as->period)) { - Logger()->messagebf(LOG_DEBUG, " added %s", ae->what); + logger->messagebf(LOG::DEBUG, " added %s", ae->what); grouped.push_back(ae); all.erase(aei); GetEpisodeIntersects(all, grouped); @@ -191,8 +197,7 @@ Schedules::DoReschedule(const Ice::Current & ice) unsigned int tunerCount = devs->TunerCount(); // Load list from database - auto episodes = Slicer::DeserializeAny( - *Select(Schedules_getCandidates).second); + auto episodes = fetch(P2PVR::sql::Schedules_getCandidates); Episodes scheduleList; Showings allShowings; @@ -209,9 +214,9 @@ Schedules::DoReschedule(const Ice::Current & ice) cur->showings.push_back(s); allShowings.push_back(s); } - Logger()->messagebf(LOG_DEBUG, "%d episodes created, %s showings", scheduleList.size(), allShowings.size()); + logger->messagebf(LOG::DEBUG, "%d episodes created, %s showings", scheduleList.size(), allShowings.size()); for (const auto & e : scheduleList) { - Logger()->messagebf(LOG_DEBUG, " %s", e->what); + logger->messagebf(LOG::DEBUG, " %s", e->what); for (const auto & s : e->showings) { s->priority += 1 - minPriority; e->priority += s->priority; @@ -223,7 +228,7 @@ Schedules::DoReschedule(const Ice::Current & ice) // Solve while (!scheduleList.empty()) { auto work = scheduleList.begin(); - Logger()->messagebf(LOG_DEBUG, "start %s", (*work)->what); + logger->messagebf(LOG::DEBUG, "start %s", (*work)->what); Episodes group; group.push_back(*work); scheduleList.erase(work); @@ -234,17 +239,17 @@ Schedules::DoReschedule(const Ice::Current & ice) return a->what < b->what; }); - Logger()->messagebf(LOG_DEBUG, "group created with %d episodes", group.size()); + logger->messagebf(LOG::DEBUG, "group created with %d episodes", group.size()); double total = 1; // Measure and add the optional to not record for (const auto & e : group) { - Logger()->messagebf(LOG_DEBUG, " %d * %d:%s", e->showings.size(), e->priority, e->what); + logger->messagebf(LOG::DEBUG, " %d * %d:%s", e->showings.size(), e->priority, e->what); e->showings.push_back(NULL); total *= e->showings.size(); } - Logger()->messagebf(LOG_DEBUG, "group complexity of %d options", total); + logger->messagebf(LOG::DEBUG, "group complexity of %d options", total); - EpisodeGroupPtr sched = EpisodeGroupPtr(EpisodeGroupFactory::createNew(SchedulerAlgorithm, group)); + EpisodeGroupPtr sched = EpisodeGroupPtr(EpisodeGroupFactory::createNew(options->SchedulerAlgorithm, group)); sched->tuners = tunerCount; std::set selected; for (const auto & s : sched->Solve()) { @@ -252,17 +257,17 @@ Schedules::DoReschedule(const Ice::Current & ice) } for (const auto & c : group) { - Logger()->messagebf(LOG_DEBUG, "Episode %s, %d options", c->what, c->showings.size()); + logger->messagebf(LOG::DEBUG, "Episode %s, %d options", c->what, c->showings.size()); for (const auto & i : c->showings) { if (selected.find(i) != selected.end()) { - Logger()->messagebf(LOG_DEBUG, " %s - %s (%d) <-", i->startTime, i->stopTime, i->transportStreamId); + logger->messagebf(LOG::DEBUG, " %s - %s (%d) <-", i->startTime, i->stopTime, i->transportStreamId); } else if (i) { - Logger()->messagebf(LOG_DEBUG, " %s - %s (%d)", i->startTime, i->stopTime, i->transportStreamId); + logger->messagebf(LOG::DEBUG, " %s - %s (%d)", i->startTime, i->stopTime, i->transportStreamId); } } } - Logger()->message(LOG_DEBUG, "----------"); + logger->message(LOG::DEBUG, "----------"); for (const auto & c : group) { bool found = false; for (const auto & i : c->showings) { @@ -282,14 +287,11 @@ Schedules::DoReschedule(const Ice::Current & ice) } } - TxHelper tx(this); - PrivateExecContext ec; - SqlMergeTask mergeRecords("postgres", "record"); - auto rcs = CreateColumns(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); - mergeRecords.sources.insert(new ContainerIterator(&records, rcs)); - mergeRecords.loadComplete(this); - mergeRecords.execute(&ec); - tx.Commit(); + auto dbc = db->get(); + DB::TransactionScope tx(dbc.get()); + DB::TablePatch mergeRecords; + mergeRecords.dest = "record"; + Slicer::SerializeAny(records, dbc.get(), mergeRecords); auto recorder = P2PVR::RecorderPrx::checkedCast(ice.adapter->createProxy(ice.adapter->getCommunicator()->stringToIdentity("Recorder"))); recorder->RefreshSchedules(); @@ -298,25 +300,25 @@ Schedules::DoReschedule(const Ice::Current & ice) void Schedules::DeleteSchedule(int id, const Ice::Current & ice) { - TxHelper tx(this); - Modify(Schedules_delete, id).second->execute(); + auto dbc = db->get(); + auto del = P2PVR::sql::Schedules_delete.modify(dbc.get()); + del->bindParamI(0, id); + del->execute(); DoReschedule(ice); } P2PVR::ScheduleList Schedules::GetSchedules(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(Schedules_selectAll).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::Schedules_selectAll); } P2PVR::SchedulePtr Schedules::GetSchedule(int id, const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - auto schedules = Slicer::DeserializeAny( - *Select(Schedules_selectById, id).second); + logger->messagebf(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + auto schedules = fetch(P2PVR::sql::Schedules_selectById, id); if (schedules.empty()) throw P2PVR::NotFound(); return schedules.front(); } @@ -324,16 +326,15 @@ Schedules::GetSchedule(int id, const Ice::Current &) P2PVR::ScheduledToRecordList Schedules::GetScheduledToRecord(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(Schedules_scheduledToRecord).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::Schedules_scheduledToRecord); } Ice::Int Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { - TxHelper tx(this); - Store(s, "schedules"); + auto dbc = db->get(); + Slicer::SerializeAny(s, dbc.get(), "schedules"); DoReschedule(ice); return s->ScheduleId; } @@ -341,8 +342,8 @@ Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) void Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { - TxHelper tx(this); - Store(s, "schedules"); + auto dbc = db->get(); + Slicer::SerializeAny(s, dbc.get(), "schedules"); DoReschedule(ice); } diff --git a/p2pvr/daemon/schedules.h b/p2pvr/daemon/schedules.h index 122e214..1acf69f 100644 --- a/p2pvr/daemon/schedules.h +++ b/p2pvr/daemon/schedules.h @@ -3,9 +3,11 @@ #include #include -#include "dbClient.h" +#include #include #include +#include +#include typedef boost::posix_time::ptime datetime; class Episode; @@ -62,8 +64,19 @@ class EpisodeGroup { Showings selected; }; -class DLL_PUBLIC Schedules : public P2PVR::Schedules, public DatabaseClient { +class DLL_PUBLIC Schedules : public P2PVR::Schedules, public IceTray::AbstractDatabaseClient { public: + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + std::string SchedulerAlgorithm; + }; + + Schedules(IceTray::DatabasePoolPtr); + void DeleteSchedule(int id, const Ice::Current &); P2PVR::SchedulePtr GetSchedule(int id, const Ice::Current &); P2PVR::ScheduleList GetSchedules(const Ice::Current &); @@ -72,12 +85,12 @@ class DLL_PUBLIC Schedules : public P2PVR::Schedules, public DatabaseClient { void UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &); void DoReschedule(const Ice::Current &); - INITOPTIONS; protected: static void GetEpisodeIntersects(Episodes &, Episodes &); private: - static std::string SchedulerAlgorithm; + IceTray::OptionsResolver options; + static IceTray::Logging::LoggerPtr logger; }; typedef AdHoc::Factory EpisodeGroupFactory; diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp index bff86fb..1186547 100644 --- a/p2pvr/daemon/si.cpp +++ b/p2pvr/daemon/si.cpp @@ -1,6 +1,4 @@ -#include #include "si.h" -#include "resources.h" #include #include #include @@ -8,36 +6,41 @@ #include #include -ResourceString(SI_allNetworks, sql_SI_allNetworks); -ResourceString(SI_allDeliveries, sql_SI_allDeliveries); -ResourceString(SI_deliveryForTransport, sql_SI_deliveryForTransport); -ResourceString(SI_deliveryForService, sql_SI_deliveryForService); -ResourceString(SI_serviceNextUsed, sql_SI_serviceNextUsed); -ResourceString(SI_servicesSelectAll, sql_SI_servicesSelectAll); -ResourceString(SI_servicesSelectById, sql_SI_servicesSelectById); -ResourceString(SI_eventByUid, sql_SI_eventByUid); -ResourceString(SI_eventById, sql_SI_eventById); -ResourceString(SI_eventsOnNow, sql_SI_eventsOnNow); -ResourceString(SI_eventsInSchedule, sql_SI_eventsInSchedule); -ResourceString(SI_eventsInSchedules, sql_SI_eventsInSchedules); -ResourceString(SI_eventsInRange, sql_SI_eventsInRange); -ResourceString(SI_eventSearch, sql_SI_eventSearch); +#include "sql/SI_allNetworks.sql.h" +#include "sql/SI_allDeliveries.sql.h" +#include "sql/SI_deliveryForTransport.sql.h" +#include "sql/SI_deliveryForService.sql.h" +#include "sql/SI_serviceNextUsed.sql.h" +#include "sql/SI_servicesSelectAll.sql.h" +#include "sql/SI_servicesSelectById.sql.h" +#include "sql/SI_eventByUid.sql.h" +#include "sql/SI_eventById.sql.h" +#include "sql/SI_eventsOnNow.sql.h" +#include "sql/SI_eventsInSchedule.sql.h" +#include "sql/SI_eventsInSchedules.sql.h" +#include "sql/SI_eventsInRange.sql.h" +#include "sql/SI_eventSearch.sql.h" + +IceTray::Logging::LoggerPtr SI::logger(LOGMANAGER()->getLogger()); + +SI::SI(IceTray::DatabasePoolPtr db) : + IceTray::AbstractDatabaseClient(db) +{ +} DVBSI::Networks SI::GetNetworks(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_allNetworks).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_allNetworks); } P2PVR::Deliveries SI::GetAllDeliveries(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - auto rtn = Slicer::DeserializeAny( - *Select(SI_allDeliveries).second, "delivery_type"); - Logger()->messagebf(LOG_DEBUG, "%s: Found %d delivery methods", __PRETTY_FUNCTION__, rtn.size()); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + auto rtn = fetch("delivery_type", P2PVR::sql::SI_allDeliveries); + logger->messagebf(LOG::DEBUG, "%s: Found %d delivery methods", __PRETTY_FUNCTION__, rtn.size()); return rtn; } @@ -45,9 +48,8 @@ DVBSI::DeliveryPtr SI::GetDeliveryForTransport(int id, const Ice::Current&) { try { - Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - return Slicer::DeserializeAny( - *Select(SI_deliveryForTransport, id).second, "delivery_type"); + logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + return fetch("delivery_type", P2PVR::sql::SI_deliveryForTransport, id); } catch (const Slicer::NoRowsReturned &) { throw P2PVR::NotFound(); @@ -58,9 +60,8 @@ DVBSI::DeliveryPtr SI::GetDeliveryForSi(const Ice::Current&) { try { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_serviceNextUsed).second, "delivery_type"); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch("delivery_type", P2PVR::sql::SI_serviceNextUsed); } catch (const Slicer::NoRowsReturned &) { return NULL; @@ -71,9 +72,8 @@ DVBSI::DeliveryPtr SI::GetDeliveryForService(int id, const Ice::Current&) { try { - Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - return Slicer::DeserializeAny( - *Select(SI_deliveryForService, id).second, "delivery_type"); + logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + return fetch("delivery_type", P2PVR::sql::SI_deliveryForService, id); } catch (const Slicer::NoRowsReturned &) { throw P2PVR::NotFound(); @@ -83,17 +83,15 @@ SI::GetDeliveryForService(int id, const Ice::Current&) DVBSI::ServiceList SI::GetServices(const Ice::Current&) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_servicesSelectAll).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_servicesSelectAll); } DVBSI::ServicePtr SI::GetService(int id, const Ice::Current&) { - Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - auto rtn = Slicer::DeserializeAny( - *Select(SI_servicesSelectById, id).second); + logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + auto rtn = fetch(P2PVR::sql::SI_servicesSelectById, id); if (rtn.empty()) throw P2PVR::NotFound(); return rtn.front(); } @@ -101,11 +99,10 @@ SI::GetService(int id, const Ice::Current&) P2PVR::Events SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); P2PVR::Events rtn; for (const auto & uid : eventUids) { - auto list = Slicer::DeserializeAny( - *Select(SI_eventByUid, uid).second); + auto list = fetch(P2PVR::sql::SI_eventByUid, uid); std::copy(list.begin(), list.end(), std::back_inserter(rtn)); } if (rtn.size() != eventUids.size()) throw P2PVR::NotFound(); @@ -115,9 +112,8 @@ SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &) P2PVR::EventPtr SI::GetEvent(int serviceId, int eventId, const Ice::Current &) { - Logger()->messagef(LOG_DEBUG, "%s(s=%d, e=%d)", __PRETTY_FUNCTION__, serviceId, eventId); - auto rtn = Slicer::DeserializeAny( - *Select(SI_eventById, serviceId, eventId).second); + logger->messagef(LOG::DEBUG, "%s(s=%d, e=%d)", __PRETTY_FUNCTION__, serviceId, eventId); + auto rtn = fetch(P2PVR::sql::SI_eventById, serviceId, eventId); if (rtn.empty()) throw P2PVR::NotFound(); return rtn.front(); } @@ -125,41 +121,49 @@ SI::GetEvent(int serviceId, int eventId, const Ice::Current &) P2PVR::Events SI::EventsOnNow(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_eventsOnNow).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_eventsOnNow); +} + +namespace IceTray { + template<> + void + AbstractDatabaseClient::bind1(int x, DB::Command * cmd, const Common::DateTime &); +} + +template<> +void +IceTray::AbstractDatabaseClient::bind1(int x, DB::Command * cmd, const Common::DateTime & dt) +{ + cmd->bindParamT(x, *dt); } P2PVR::Events SI::EventsInRange(const Common::DateTime & from, const Common::DateTime & to, const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s([%s]-[%s])", from, to, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_eventsInRange, from, to).second); + logger->messagebf(LOG::DEBUG, "%s([%s]-[%s])", from, to, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_eventsInRange, from, to); } P2PVR::Events SI::EventSearch(const IceUtil::Optional & keywords, const IceUtil::Optional & serviceId, const IceUtil::Optional & from, const IceUtil::Optional & to, const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s(keywords=%s,serviceId=%s,from=%s,to=%s)", + logger->messagebf(LOG::DEBUG, "%s(keywords=%s,serviceId=%s,from=%s,to=%s)", keywords, serviceId, from, to, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords).second); + return fetch(P2PVR::sql::SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords); } P2PVR::Events SI::EventsInSchedules(const Ice::Current &) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_eventsInSchedules).second); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_eventsInSchedules); } P2PVR::Events SI::EventsInSchedule(int scheduleId, const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__); - return Slicer::DeserializeAny( - *Select(SI_eventsInSchedule, scheduleId).second); + logger->messagebf(LOG::DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__); + return fetch(P2PVR::sql::SI_eventsInSchedule, scheduleId); } diff --git a/p2pvr/daemon/si.h b/p2pvr/daemon/si.h index 0e388a1..c9080ab 100644 --- a/p2pvr/daemon/si.h +++ b/p2pvr/daemon/si.h @@ -2,11 +2,14 @@ #define P2PVR_SI_H #include -#include "dbClient.h" +#include #include +#include -class DLL_PUBLIC SI : public P2PVR::SI, public DatabaseClient { +class DLL_PUBLIC SI : public P2PVR::SI, public IceTray::AbstractDatabaseClient { public: + SI(IceTray::DatabasePoolPtr); + DVBSI::Networks GetNetworks(const Ice::Current &); P2PVR::Deliveries GetAllDeliveries(const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &); @@ -23,6 +26,8 @@ class DLL_PUBLIC SI : public P2PVR::SI, public DatabaseClient { P2PVR::Events EventsInSchedule(int scheduleId, const Ice::Current &); P2PVR::Events EventsInRange(const Common::DateTime &, const Common::DateTime &, const Ice::Current &); P2PVR::Events EventSearch(const IceUtil::Optional & keywords, const IceUtil::Optional & serviceId, const IceUtil::Optional & from, const IceUtil::Optional & to, const Ice::Current &); + + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/storage.cpp b/p2pvr/daemon/storage.cpp index d43bddc..e443699 100644 --- a/p2pvr/daemon/storage.cpp +++ b/p2pvr/daemon/storage.cpp @@ -1,4 +1,3 @@ -#include #include "storage.h" #include "fileSink.h" #include "muxedFileSink.h" @@ -7,34 +6,39 @@ #include namespace fs = boost::filesystem; +namespace po = boost::program_options; -std::string Storage::muxerCommand; -fs::path Storage::root; +Storage::Options::Options() : + IceTray::Options("P2PVR Storage options") +{ +} -DECLARE_OPTIONS(Storage, "P2PVR Storage options") -("p2pvr.storage.muxercommand", Options::value(&muxerCommand, "/usr/bin/ffmpeg -i - -f mp4 -y ${TARGET}"), +ICETRAY_OPTIONS(Storage::Options, +("p2pvr.storage.muxercommand", po::value(&muxerCommand)->default_value("/usr/bin/ffmpeg -i - -f mp4 -y ${TARGET}"), "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -i - -f mp4 -y ${TARGET}')") -("p2pvr.storage.root", Options::value(&root, "recordings"), +("p2pvr.storage.root", po::value(&root)->default_value("recordings"), "Root folder in which to store recordings") -END_OPTIONS(Storage); +); + +IceTray::Logging::LoggerPtr Storage::logger(LOGMANAGER()->getLogger()); P2PVR::RawDataClientPrx Storage::OpenForWrite(const std::string & id, const Ice::Current & ice) { - fs::create_directories(root); - fs::path path = root / id; + fs::create_directories(options->root); + fs::path path = options->root / id; P2PVR::RawDataClient * target; - if (muxerCommand.empty()) { + if (options->muxerCommand.empty()) { auto fd = open(path.string().c_str(), O_WRONLY | O_CREAT | O_EXCL, 0664); if (fd < 0) { - Logger()->messagebf(LOG_ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, + logger->messagebf(LOG::ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); throw P2PVR::StorageException(path.string(), strerror(errno)); } target = new FileSink(fd); } else { - target = new MuxedFileSink(path, muxerCommand); + target = new MuxedFileSink(path, options->muxerCommand); } auto openFile = OpenFilePtr(new OpenFile(ice.adapter, target)); openFiles.insert(openFile); @@ -50,18 +54,18 @@ Storage::Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &) void Storage::Delete(const std::string & id, const Ice::Current &) { - fs::path path = root / id; - Logger()->messagebf(LOG_INFO, "%s: Deleting %s", __PRETTY_FUNCTION__, path); + fs::path path = options->root / id; + logger->messagebf(LOG::INFO, "%s: Deleting %s", __PRETTY_FUNCTION__, path); fs::remove(path); } void Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) { - fs::path path = root / id; + fs::path path = options->root / id; auto fd = open(path.string().c_str(), O_RDONLY | O_LARGEFILE); if (fd < 0) { - Logger()->messagebf(LOG_ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, + logger->messagebf(LOG::ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); throw P2PVR::StorageException(path.string(), strerror(errno)); } @@ -71,7 +75,7 @@ Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ic P2PVR::Data buf(16 * 1024); auto r = read(fd, &buf.front(), std::min(buf.size(), end - start)); if (r < 0) { - Logger()->messagebf(LOG_ERR, "%s: Failed to read file %s (%d:%s)", __PRETTY_FUNCTION__, + logger->messagebf(LOG::ERR, "%s: Failed to read file %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); close(fd); throw P2PVR::StorageException(path.string(), strerror(errno)); @@ -88,7 +92,7 @@ Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ic Ice::Long Storage::FileSize(const std::string & id, const Ice::Current &) { - fs::path path = root / id; + fs::path path = options->root / id; try { return fs::file_size(path); } diff --git a/p2pvr/daemon/storage.h b/p2pvr/daemon/storage.h index 982c3fd..d66a5d3 100644 --- a/p2pvr/daemon/storage.h +++ b/p2pvr/daemon/storage.h @@ -4,28 +4,37 @@ #include #include #include +#include #include #include "temporaryIceAdapterObject.h" #include +#include class DLL_PUBLIC Storage : public P2PVR::Storage { public: + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + std::string muxerCommand; + boost::filesystem::path root; + }; + P2PVR::RawDataClientPrx OpenForWrite(const std::string &, const Ice::Current &) override; void Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &) override; void Delete(const std::string &, const Ice::Current &) override; Ice::Long FileSize(const std::string &, const Ice::Current &) override; void Send(const std::string &, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) override; - INITOPTIONS; - protected: typedef TemporaryIceAdapterObject OpenFile; typedef boost::shared_ptr OpenFilePtr; typedef std::set OpenFiles; OpenFiles openFiles; - - static std::string muxerCommand; - static boost::filesystem::path root; + IceTray::OptionsResolver options; + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index 252dd89..bb39bbb 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -4,11 +4,15 @@ lib boost_system ; lib boost_filesystem ; lib IceUtil ; lib Ice ; +lib IceBox ; +lib dbppcore : : : : /usr/include/dbpp ; lib dbpp-postgresql : : : : /usr/include/dbpp-postgresql ; +lib dryice : : : : /usr/include/icetray ; path-constant me : . ; alias test-data : + ../../datasources/schema.sql datasources/data.sql datasources/delivery_dvbc datasources/delivery_dvbs @@ -24,204 +28,75 @@ alias test-data : ; lib testCommon : - mockDefs.cpp + [ glob mock*.cpp ] : - dbpp-postgresql - ../..//p2sql - ../..//p2common - ../..//adhocutil - ../..//p2ut ROOT=\"$(me)\" - boost_system - boost_filesystem - ; - -run - testEmbedding.cpp - dummySelect.sql - : : : - BOOST_TEST_DYN_LINK - ../..//boost_utf - .. - : testEmbedding ; - -run - testMaint.cpp mockDevices.cpp mockScheduler.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - ../../devices//p2pvrMockTuner - IceUtil + dryice Ice + IceUtil + IceBox + dbppcore + dbpp-postgresql + ../../devices//p2pvrMockTuner boost_system boost_filesystem - testCommon - ../..//boost_utf - test-data - ROOT=\"$(me)\" - : testMaint ; - -run - testRecording.cpp mockDevices.cpp mockScheduler.cpp + ../../ice + ../../ice : : - ../../datasources/schema.sql - : + ROOT=\"$(me)\" BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - ../../devices//p2pvrMockTuner - IceUtil + dryice + ../..//icetray + dbppcore + dbpp-postgresql Ice + IceBox + IceUtil boost_system boost_filesystem - testCommon ../..//boost_utf + ../../devices//p2pvrMockTuner + ..//p2pvrdaemon test-data - ROOT=\"$(me)\" - : testRecording ; + ; run - testErrorHandling.cpp mockDevices.cpp mockScheduler.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics - ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - ../../devices//p2pvrMockTuner - ../../dvb//p2pvrdvb - IceUtil - Ice - boost_system - boost_filesystem + testMaint.cpp + : : : testCommon - ../..//boost_utf - test-data - ROOT=\"$(me)\" - : testErrorHandling ; + : testMaint ; -run - testRecordings.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics - ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - IceUtil - Ice - boost_system - boost_filesystem +run testRecording.cpp + : : : testCommon - ../..//boost_utf - test-data - ROOT=\"$(me)\" - : testRecordings ; + ; -run - testSi.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics - ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - IceUtil - Ice - boost_system - boost_filesystem +run testErrorHandling.cpp + : : : testCommon - ../..//boost_utf - test-data - ROOT=\"$(me)\" - : testSi ; + ../../dvb//p2pvrdvb + ; -run - testSched.cpp mockDevices.cpp mockRecorder.cpp - : : - ../../datasources/schema.sql - datasources/eventOffset.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics - ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - IceUtil - Ice - boost_system - boost_filesystem - ../../devices//p2pvrMockTuner - ../..//boost_utf +run testRecordings.cpp + : : : testCommon - test-data - ROOT=\"$(me)\" - : testSched ; + ; -run - testStorage.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2basics - ../..//adhocutil - ../..//p2xml - ../..//p2ut - ..//p2pvrdaemon - IceUtil - Ice - boost_system - boost_filesystem +run testSi.cpp + : : : testCommon - ../..//boost_utf - test-data - ROOT=\"$(me)\" - : testStorage ; + ; -run - testSqlSelectDeserializer.cpp - : : - ../../datasources/schema.sql - : - BOOST_TEST_DYN_LINK - ../..//p2common - ../..//p2sql - ../..//p2ut - ../..//p2xml - ..//p2pvrdaemon - IceUtil - Ice - ../..//boost_utf +run testSched.cpp + : : : testCommon - ..//slicer-db - test-data - ROOT=\"$(me)\" - : testSqlSelectDeserializer ; + datasources/eventOffset.sql + ; + +run testStorage.cpp + : : : + testCommon + ; diff --git a/p2pvr/daemon/unittests/datasources/postgres.xml b/p2pvr/daemon/unittests/datasources/postgres.xml deleted file mode 100644 index 363572d..0000000 --- a/p2pvr/daemon/unittests/datasources/postgres.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/p2pvr/daemon/unittests/dummySelect.sql b/p2pvr/daemon/unittests/dummySelect.sql deleted file mode 100644 index 3f9397b..0000000 --- a/p2pvr/daemon/unittests/dummySelect.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT stuff FROM things diff --git a/p2pvr/daemon/unittests/mockDefs.cpp b/p2pvr/daemon/unittests/mockDefs.cpp index 8c44b9a..d810719 100644 --- a/p2pvr/daemon/unittests/mockDefs.cpp +++ b/p2pvr/daemon/unittests/mockDefs.cpp @@ -22,3 +22,15 @@ StandardMockDatabasePlusOffset::StandardMockDatabasePlusOffset() : { } +TestClient::TestClient() : + localDevices(getProxy("Devices")), + devices(getProxy("GlobalDevices")), + maint(getProxy("Maintenance")), + si(getProxy("SI")), + schedules(getProxy("Schedules")), + storage(getProxy("Storage")), + recorder(getProxy("Recorder")), + recordings(getProxy("Recordings")) +{ +} + diff --git a/p2pvr/daemon/unittests/mockDefs.h b/p2pvr/daemon/unittests/mockDefs.h index b16b47d..6675c2f 100644 --- a/p2pvr/daemon/unittests/mockDefs.h +++ b/p2pvr/daemon/unittests/mockDefs.h @@ -3,8 +3,10 @@ #include #include +#include +#include -#define DECLAREMOCK(Name) class DLL_PUBLIC Name : public PQ::Mock { public: Name(); } +#define DECLAREMOCK(Name) class DLL_PUBLIC Name : public PQ::Mock, public IceTray::DryIce { public: Name(); } DECLAREMOCK(SchemaOnlyMockDatabase); DECLAREMOCK(StandardMockDatabase); @@ -12,5 +14,19 @@ DECLAREMOCK(StandardMockDatabasePlusOffset); #undef DECLAREMOCK +class DLL_PUBLIC TestClient : public IceTray::DryIceClient { + public: + TestClient(); + + P2PVR::LocalDevicesPrx localDevices; + P2PVR::DevicesPrx devices; + P2PVR::MaintenancePrx maint; + P2PVR::SIPrx si; + P2PVR::SchedulesPrx schedules; + P2PVR::StoragePrx storage; + P2PVR::RecorderPrx recorder; + P2PVR::RecordingsPrx recordings; +}; + #endif diff --git a/p2pvr/daemon/unittests/mockDevices.h b/p2pvr/daemon/unittests/mockDevices.h index 195867e..f6e4c43 100644 --- a/p2pvr/daemon/unittests/mockDevices.h +++ b/p2pvr/daemon/unittests/mockDevices.h @@ -2,8 +2,9 @@ #define P2PVR_MOCKS_DEVICES_H #include +#include -class MockDevices : public P2PVR::Devices { +class DLL_PUBLIC MockDevices : public P2PVR::Devices { public: P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; diff --git a/p2pvr/daemon/unittests/mockRecorder.h b/p2pvr/daemon/unittests/mockRecorder.h index 85f747b..d76904d 100644 --- a/p2pvr/daemon/unittests/mockRecorder.h +++ b/p2pvr/daemon/unittests/mockRecorder.h @@ -2,8 +2,9 @@ #define P2PVR_MOCKS_RECORDER_H #include +#include -class MockRecorder : public P2PVR::Recorder { +class DLL_PUBLIC MockRecorder : public P2PVR::Recorder { public: void RefreshSchedules(const Ice::Current &) override; }; diff --git a/p2pvr/daemon/unittests/mockScheduler.h b/p2pvr/daemon/unittests/mockScheduler.h index e90567b..c3640f6 100644 --- a/p2pvr/daemon/unittests/mockScheduler.h +++ b/p2pvr/daemon/unittests/mockScheduler.h @@ -2,8 +2,9 @@ #define P2PVR_MOCKS_SCHEDULER_H #include +#include -class MockScheduler : public P2PVR::Schedules { +class DLL_PUBLIC MockScheduler : public P2PVR::Schedules { public: void DoReschedule(const ::Ice::Current&) override; void DeleteSchedule(Ice::Int, const Ice::Current&) override; diff --git a/p2pvr/daemon/unittests/testEmbedding.cpp b/p2pvr/daemon/unittests/testEmbedding.cpp deleted file mode 100644 index b0e01f1..0000000 --- a/p2pvr/daemon/unittests/testEmbedding.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#define BOOST_TEST_MODULE embedding -#include - -#include "resources.h" - -ResourceString(DummySql, sql_dummySelect); - -BOOST_AUTO_TEST_CASE( embed ) -{ - BOOST_REQUIRE_EQUAL(25, DummySql.length()); - BOOST_REQUIRE_EQUAL(sql_dummySelect_len, DummySql.length()); - BOOST_REQUIRE_EQUAL("SELECT stuff FROM things\n", DummySql); -} - diff --git a/p2pvr/daemon/unittests/testErrorHandling.cpp b/p2pvr/daemon/unittests/testErrorHandling.cpp index c4ea88d..b04c78c 100644 --- a/p2pvr/daemon/unittests/testErrorHandling.cpp +++ b/p2pvr/daemon/unittests/testErrorHandling.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE ErrorHandling #include #include -#include +#include #include #include #include @@ -15,46 +15,16 @@ #include #include #include "mockDefs.h" -#include -class Core : public TestAppInstance { +class Core : public StandardMockDatabase { public: Core() { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12006"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->activate(); - - s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); - BOOST_REQUIRE(s); - s->ice_ping(); - - d = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("GlobalDevices")); - BOOST_REQUIRE(d); - d->ice_ping(); + replace("GlobalDevices", new MockDevices()); } - - ~Core() - { - ic->destroy(); - } - - P2PVR::DevicesPrx d; - P2PVR::SIPrx s; - - protected: - Ice::ObjectAdapterPtr adapter; - private: - Ice::CommunicatorPtr ic; }; -class TestClient : public P2PVR::RawDataClient { +class TestDataClient : public P2PVR::RawDataClient { public: virtual bool NewData(const P2PVR::Data &, const Ice::Current &) override { @@ -86,16 +56,16 @@ class FailingTestNetworkParser : public SiNetworkInformationParser { } }; -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE( Core ); -BOOST_FIXTURE_TEST_SUITE(ErrorHandling, Core) +BOOST_FIXTURE_TEST_SUITE(ErrorHandling, TestClient) BOOST_AUTO_TEST_CASE(TestRawDataClient) { BOOST_TEST_CHECKPOINT("Setup"); - auto del = s->GetDeliveryForSi(); - auto gd = d->GetTunerAny(del); - TemporaryIceAdapterObject a(adapter, new TestClient()); + auto del = si->GetDeliveryForSi(); + auto gd = devices->GetTunerAny(del); + TemporaryIceAdapterObject a(getAdapter(), new TestDataClient()); BOOST_TEST_CHECKPOINT("Make successful call"); gd->SendNetworkInformation(a); } @@ -103,9 +73,9 @@ BOOST_AUTO_TEST_CASE(TestRawDataClient) BOOST_AUTO_TEST_CASE(TestParser) { BOOST_TEST_CHECKPOINT("Setup"); - auto del = s->GetDeliveryForSi(); - auto gd = d->GetTunerAny(del); - TemporaryIceAdapterObject a(adapter, new TestNetworkParser()); + auto del = si->GetDeliveryForSi(); + auto gd = devices->GetTunerAny(del); + TemporaryIceAdapterObject a(getAdapter(), new TestNetworkParser()); BOOST_TEST_CHECKPOINT("Make successful call"); gd->SendNetworkInformation(a); } @@ -113,9 +83,9 @@ BOOST_AUTO_TEST_CASE(TestParser) BOOST_AUTO_TEST_CASE(TestRawDataClientWithError) { BOOST_TEST_CHECKPOINT("Setup"); - auto del = s->GetDeliveryForSi(); - auto gd = d->GetTunerAny(del); - TemporaryIceAdapterObject a(adapter, new FailingTestClient()); + auto del = si->GetDeliveryForSi(); + auto gd = devices->GetTunerAny(del); + TemporaryIceAdapterObject a(getAdapter(), new FailingTestClient()); BOOST_TEST_CHECKPOINT("Make failing call"); BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); } @@ -123,9 +93,9 @@ BOOST_AUTO_TEST_CASE(TestRawDataClientWithError) BOOST_AUTO_TEST_CASE(TestParserWithError) { BOOST_TEST_CHECKPOINT("Setup"); - auto del = s->GetDeliveryForSi(); - auto gd = d->GetTunerAny(del); - TemporaryIceAdapterObject a(adapter, new FailingTestNetworkParser()); + auto del = si->GetDeliveryForSi(); + auto gd = devices->GetTunerAny(del); + TemporaryIceAdapterObject a(getAdapter(), new FailingTestNetworkParser()); BOOST_TEST_CHECKPOINT("Make failing call"); BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); } diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp index a86ff78..e02abae 100644 --- a/p2pvr/daemon/unittests/testMaint.cpp +++ b/p2pvr/daemon/unittests/testMaint.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -17,54 +17,19 @@ #include #include "commonHelpers.h" #include -#include -class Core : public CommonObjects, public TestAppInstance { +class TestService : public SchemaOnlyMockDatabase { public: - Core() + TestService() { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); - adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules")); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->add(new Recordings(), ic->stringToIdentity("Recordings")); - adapter->add(new Maintenance(adapter, NULL), ic->stringToIdentity("Maintenance")); - adapter->activate(); - - r = P2PVR::RecordingsPrx::checkedCast(ic->stringToProxy("Recordings")); - BOOST_REQUIRE(r); - r->ice_ping(); - - s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); - BOOST_REQUIRE(s); - s->ice_ping(); - - m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance")); - BOOST_REQUIRE(m); - m->ice_ping(); + replace("GlobalDevices", new MockDevices()); + replace("Schedules", new MockScheduler()); } - - ~Core() - { - ic->destroy(); - } - - P2PVR::MaintenancePrx m; - P2PVR::RecordingsPrx r; - P2PVR::SIPrx s; - - private: - Ice::CommunicatorPtr ic; }; -BOOST_GLOBAL_FIXTURE( SchemaOnlyMockDatabase ); +BOOST_GLOBAL_FIXTURE( TestService ); -BOOST_FIXTURE_TEST_SUITE( MaintCore, Core ); +BOOST_FIXTURE_TEST_SUITE( MaintCore, TestClient ); const int serviceId = 4170; const int transportId = 20544; @@ -72,47 +37,47 @@ const int eventId1 = 31; const int eventId2 = 915; // -// Run all these tests when there's no data +// Run all these tests when there'si no data // This tests behaviour from clean startup/fresh install // BOOST_AUTO_TEST_CASE( GetNetworks_emptySet ) { - BOOST_REQUIRE(s->GetNetworks().empty()); + BOOST_REQUIRE(si->GetNetworks().empty()); } BOOST_AUTO_TEST_CASE( GetAllDeliveries_emptySet ) { - BOOST_REQUIRE(s->GetAllDeliveries().empty()); + BOOST_REQUIRE(si->GetAllDeliveries().empty()); } BOOST_AUTO_TEST_CASE( GetDeliveryForService_notFound ) { - BOOST_REQUIRE_THROW(s->GetDeliveryForService(serviceId), P2PVR::NotFound); + BOOST_REQUIRE_THROW(si->GetDeliveryForService(serviceId), P2PVR::NotFound); } BOOST_AUTO_TEST_CASE( GetDeliveryForTransport_notFound ) { - BOOST_REQUIRE_THROW(s->GetDeliveryForTransport(transportId), P2PVR::NotFound); + BOOST_REQUIRE_THROW(si->GetDeliveryForTransport(transportId), P2PVR::NotFound); } BOOST_AUTO_TEST_CASE( GetDeliveryForSi_null ) { - BOOST_REQUIRE_EQUAL(s->GetDeliveryForSi(), DVBSI::DeliveryPtr()); + BOOST_REQUIRE_EQUAL(si->GetDeliveryForSi(), DVBSI::DeliveryPtr()); } BOOST_AUTO_TEST_CASE( GetServices_emptySet ) { - BOOST_REQUIRE(s->GetServices().empty()); + BOOST_REQUIRE(si->GetServices().empty()); } BOOST_AUTO_TEST_CASE( GetService_notFound ) { - BOOST_REQUIRE_THROW(s->GetService(serviceId), P2PVR::NotFound); + BOOST_REQUIRE_THROW(si->GetService(serviceId), P2PVR::NotFound); } BOOST_AUTO_TEST_CASE( GetSpecificEvents_notFound ) { - BOOST_REQUIRE_THROW(s->GetEvents({ eventId1, eventId2 }), P2PVR::NotFound); + BOOST_REQUIRE_THROW(si->GetEvents({ eventId1, eventId2 }), P2PVR::NotFound); } // @@ -121,12 +86,12 @@ BOOST_AUTO_TEST_CASE( GetSpecificEvents_notFound ) BOOST_AUTO_TEST_CASE( update_network ) { - m->UpdateNetwork(FE_OFDM); + maint->UpdateNetwork(FE_OFDM); } BOOST_AUTO_TEST_CASE( GetNetworks ) { - auto ns = s->GetNetworks(); + auto ns = si->GetNetworks(); BOOST_REQUIRE_EQUAL(ns.size(), 1); BOOST_REQUIRE_EQUAL(ns[0]->NetworkId, 12333); BOOST_REQUIRE_EQUAL(ns[0]->Name, "Yorkshire"); @@ -134,7 +99,7 @@ BOOST_AUTO_TEST_CASE( GetNetworks ) BOOST_AUTO_TEST_CASE( GetDeliveryForService ) { - auto del = s->GetDeliveryForService(serviceId); + auto del = si->GetDeliveryForService(serviceId); BOOST_REQUIRE(del); BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery"); BOOST_REQUIRE_EQUAL(del->Frequency, 682000000); @@ -142,7 +107,7 @@ BOOST_AUTO_TEST_CASE( GetDeliveryForService ) BOOST_AUTO_TEST_CASE( GetDeliveryForTransport ) { - auto del = s->GetDeliveryForTransport(transportId); + auto del = si->GetDeliveryForTransport(transportId); BOOST_REQUIRE(del); BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery"); BOOST_REQUIRE_EQUAL(del->Frequency, 722000000); @@ -150,7 +115,7 @@ BOOST_AUTO_TEST_CASE( GetDeliveryForTransport ) BOOST_AUTO_TEST_CASE( GetServices_stubs ) { - auto services = s->GetServices(); + auto services = si->GetServices(); BOOST_REQUIRE_EQUAL(services.size(), 145); BOOST_REQUIRE_EQUAL(services[0]->ServiceId, 4170); BOOST_REQUIRE_EQUAL(services[0]->TransportStreamId, 4170); @@ -160,7 +125,7 @@ BOOST_AUTO_TEST_CASE( GetServices_stubs ) BOOST_AUTO_TEST_CASE( GetService_stubs ) { - auto service = s->GetService(serviceId); + auto service = si->GetService(serviceId); BOOST_REQUIRE_EQUAL(service->ServiceId, serviceId); // Definitely a stub BOOST_REQUIRE(!service->Name); @@ -168,7 +133,7 @@ BOOST_AUTO_TEST_CASE( GetService_stubs ) BOOST_AUTO_TEST_CASE( GetDeliveryForSi_any ) { - auto del = s->GetDeliveryForSi(); + auto del = si->GetDeliveryForSi(); BOOST_REQUIRE(del); // Any yes, but is our case it should be DVB-T BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery"); @@ -177,7 +142,7 @@ BOOST_AUTO_TEST_CASE( GetDeliveryForSi_any ) BOOST_AUTO_TEST_CASE( UpdateNetwork_prepopulated ) { // This should now run using existing transport data (although this test doesn't prove that) - m->UpdateNetwork(FE_OFDM); + maint->UpdateNetwork(FE_OFDM); } // @@ -186,12 +151,12 @@ BOOST_AUTO_TEST_CASE( UpdateNetwork_prepopulated ) // BOOST_AUTO_TEST_CASE( update_services ) { - m->UpdateServices(); + maint->UpdateServices(); } BOOST_AUTO_TEST_CASE( GetServices ) { - auto services = s->GetServices(); + auto services = si->GetServices(); BOOST_REQUIRE_EQUAL(services.size(), 145); BOOST_REQUIRE_EQUAL(services[0]->ServiceId, 4170); BOOST_REQUIRE_EQUAL(services[0]->TransportStreamId, 4170); @@ -201,7 +166,7 @@ BOOST_AUTO_TEST_CASE( GetServices ) BOOST_AUTO_TEST_CASE( GetService ) { - auto service = s->GetService(serviceId); + auto service = si->GetService(serviceId); BOOST_REQUIRE_EQUAL(service->ServiceId, serviceId); BOOST_REQUIRE_EQUAL(service->TransportStreamId, 4170); BOOST_REQUIRE_EQUAL(service->Name, "BBC ONE Yorks"); @@ -211,20 +176,20 @@ BOOST_AUTO_TEST_CASE( GetService ) BOOST_AUTO_TEST_CASE( update_events ) { BOOST_TEST_CHECKPOINT("Get a DB connection for faking stuff"); - auto db = this->dataSource("postgres")->getReadonly(); // Naughty, but don't want txs + auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("postgres")); BOOST_TEST_CHECKPOINT("Write first events"); MockTuner::SetEventsSet(0); - m->UpdateEvents(); - auto dayOneEvents = s->EventSearch(IceUtil::Optional(), IceUtil::Optional(), + maint->UpdateEvents(); + auto dayOneEvents = si->EventSearch(IceUtil::Optional(), IceUtil::Optional(), Common::DateTime {2014, 12, 18, 3, 0}, Common::DateTime {2014, 12, 19, 3, 0}); BOOST_REQUIRE_EQUAL(dayOneEvents.size(), 3345); - BOOST_REQUIRE(s->GetEvent(14448, 27052)); - BOOST_REQUIRE_THROW(s->GetEvent(15856, 3591), P2PVR::NotFound); + BOOST_REQUIRE(si->GetEvent(14448, 27052)); + BOOST_REQUIRE_THROW(si->GetEvent(15856, 3591), P2PVR::NotFound); BOOST_TEST_CHECKPOINT("Fake some recorded stuff"); - auto keyEvent1 = s->GetEvent(25664, 55689); - auto keyEvent2 = s->GetEvent(24256, 1014); + auto keyEvent1 = si->GetEvent(25664, 55689); + auto keyEvent2 = si->GetEvent(24256, 1014); db->execute("INSERT INTO schedules(repeats) VALUES(false)"); auto irecorded = boost::shared_ptr( db->newModifyCommand("INSERT INTO recorded(scheduleId, eventUid) VALUES(?, ?)")); @@ -245,12 +210,12 @@ BOOST_AUTO_TEST_CASE( update_events ) BOOST_TEST_CHECKPOINT("Write second events"); MockTuner::SetEventsSet(1); - m->UpdateEvents(); - BOOST_REQUIRE_THROW(s->GetEvent(14448, 27052), P2PVR::NotFound); - BOOST_REQUIRE(s->GetEvent(15856, 3591)); + maint->UpdateEvents(); + BOOST_REQUIRE_THROW(si->GetEvent(14448, 27052), P2PVR::NotFound); + BOOST_REQUIRE(si->GetEvent(15856, 3591)); BOOST_TEST_CHECKPOINT("Check our faked stuff is still there and right"); - auto dayOneEventsOnDayTwo = s->EventSearch(IceUtil::Optional(), IceUtil::Optional(), + auto dayOneEventsOnDayTwo = si->EventSearch(IceUtil::Optional(), IceUtil::Optional(), Common::DateTime {2014, 12, 18, 3, 0}, Common::DateTime {2014, 12, 19, 3, 0}); // Some datetime range overlap, but most are gone BOOST_REQUIRE_EQUAL(dayOneEventsOnDayTwo.size(), 373); @@ -258,7 +223,7 @@ BOOST_AUTO_TEST_CASE( update_events ) [](const P2PVR::EventPtr & e) { return (e->ServiceId == 25664 && e->EventId == 55689) || (e->ServiceId == 24256 && e->EventId == 1014); }), 0); - auto keyEventsOnDayTwo = s->GetEvents({keyEvent1->EventUid, keyEvent2->EventUid}); + auto keyEventsOnDayTwo = si->GetEvents({keyEvent1->EventUid, keyEvent2->EventUid}); BOOST_REQUIRE_EQUAL(keyEventsOnDayTwo.size(), 2); BOOST_REQUIRE(!keyEventsOnDayTwo[0]->Current); BOOST_REQUIRE(!keyEventsOnDayTwo[1]->Current); @@ -269,7 +234,7 @@ BOOST_AUTO_TEST_CASE( update_events ) BOOST_AUTO_TEST_CASE( test_titleFiltering ) { - auto thingsWithNew = s->EventSearch("new", IceUtil::Optional(), + auto thingsWithNew = si->EventSearch("new", IceUtil::Optional(), IceUtil::Optional(), IceUtil::Optional()); BOOST_REQUIRE_EQUAL(0, std::count_if(thingsWithNew.begin(), thingsWithNew.end(), [](auto e) { return boost::algorithm::starts_with(e->Title, "New:"); diff --git a/p2pvr/daemon/unittests/testRecording.cpp b/p2pvr/daemon/unittests/testRecording.cpp index 2ce4080..ca15447 100644 --- a/p2pvr/daemon/unittests/testRecording.cpp +++ b/p2pvr/daemon/unittests/testRecording.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE Recording #include #include -#include +#include #include #include #include @@ -18,50 +18,14 @@ #include "serviceStreamer.h" #include "temporaryIceAdapterObject.h" #include -#include -class Core : public CommonObjects, public TestAppInstance { +class TestService : public StandardMockDatabase { public: - Core() + TestService() { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12005"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); - adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules")); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->add(new Recordings(), ic->stringToIdentity("Recordings")); - adapter->add(new Maintenance(adapter, NULL), ic->stringToIdentity("Maintenance")); - adapter->activate(); - - r = P2PVR::RecordingsPrx::checkedCast(ic->stringToProxy("Recordings")); - BOOST_REQUIRE(r); - r->ice_ping(); - - s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); - BOOST_REQUIRE(s); - s->ice_ping(); - - m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance")); - BOOST_REQUIRE(m); - m->ice_ping(); - } - - ~Core() - { - ic->destroy(); + replace("GlobalDevices", new MockDevices()); + replace("Schedules", new MockScheduler()); } - - P2PVR::MaintenancePrx m; - P2PVR::RecordingsPrx r; - P2PVR::SIPrx s; - - protected: - Ice::CommunicatorPtr ic; - Ice::ObjectAdapterPtr adapter; }; class MockTarget : public P2PVR::RawDataClient { @@ -77,18 +41,18 @@ class MockTarget : public P2PVR::RawDataClient { unsigned int bytesReceived; }; -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE( TestService ); -BOOST_FIXTURE_TEST_SUITE( RecordingCore, Core ); +BOOST_FIXTURE_TEST_SUITE( RecordingCore, TestClient ); BOOST_AUTO_TEST_CASE( streamServiceToTarget ) { BOOST_TEST_CHECKPOINT("Create mock target"); IceUtil::Handle target = new MockTarget(); - TemporaryIceAdapterObject targetPrx(adapter, target); + TemporaryIceAdapterObject targetPrx(getAdapter(), target); BOOST_TEST_CHECKPOINT("Create service streamer"); - auto ss = ServiceStreamerPtr(new ServiceStreamer(4170, targetPrx, ic, adapter)); + auto ss = ServiceStreamerPtr(new ServiceStreamer(4170, targetPrx, devices, si, getAdapter())); BOOST_TEST_CHECKPOINT("Start"); ss->Start(); diff --git a/p2pvr/daemon/unittests/testRecordings.cpp b/p2pvr/daemon/unittests/testRecordings.cpp index a0b88b5..de28c8b 100644 --- a/p2pvr/daemon/unittests/testRecordings.cpp +++ b/p2pvr/daemon/unittests/testRecordings.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE Recordings #include #include -#include +#include #include #include #include @@ -14,50 +14,14 @@ #include #include #include "mockDefs.h" -#include - -class Core : public TestAppInstance { - public: - Core() - { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12001"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new Recordings(), ic->stringToIdentity("Recordings")); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->activate(); - - r = P2PVR::RecordingsPrx::checkedCast(ic->stringToProxy("Recordings")); - BOOST_REQUIRE(r); - r->ice_ping(); - - si = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); - BOOST_REQUIRE(si); - si->ice_ping(); - } - - ~Core() - { - ic->destroy(); - } - - P2PVR::SIPrx si; - P2PVR::RecordingsPrx r; - - private: - Ice::CommunicatorPtr ic; -}; BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); -BOOST_FIXTURE_TEST_SUITE( RecCore, Core ) +BOOST_FIXTURE_TEST_SUITE( RecCore, TestClient ) BOOST_AUTO_TEST_CASE( recordings_get ) { - r->GetRecordings(); + recordings->GetRecordings(); } BOOST_AUTO_TEST_CASE( recordings_addAndDelete ) @@ -68,10 +32,10 @@ BOOST_AUTO_TEST_CASE( recordings_addAndDelete ) auto guid = boost::lexical_cast(boost::uuids::random_generator()()); auto rec = P2PVR::RecordingPtr(new P2PVR::Recording(0, "", guid, 0, event->EventUid)); - rec->RecordingId = r->NewRecording(rec); + rec->RecordingId = recordings->NewRecording(rec); BOOST_REQUIRE_EQUAL(218, rec->RecordingId); - r->GetRecordings(); - r->DeleteRecording(rec->RecordingId); + recordings->GetRecordings(); + recordings->DeleteRecording(rec->RecordingId); } BOOST_AUTO_TEST_SUITE_END() diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp index 45414aa..aab5102 100644 --- a/p2pvr/daemon/unittests/testSched.cpp +++ b/p2pvr/daemon/unittests/testSched.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE Scheduler #include #include -#include +#include #include #include #include @@ -16,46 +16,23 @@ #include #include #include "mockDefs.h" -#include -class Core : public TestAppInstance { +class TestService : public StandardMockDatabasePlusOffset { public: - Core() + TestService() { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12003"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new Schedules(), ic->stringToIdentity("Schedules")); - adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); - adapter->add(new MockRecorder(), ic->stringToIdentity("Recorder")); - adapter->activate(); - - sc = P2PVR::SchedulesPrx::checkedCast(ic->stringToProxy("Schedules")); - BOOST_REQUIRE(sc); - sc->ice_ping(); - } - - ~Core() - { - ic->destroy(); + replace("GlobalDevices", new MockDevices()); + replace("Recorder", new MockRecorder()); } - - P2PVR::SchedulesPrx sc; - - private: - Ice::CommunicatorPtr ic; }; -BOOST_GLOBAL_FIXTURE( StandardMockDatabasePlusOffset ); +BOOST_GLOBAL_FIXTURE( TestService ); -BOOST_FIXTURE_TEST_SUITE( ScCore, Core ) +BOOST_FIXTURE_TEST_SUITE( ScCore, TestClient ) BOOST_AUTO_TEST_CASE( sc_getSchedules ) { - auto ss = sc->GetSchedules(); + auto ss = schedules->GetSchedules(); BOOST_REQUIRE_EQUAL(ss.size(), 2); BOOST_REQUIRE(ss[0]->Search); BOOST_REQUIRE_EQUAL(*ss[0]->Search, "Top Gear"); @@ -65,12 +42,12 @@ BOOST_AUTO_TEST_CASE( sc_getSchedules ) BOOST_AUTO_TEST_CASE( sc_doReschedule ) { - sc->DoReschedule(); + schedules->DoReschedule(); } BOOST_AUTO_TEST_CASE( sc_getScheduled ) { - auto str = sc->GetScheduledToRecord(); + auto str = schedules->GetScheduledToRecord(); BOOST_REQUIRE_EQUAL(str.size(), 62); } @@ -79,10 +56,10 @@ BOOST_AUTO_TEST_CASE( sc_crud ) P2PVR::SchedulePtr schedule = new P2PVR::Schedule(); schedule->Search = "Top Gear"; - schedule->ScheduleId = sc->NewSchedule(schedule); + schedule->ScheduleId = schedules->NewSchedule(schedule); BOOST_REQUIRE_EQUAL(187, schedule->ScheduleId); - auto fetched = sc->GetSchedule(schedule->ScheduleId); + auto fetched = schedules->GetSchedule(schedule->ScheduleId); BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId); BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search); BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority); @@ -93,9 +70,9 @@ BOOST_AUTO_TEST_CASE( sc_crud ) schedule->Search = "Top Gear Special"; schedule->Early.Minutes = 5; schedule->Late.Minutes = 15; - sc->UpdateSchedule(schedule); + schedules->UpdateSchedule(schedule); - fetched = sc->GetSchedule(schedule->ScheduleId); + fetched = schedules->GetSchedule(schedule->ScheduleId); BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId); BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search); BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority); @@ -103,7 +80,7 @@ BOOST_AUTO_TEST_CASE( sc_crud ) BOOST_REQUIRE_EQUAL(schedule->Early, fetched->Early); BOOST_REQUIRE_EQUAL(schedule->Late, fetched->Late); - sc->DeleteSchedule(fetched->ScheduleId); + schedules->DeleteSchedule(fetched->ScheduleId); } BOOST_AUTO_TEST_SUITE_END() diff --git a/p2pvr/daemon/unittests/testSi.cpp b/p2pvr/daemon/unittests/testSi.cpp index 9e42e74..55998f9 100644 --- a/p2pvr/daemon/unittests/testSi.cpp +++ b/p2pvr/daemon/unittests/testSi.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE SI #include #include -#include +#include #include #include #include @@ -13,40 +13,10 @@ #include #include #include "mockDefs.h" -#include - -class Core : public TestAppInstance { - public: - Core() - { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12002"); - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - adapter->add(new SI(), ic->stringToIdentity("SI")); - adapter->activate(); - - si = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); - BOOST_REQUIRE(si); - si->ice_ping(); - } - - ~Core() - { - ic->destroy(); - } - - P2PVR::SIPrx si; - - private: - Ice::CommunicatorPtr ic; -}; BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); -BOOST_FIXTURE_TEST_SUITE( SiCore, Core ) +BOOST_FIXTURE_TEST_SUITE( SiCore, TestClient ) BOOST_AUTO_TEST_CASE ( si_getEvents ) { diff --git a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp deleted file mode 100644 index 47d36c5..0000000 --- a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#define BOOST_TEST_MODULE SqlSelectDeserializer -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mockDefs.h" -#include - -typedef boost::shared_ptr SelectPtr; - -class TestCommonObjects : public CommonObjects, public TestAppInstance { - public: - TestCommonObjects() - { - TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (rootDir / "datasources").string() }, - }); - } -}; - -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); - -BOOST_FIXTURE_TEST_SUITE ( Sql, TestCommonObjects ); - -BOOST_AUTO_TEST_CASE( listOfEvents ) -{ - auto db = dataSource("postgres")->getReadonly(); - auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 100")); - auto res = Slicer::DeserializeAny(*sel); - BOOST_REQUIRE_EQUAL(res.size(), 100); - BOOST_REQUIRE_EQUAL(res[0]->ServiceId, 4166); - BOOST_REQUIRE_EQUAL(res[0]->EventId, 49741); - BOOST_REQUIRE_EQUAL(res[0]->Title, "Skiing Weatherview"); - BOOST_REQUIRE(!res[0]->Subtitle); - BOOST_REQUIRE_EQUAL(res[0]->Description, "Detailed weather forecast."); - BOOST_REQUIRE_EQUAL(res[0]->StartTime, Common::DateTime({2014, 12, 19, 0, 25})); - BOOST_REQUIRE_EQUAL(res[0]->StopTime, Common::DateTime({2014, 12, 19, 0, 30})); - BOOST_REQUIRE(res[0]->Current); - BOOST_REQUIRE_EQUAL(res[99]->ServiceId, 4166); - BOOST_REQUIRE_EQUAL(res[99]->EventId, 52448); - BOOST_REQUIRE_EQUAL(res[99]->Title, "East Midlands Today"); -} - -BOOST_AUTO_TEST_CASE( singleField ) -{ - auto db = dataSource("postgres")->getReadonly(); - auto sel = SelectPtr(db->newSelectCommand("SELECT EventId FROM events ORDER BY serviceId, eventId LIMIT 1")); - auto res = Slicer::DeserializeAny(*sel); - BOOST_REQUIRE_EQUAL(res, 49741); -} - -BOOST_AUTO_TEST_CASE( singleEvent ) -{ - auto db = dataSource("postgres")->getReadonly(); - auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 1")); - auto res = Slicer::DeserializeAny(*sel); - BOOST_REQUIRE_EQUAL(res->ServiceId, 4166); - BOOST_REQUIRE_EQUAL(res->EventId, 49741); - BOOST_REQUIRE_EQUAL(res->Title, "Skiing Weatherview"); - BOOST_REQUIRE(!res->Subtitle); - BOOST_REQUIRE_EQUAL(res->Description, "Detailed weather forecast."); - BOOST_REQUIRE_EQUAL(res->StartTime, Common::DateTime({2014, 12, 19, 0, 25})); - BOOST_REQUIRE_EQUAL(res->StopTime, Common::DateTime({2014, 12, 19, 0, 30})); -} - -BOOST_AUTO_TEST_CASE( dynamicTypes ) -{ - auto db = dataSource("postgres")->getReadonly(); - auto sel = SelectPtr(db->newSelectCommand("SELECT d.*, '::DVBSI::TerrestrialDelivery' \"typeid\" FROM delivery_dvbt d ORDER BY TransportStreamId")); - auto res = Slicer::DeserializeAny(*sel, "typeid"); - BOOST_REQUIRE_EQUAL(res.size(), 6); - auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(res[0]); - BOOST_REQUIRE_EQUAL(dvbt->Frequency, 682000000); - BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170); - BOOST_REQUIRE_EQUAL(dvbt->CodeRateHP, 2); -} - -BOOST_AUTO_TEST_SUITE_END(); - diff --git a/p2pvr/daemon/unittests/testStorage.cpp b/p2pvr/daemon/unittests/testStorage.cpp index 973e93b..9e15662 100644 --- a/p2pvr/daemon/unittests/testStorage.cpp +++ b/p2pvr/daemon/unittests/testStorage.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE Storage #include #include -#include +#include #include #include #include @@ -10,73 +10,60 @@ #include #include #include -#include +#include +#include "mockDefs.h" -const boost::filesystem::path rootDir = "/tmp/ut/p2pvr/recordings"; -class Core : public TestAppInstance { +const boost::filesystem::path storageRootDir = "/tmp/ut/p2pvr/recordings"; +class TestService : public PQ::Mock, public IceTray::DryIce { public: - Core() + TestService() : + PQ::Mock("user=postgres dbname=postgres", "postgres", { + rootDir.parent_path().parent_path() / "datasources" / "schema.sql" }), + IceTray::DryIce({ + R"C(--p2pvr.storage.muxercommand="")C", + std::string("--p2pvr.storage.root=" + storageRootDir.string()), + }) { - int paramCount = 0; - ic = Ice::initialize(paramCount, NULL); - auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12004"); - TestOptionsSource::LoadTestOptions({ - { "p2pvr.storage.muxercommand", std::string() }, - { "p2pvr.storage.root", rootDir.string() }, - }); - adapter->add(new Storage(), ic->stringToIdentity("Storage")); - adapter->activate(); - - st = P2PVR::StoragePrx::checkedCast(ic->stringToProxy("Storage")); - BOOST_REQUIRE(st); - st->ice_ping(); } - - ~Core() - { - ic->destroy(); - } - - P2PVR::StoragePrx st; - - private: - Ice::CommunicatorPtr ic; }; -BOOST_FIXTURE_TEST_SUITE( StCore, Core ) +BOOST_GLOBAL_FIXTURE( TestService ); + +BOOST_FIXTURE_TEST_SUITE( StCore, TestClient ); BOOST_AUTO_TEST_CASE( st_openWriteClose ) { - boost::filesystem::remove_all(rootDir); + boost::filesystem::remove_all(storageRootDir); std::string id = "made-up-storage-id"; - auto rdc = st->OpenForWrite(id); + auto rdc = storage->OpenForWrite(id); + BOOST_REQUIRE(rdc); P2PVR::Data data; data.resize(1024); rdc->NewData(data); - st->Close(rdc); + storage->Close(rdc); - auto stSize = st->FileSize(id); + auto stSize = storage->FileSize(id); BOOST_REQUIRE_EQUAL(1024, stSize); - BOOST_REQUIRE_EQUAL(1024, boost::filesystem::file_size(rootDir / id)); + BOOST_REQUIRE_EQUAL(1024, boost::filesystem::file_size(storageRootDir / id)); - st->Delete(id); - BOOST_REQUIRE(!boost::filesystem::exists(rootDir / id)); + storage->Delete(id); + BOOST_REQUIRE(!boost::filesystem::exists(storageRootDir / id)); } BOOST_AUTO_TEST_CASE( st_notuniqueid ) { - boost::filesystem::remove_all(rootDir); + boost::filesystem::remove_all(storageRootDir); std::string id = "made-up-storage-id"; - auto rdc = st->OpenForWrite(id); - st->Close(rdc); + auto rdc = storage->OpenForWrite(id); + storage->Close(rdc); - BOOST_REQUIRE_THROW(st->OpenForWrite(id), P2PVR::StorageException); - st->Delete(id); + BOOST_REQUIRE_THROW(storage->OpenForWrite(id), P2PVR::StorageException); + storage->Delete(id); } BOOST_AUTO_TEST_SUITE_END() diff --git a/p2pvr/daemonbase/Jamfile.jam b/p2pvr/daemonbase/Jamfile.jam deleted file mode 100644 index f02a172..0000000 --- a/p2pvr/daemonbase/Jamfile.jam +++ /dev/null @@ -1,23 +0,0 @@ -lib boost_system ; -lib boost_filesystem ; - -cpp-pch pch : pch.hpp : - ..//p2common - ..//p2daemonlib - ../ice//p2pvrice -; - -lib p2pvrdaemonbase : - pch - [ glob-tree *.cpp ] - : - ..//p2common - ../lib//p2pvrlib - ../ice//p2pvrice - ..//adhocutil - ../ice//p2pvrice - : : - ../ice//p2pvrice - ..//p2daemonlib - . - ; diff --git a/p2pvr/daemonbase/daemonBase.cpp b/p2pvr/daemonbase/daemonBase.cpp deleted file mode 100644 index 4739498..0000000 --- a/p2pvr/daemonbase/daemonBase.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include "daemonBase.h" -#include "p2LoggerWrapper.h" -#include -#include - -std::string DaemonBase::Adapter; -std::string DaemonBase::Endpoint; - -DECLARE_OPTIONS(DaemonBase, "P2PVR Daemon") -("p2pvr.daemon.iceadapter", Options::value(&Adapter, "DefaultAdapter"), "ICE Adapter name") -("p2pvr.daemon.iceendpoint", Options::value(&Endpoint, "default -p 10000"), "ICE Endpoint address") -END_OPTIONS(DaemonBase); - -DaemonBase::DaemonBase(int argc, char ** argv) : - ic(Ice::initialize(args(argc, argv), initData())) -{ -} - -DaemonBase::~DaemonBase() -{ - ic->destroy(); -} - -void -DaemonBase::run() const -{ - IceUtil::TimerPtr timer = new IceUtil::Timer(); - Logger()->messagebf(LOG_INFO, "Creating adapter (%s, %s)", Adapter, Endpoint); - auto adapter = ic->createObjectAdapterWithEndpoints(Adapter, Endpoint); - addServants(adapter, timer); - adapter->activate(); - - ic->waitForShutdown(); - timer->destroy(); -} - -void -DaemonBase::shutdown() const -{ - ic->shutdown(); - ic->waitForShutdown(); -} - -Ice::InitializationData -DaemonBase::initData() -{ - Ice::InitializationData data; - data.logger = new P2LoggerWrapper(); - return data; -} - -Ice::StringSeq & -DaemonBase::args(int, char **) -{ - _args.clear(); - _args.push_back("--Ice.ThreadPool.Client.Size=5"); - _args.push_back("--Ice.ThreadPool.Server.Size=5"); - _args.push_back("--Ice.ThreadPool.Client.SizeMax=10"); - _args.push_back("--Ice.ThreadPool.Server.SizeMax=20"); - _args.push_back("--Ice.ThreadPool.Client.SizeWarn=8"); - _args.push_back("--Ice.ThreadPool.Server.SizeWarn=16"); - return _args; -} diff --git a/p2pvr/daemonbase/daemonBase.h b/p2pvr/daemonbase/daemonBase.h deleted file mode 100644 index 87e741b..0000000 --- a/p2pvr/daemonbase/daemonBase.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DAEMONBASE_H -#define DAEMONBASE_H - -#include -#include -#include -#include -#include - -class DLL_PUBLIC DaemonBase : public Daemon { - public: - DaemonBase(int argc, char ** argv); - ~DaemonBase(); - - void run() const; - void shutdown() const; - INITOPTIONS; - - protected: - virtual void addServants(const Ice::ObjectAdapterPtr &, const IceUtil::TimerPtr &) const = 0; - static Ice::InitializationData initData(); - Ice::StringSeq & args(int, char **); - - Ice::StringSeq _args; - Ice::CommunicatorPtr ic; - - static std::string Adapter; - static std::string Endpoint; -}; - -#endif - diff --git a/p2pvr/daemonbase/fileSink.cpp b/p2pvr/daemonbase/fileSink.cpp deleted file mode 100644 index dade921..0000000 --- a/p2pvr/daemonbase/fileSink.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include "fileSink.h" - -FileSink::FileSink(const boost::filesystem::path & path) : - file(fopen(path.string().c_str(), "w")) -{ -} - -FileSink::FileSink(int fd) : - file(fdopen(fd, "w")) -{ -} - -FileSink::~FileSink() -{ - if (file) { - fclose(file); - } -} - -bool -FileSink::NewData(const P2PVR::Data & data, const Ice::Current &) -{ - fwrite(&data.front(), data.size(), 1, file); - return false; -} - diff --git a/p2pvr/daemonbase/fileSink.h b/p2pvr/daemonbase/fileSink.h deleted file mode 100644 index fbd469c..0000000 --- a/p2pvr/daemonbase/fileSink.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef FILESINK_H -#define FILESINK_H - -#include -#include -#include -#include - -class DLL_PUBLIC FileSink : public P2PVR::RawDataClient { - public: - FileSink(const boost::filesystem::path & path); - FileSink(int fd); - ~FileSink(); - - bool NewData(const P2PVR::Data & data, const Ice::Current &); - - private: - FILE * const file; -}; - -#endif - diff --git a/p2pvr/daemonbase/p2LoggerWrapper.cpp b/p2pvr/daemonbase/p2LoggerWrapper.cpp deleted file mode 100644 index 419caa2..0000000 --- a/p2pvr/daemonbase/p2LoggerWrapper.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include "p2LoggerWrapper.h" -#include "logger.h" - -P2LoggerWrapper::P2LoggerWrapper(const std::string & p) : - prefix(p) -{ -} - -void -P2LoggerWrapper::print(const std::string & message) -{ - ::Logger()->messagebf(LOG_INFO, "%s: %s", prefix, message); -} - -void -P2LoggerWrapper::trace(const std::string & cat, const std::string & message) -{ - ::Logger()->messagebf(LOG_DEBUG, "%s: [%s] %s", prefix, cat, message); -} - -void -P2LoggerWrapper::warning(const std::string & message) -{ - ::Logger()->messagebf(LOG_WARNING, "%s: %s", prefix, message); -} - -void -P2LoggerWrapper::error(const std::string & message) -{ - ::Logger()->messagebf(LOG_ERR, "%s: %s", prefix, message); -} - -Ice::LoggerPtr -P2LoggerWrapper::cloneWithPrefix(const std::string & p) -{ - return new P2LoggerWrapper(prefix + "-" + p); -} - -std::string -P2LoggerWrapper::getPrefix() -{ - return prefix; -} - diff --git a/p2pvr/daemonbase/p2LoggerWrapper.h b/p2pvr/daemonbase/p2LoggerWrapper.h deleted file mode 100644 index 0d84683..0000000 --- a/p2pvr/daemonbase/p2LoggerWrapper.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef P2LOGGERWRAPPER -#define P2LOGGERWRAPPER - -#include -#include - -class DLL_PUBLIC P2LoggerWrapper : public Ice::Logger { - public: - P2LoggerWrapper(const std::string & prefix = std::string()); - - void print(const std::string & message) override; - void trace(const std::string & cat, const std::string & message) override; - void warning(const std::string & message) override; - void error(const std::string & message) override; - - Ice::LoggerPtr cloneWithPrefix(const std::string & prefix) override; - std::string getPrefix(); - - private: - const std::string prefix; -}; - - -#endif - diff --git a/p2pvr/daemonbase/pch.hpp b/p2pvr/daemonbase/pch.hpp deleted file mode 100644 index 74671ef..0000000 --- a/p2pvr/daemonbase/pch.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifdef BOOST_BUILD_PCH_ENABLED -#ifndef P2PVRLIB_PCH -#define P2PVRLIB_PCH - -#include - -#endif -#endif - diff --git a/p2pvr/datasources/postgres.xml b/p2pvr/datasources/postgres.xml deleted file mode 100644 index c538a8c..0000000 --- a/p2pvr/datasources/postgres.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/p2pvr/devices/Jamfile.jam b/p2pvr/devices/Jamfile.jam index f39256b..0379340 100644 --- a/p2pvr/devices/Jamfile.jam +++ b/p2pvr/devices/Jamfile.jam @@ -1,29 +1,23 @@ -import type ; -import generators ; +import type ; +import generators ; lib boost_system ; lib boost_thread ; lib boost_filesystem ; +lib boost_program_options ; lib lzma ; -cpp-pch pch : pch.hpp : - boost_system - boost_filesystem - ..//p2common - ../ice//p2pvrice -; - lib p2pvrdevices : - pch [ glob-tree *.cpp : mockTuner.cpp ] : boost_system boost_filesystem + boost_program_options ../dvb//p2pvrdvb ../ice//p2pvrice ../lib//p2pvrlib - ..//p2common ..//adhocutil + ..//icetray ../ice//p2pvrice : : boost_filesystem @@ -32,12 +26,12 @@ lib p2pvrdevices : . ; -type.register DATXZ : datxz ; +type.register DATXZ : datxz ; -generators.register-standard datxz.embed.asm : DATXZ : ASM ; +generators.register-standard datxz.embed.asm : DATXZ : ASM ; actions datxz.embed.asm -{ +{ m4 -DNAME="$(2:B)" -DPATH="$(2)" "$(root)/embed.m4" > "$(1)" } @@ -45,7 +39,6 @@ IMPORT $(__name__) : datxz.embed.asm : : datxz.embed.asm ; lib p2pvrMockTuner : - pch mockTuner.cpp [ glob-tree *.datxz ] : @@ -56,8 +49,8 @@ lib p2pvrMockTuner : ../dvb//p2pvrdvb ../ice//p2pvrice ../lib//p2pvrlib - ..//p2common ..//adhocutil + ..//icetray ../ice//p2pvrice : : boost_filesystem diff --git a/p2pvr/devices/frontend.cpp b/p2pvr/devices/frontend.cpp index 5b9280b..c1d2c61 100644 --- a/p2pvr/devices/frontend.cpp +++ b/p2pvr/devices/frontend.cpp @@ -1,15 +1,14 @@ -#include #include "frontend.h" #include "tuner.h" -#include #include #include #include -Frontend::Frontend(Tuner * t, int fd, const struct dvb_frontend_info & i) : +Frontend::Frontend(Tuner * t, int fd, const struct dvb_frontend_info & i, IceTray::Logging::LoggerPtr log) : tuner(t), frontendFD(fd), - fe_info(i) + fe_info(i), + logger(log) { } @@ -29,7 +28,7 @@ Frontend::GetStatus() const { fe_status_t status; if (ioctl(frontendFD, FE_READ_STATUS, &status) < 0) { - Logger()->messagebf(LOG_ERR, "Reading frontend %s status failed (%s:%d)", tuner->Device(), strerror(errno), errno); + logger->messagebf(LOG::ERR, "Reading frontend %s status failed (%s:%d)", tuner->Device(), strerror(errno), errno); throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno); } return status; diff --git a/p2pvr/devices/frontend.h b/p2pvr/devices/frontend.h index b68cdba..51399b1 100644 --- a/p2pvr/devices/frontend.h +++ b/p2pvr/devices/frontend.h @@ -4,13 +4,14 @@ #include #include #include +#include class Tuner; class Frontend { public: typedef boost::function OnFrequencyFound; - Frontend(Tuner *, int fd, const struct dvb_frontend_info &); + Frontend(Tuner *, int fd, const struct dvb_frontend_info &, IceTray::Logging::LoggerPtr); virtual ~Frontend(); fe_status_t GetStatus() const; @@ -25,6 +26,7 @@ class Frontend { const Tuner * tuner; const int frontendFD; const struct dvb_frontend_info fe_info; + IceTray::Logging::LoggerPtr logger; }; typedef AdHoc::Factory FrontendFactory; diff --git a/p2pvr/devices/frontends/ofdm.cpp b/p2pvr/devices/frontends/ofdm.cpp index cb174ba..caa42a6 100644 --- a/p2pvr/devices/frontends/ofdm.cpp +++ b/p2pvr/devices/frontends/ofdm.cpp @@ -1,8 +1,6 @@ -#include #include "../frontend.h" #include "../tuner.h" #include -#include #include #define FREQ_OFFSET_MIN 0 @@ -10,8 +8,11 @@ class Frontend_OFDM : public Frontend { public: - Frontend_OFDM(Tuner * t, int fd, const struct dvb_frontend_info & i) : Frontend(t, fd, i) { } - + Frontend_OFDM(Tuner * t, int fd, const struct dvb_frontend_info & i) : + Frontend(t, fd, i, LOGMANAGER()->getLogger()) + { + } + void TuneTo(const DVBSI::DeliveryPtr & mp) const { auto td = DVBSI::TerrestrialDeliveryPtr::dynamicCast(mp); @@ -38,7 +39,7 @@ class Frontend_OFDM : public Frontend { dvb_frontend_parameters feparams; memset(&feparams, 0, sizeof(dvb_frontend_parameters)); if (ioctl(frontendFD, FE_GET_FRONTEND, &feparams) < 0) { - Logger()->messagebf(LOG_ERR, "Reading frontend parameters failed (%s:%d)", tuner->Device(), strerror(errno), errno); + logger->messagebf(LOG::ERR, "Reading frontend parameters failed (%s:%d)", tuner->Device(), strerror(errno), errno); throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno); } return feparams; @@ -48,20 +49,20 @@ class Frontend_OFDM : public Frontend { { fe_status_t status = (fe_status_t)0; // Wait for something - for (int x = Tuner::TuningTimeout / 10; x > 0 && (status = GetStatus()) == 0; x -= 1) { + for (int x = tuner->options->TuningTimeout / 10; x > 0 && (status = GetStatus()) == 0; x -= 1) { usleep(10000); } // Was it useful? if (!(status & (FE_HAS_SIGNAL | FE_HAS_CARRIER))) { - Logger()->messagebf(LOG_ERR, "Tuning of device %s failed (No signal or carrier: 0x%02x)", tuner->Device(), status); + logger->messagebf(LOG::ERR, "Tuning of device %s failed (No signal or carrier: 0x%02x)", tuner->Device(), status); throw P2PVR::DeviceError(tuner->Device(), "No carrier", 0); } // Wait for lock - for (int x = Tuner::LockTimeout / 10; x > 0 && ((status = GetStatus()) & FE_HAS_LOCK) == 0; x -= 1) { + for (int x = tuner->options->LockTimeout / 10; x > 0 && ((status = GetStatus()) & FE_HAS_LOCK) == 0; x -= 1) { usleep(10000); } if (!(status & FE_HAS_LOCK)) { - Logger()->messagebf(LOG_ERR, "Tuning of device %s failed (%s)", tuner->Device(), "No lock"); + logger->messagebf(LOG::ERR, "Tuning of device %s failed (%s)", tuner->Device(), "No lock"); throw P2PVR::DeviceError(tuner->Device(), "No lock", 0); } } @@ -69,7 +70,7 @@ class Frontend_OFDM : public Frontend { void SetParameters(const dvb_frontend_parameters & feparams) const { if (ioctl(frontendFD, FE_SET_FRONTEND, &feparams) < 0) { - Logger()->messagebf(LOG_ERR, "Tuning of device %s failed (%s:%d)", tuner->Device(), strerror(errno), errno); + logger->messagebf(LOG::ERR, "Tuning of device %s failed (%s:%d)", tuner->Device(), strerror(errno), errno); throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno); } } @@ -134,15 +135,15 @@ class Frontend_OFDM : public Frontend { continue; } if (fe_info.frequency_min > feparams.frequency || fe_info.frequency_max < feparams.frequency) { - Logger()->messagebf(LOG_WARNING, "Channel %d, freq (%d Hz) outside card range", channel, feparams.frequency); + logger->messagebf(LOG::WARNING, "Channel %d, freq (%d Hz) outside card range", channel, feparams.frequency); continue; } try { - Logger()->messagebf(LOG_DEBUG, "Channel %d, Frequency %d Hz", channel, feparams.frequency); + logger->messagebf(LOG::DEBUG, "Channel %d, Frequency %d Hz", channel, feparams.frequency); SetParameters(feparams); WaitForLock(); - Logger()->messagebf(LOG_INFO, "Found multiplex at %d Hz", feparams.frequency); - Logger()->messagebf(LOG_DEBUG, "frequency %d", feparams.frequency); + logger->messagebf(LOG::INFO, "Found multiplex at %d Hz", feparams.frequency); + logger->messagebf(LOG::DEBUG, "frequency %d", feparams.frequency); if (onFrequencyFound(feparams.frequency)) { return; } diff --git a/p2pvr/devices/localDevices.cpp b/p2pvr/devices/localDevices.cpp index 00ec395..cbe74a8 100644 --- a/p2pvr/devices/localDevices.cpp +++ b/p2pvr/devices/localDevices.cpp @@ -1,32 +1,36 @@ -#include #include "localDevices.h" #include #include "tuner.h" #include "bindTimerTask.h" -#include LocalDevices::Devices LocalDevices::devices; std::mutex LocalDevices::lock; -DECLARE_OPTIONS(LocalDevices, "P2PVR Devices") -("p2pvr.localdevices.frontend", - Options::functions( - [](const VariableType & df) { devices.insert(Devices::value_type(df.as(), OpenTunerPtr())); }, - []{ devices.clear(); }), - "Frontend of DVB devices to use (/dev/dvb/adapterX/frontendY)") -END_OPTIONS(LocalDevices); +LocalDevices::Options::Options() : + IceTray::Options("P2PVR Devices") +{ +} + +ICETRAY_OPTIONS(LocalDevices::Options, + ("p2pvr.localdevices.frontend", boost::program_options::value(&devices), "Frontend of DVB device(s) to use (/dev/dvb/adapterX/frontendY)") +); + +IceTray::Logging::LoggerPtr LocalDevices::logger(LOGMANAGER()->getLogger()); LocalDevices::LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr t) : timer(t), clientCheck(new BindTimerTask(boost::bind(&LocalDevices::ClientCheck, this, adapter))) { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + for (auto & device : options->devices) { + devices.insert({ device, nullptr }); + } + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(30)); } LocalDevices::~LocalDevices() { - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); timer->cancel(clientCheck); } @@ -36,7 +40,7 @@ LocalDevices::ClientCheck(Ice::ObjectAdapterPtr adapter) std::lock_guard g(lock); for (auto & device : devices) { if (device.second && device.second->tuner->GetLastUsedTime() < time(NULL) - 30) { - Logger()->messagebf(LOG_DEBUG, "%s: Device %s no longer in use", __PRETTY_FUNCTION__, device.first); + logger->messagebf(LOG::DEBUG, "%s: Device %s no longer in use", __PRETTY_FUNCTION__, device.first); auto id = device.second->tuner->ice_getIdentity(); if (adapter->find(id)) { adapter->remove(id); @@ -50,7 +54,7 @@ P2PVR::TunerPrx LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { std::lock_guard g(lock); - Logger()->messagebf(LOG_DEBUG, "%s: Searching for an open sharable tuner (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); + logger->messagebf(LOG::DEBUG, "%s: Searching for an open sharable tuner (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); auto openTuner = std::find_if(devices.begin(), devices.end(), [delivery](const Devices::value_type & ot) { return ot.second && !ot.second->openedPrivate && ot.second->delivery && ot.second->delivery->Frequency == delivery->Frequency; }); @@ -61,19 +65,19 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::C openTuner = std::find_if(devices.begin(), devices.end(), [](const Devices::value_type & ot) { return !ot.second; }); if (openTuner == devices.end()) { - Logger()->messagebf(LOG_DEBUG, "%s: None suitable and none free (frequency %d)", + logger->messagebf(LOG::DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); throw P2PVR::NoSuitableDeviceAvailable(); } - Logger()->messagebf(LOG_DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", + logger->messagebf(LOG::DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); t->TuneTo(delivery, ice); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); - Logger()->messagebf(LOG_DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", + logger->messagebf(LOG::DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); return tuner; } @@ -82,7 +86,7 @@ P2PVR::TunerPrx LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { std::lock_guard g(lock); - Logger()->messagebf(LOG_DEBUG, "%s: Searching for an open sharable tuner any frequency", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Searching for an open sharable tuner any frequency", __PRETTY_FUNCTION__); auto openTuner = std::find_if(devices.begin(), devices.end(), [delivery](const Devices::value_type & ot) { return ot.second && !ot.second->openedPrivate && ot.second->delivery; }); @@ -93,19 +97,19 @@ LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Curren openTuner = std::find_if(devices.begin(), devices.end(), [](const Devices::value_type & ot) { return !ot.second; }); if (openTuner == devices.end()) { - Logger()->messagebf(LOG_DEBUG, "%s: None suitable and none free (frequency %d)", + logger->messagebf(LOG::DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); throw P2PVR::NoSuitableDeviceAvailable(); } - Logger()->messagebf(LOG_DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", + logger->messagebf(LOG::DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); t->TuneTo(delivery, ice); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); - Logger()->messagebf(LOG_DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", + logger->messagebf(LOG::DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); return tuner; } @@ -114,14 +118,14 @@ P2PVR::PrivateTunerPrx LocalDevices::GetPrivateTuner(short , const Ice::Current & ice) { std::lock_guard g(lock); - Logger()->messagebf(LOG_DEBUG, "%s: Opening a private tuner", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Opening a private tuner", __PRETTY_FUNCTION__); auto openTuner = std::find_if(devices.begin(), devices.end(), [](const Devices::value_type & ot) { return !ot.second; }); if (openTuner == devices.end()) { - Logger()->messagebf(LOG_DEBUG, "%s: None free", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: None free", __PRETTY_FUNCTION__); throw P2PVR::NoSuitableDeviceAvailable(); } - Logger()->messagebf(LOG_DEBUG, "%s: Opening a private tuner (frontend %s)", + logger->messagebf(LOG::DEBUG, "%s: Opening a private tuner (frontend %s)", __PRETTY_FUNCTION__, openTuner->first); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new Tuner(openTuner->first))); openTuner->second = OpenTunerPtr(new OpenTuner(NULL, tuner, true)); @@ -133,15 +137,15 @@ void LocalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) { std::lock_guard g(lock); - Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s", __PRETTY_FUNCTION__); auto openTuner = std::find_if(devices.begin(), devices.end(), [tuner](const Devices::value_type & ot) { return ot.second && ot.second->tuner == tuner; }); if (openTuner == devices.end()) { - Logger()->messagebf(LOG_DEBUG, "%s: Not one of mine", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Not one of mine", __PRETTY_FUNCTION__); return; } - Logger()->messagebf(LOG_DEBUG, "%s: Locally owned deivce %s", __PRETTY_FUNCTION__, openTuner->first); + logger->messagebf(LOG::DEBUG, "%s: Locally owned deivce %s", __PRETTY_FUNCTION__, openTuner->first); openTuner->second->clients -= 1; if (openTuner->second->clients == 0) { auto id = tuner->ice_getIdentity(); diff --git a/p2pvr/devices/localDevices.h b/p2pvr/devices/localDevices.h index 1845256..7bd97ee 100644 --- a/p2pvr/devices/localDevices.h +++ b/p2pvr/devices/localDevices.h @@ -9,9 +9,19 @@ #include #include #include +#include class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { public: + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + std::vector devices; + }; + LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr); ~LocalDevices(); @@ -25,7 +35,6 @@ class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { void Add(const std::string & frontend, const Ice::Current &); void Remove(const std::string & frontend, const Ice::Current &); - INITOPTIONS; private: // Reference to global timer IceUtil::TimerPtr timer; @@ -48,6 +57,8 @@ class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { typedef std::map Devices; static Devices devices; static std::mutex lock; + static IceTray::Logging::LoggerPtr logger; + IceTray::OptionsResolver options; }; #endif diff --git a/p2pvr/devices/mockTuner.cpp b/p2pvr/devices/mockTuner.cpp index 05a0437..b040128 100644 --- a/p2pvr/devices/mockTuner.cpp +++ b/p2pvr/devices/mockTuner.cpp @@ -11,11 +11,14 @@ extern "C" { \ } \ static const Ice::ByteSeq resource(&resource##_start, &resource##_end); -#define LZMA_ASSERT(ret_xz) \ - if (ret_xz != LZMA_OK) { \ - Logger()->messagebf(LOG_ERR, "%s: LZMA error (%d)", __PRETTY_FUNCTION__, ret_xz); \ - throw P2PVR::DeviceError("LZMA", "Decompressor error", ret_xz); \ +void +MockTuner::LZMA_ASSERT(int ret_xz) +{ + if (ret_xz != LZMA_OK) { + MockTuner::logger->messagebf(LOG::ERR, "%s: LZMA error (%d)", __PRETTY_FUNCTION__, ret_xz); + throw P2PVR::DeviceError("LZMA", "Decompressor error", ret_xz); } +} ResourceFile(network); ResourceFile(services); @@ -27,6 +30,8 @@ ResourceFile(vid); int MockTuner::eventSet = 0; +IceTray::Logging::LoggerPtr MockTuner::logger = LOGMANAGER()->getLogger(); + void MockTuner::SetEventsSet(int n) { @@ -49,7 +54,7 @@ int MockTuner::GetStatus(const Ice::Current&) Ice::ByteSeq MockTuner::Decompress(const Ice::ByteSeq & dataxz) { - Logger()->messagebf(LOG_DEBUG, "%s: setup", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: setup", __PRETTY_FUNCTION__); lzma_stream strm = LZMA_STREAM_INIT; const uint32_t flags = LZMA_TELL_UNSUPPORTED_CHECK | LZMA_CONCATENATED; const uint64_t memory_limit = UINT64_MAX; @@ -58,7 +63,7 @@ Ice::ByteSeq MockTuner::Decompress(const Ice::ByteSeq & dataxz) strm.avail_in = dataxz.size(); uint8_t buf[BUFSIZ]; - Logger()->messagebf(LOG_DEBUG, "%s: decompress %d bytes", __PRETTY_FUNCTION__, dataxz.size()); + logger->messagebf(LOG::DEBUG, "%s: decompress %d bytes", __PRETTY_FUNCTION__, dataxz.size()); Ice::ByteSeq data; data.reserve(dataxz.size() * 20); do { @@ -75,17 +80,17 @@ Ice::ByteSeq MockTuner::Decompress(const Ice::ByteSeq & dataxz) void MockTuner::DecompressAndSendPackets(const Ice::ByteSeq & dataxz, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) const { - Logger()->messagebf(LOG_DEBUG, "%s: deserialize", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: deserialize", __PRETTY_FUNCTION__); std::list packets; auto istrm = Ice::createInputStream(ice.adapter->getCommunicator(), Decompress(dataxz)); istrm->read(packets); - Logger()->messagebf(LOG_DEBUG, "%s: send", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: send", __PRETTY_FUNCTION__); for (const auto & packet : packets) { client->NewData(packet); } - Logger()->messagebf(LOG_DEBUG, "%s: complete", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: complete", __PRETTY_FUNCTION__); } void MockTuner::ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) @@ -125,7 +130,7 @@ void MockTuner::SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & std::list packets; auto istrm = Ice::createInputStream(ice.adapter->getCommunicator(), Decompress(dataxz)); istrm->read(packets); - Logger()->messagebf(LOG_DEBUG, "%s: loop over %d packets", __PRETTY_FUNCTION__, packets.size()); + logger->messagebf(LOG::DEBUG, "%s: loop over %d packets", __PRETTY_FUNCTION__, packets.size()); auto p = packets.begin(); while (true) { { @@ -160,7 +165,7 @@ int MockTuner::StartSendingSection(Ice::Int sid, const P2PVR::RawDataClientPrx & void MockTuner::StopSending(int s, const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s: stop %d", __PRETTY_FUNCTION__, s); + logger->messagebf(LOG::DEBUG, "%s: stop %d", __PRETTY_FUNCTION__, s); auto sitr = senders.find(s); if (sitr != senders.end()) { sitr->second->interrupt(); diff --git a/p2pvr/devices/mockTuner.h b/p2pvr/devices/mockTuner.h index d640209..60372c9 100644 --- a/p2pvr/devices/mockTuner.h +++ b/p2pvr/devices/mockTuner.h @@ -5,6 +5,7 @@ #include #include #include +#include class DLL_PUBLIC MockTuner : public P2PVR::PrivateTuner { public: @@ -31,12 +32,15 @@ class DLL_PUBLIC MockTuner : public P2PVR::PrivateTuner { protected: static Ice::ByteSeq Decompress(const Ice::ByteSeq &); + static void LZMA_ASSERT(int ret_xz); void DecompressAndSendPackets(const Ice::ByteSeq &, const P2PVR::RawDataClientPrx &, const Ice::Current&) const; void SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const; static int eventSet; std::map senders; int senderId; + + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/devices/pch.hpp b/p2pvr/devices/pch.hpp deleted file mode 100644 index 7a7881c..0000000 --- a/p2pvr/devices/pch.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef BOOST_BUILD_PCH_ENABLED -#ifndef P2PVRLIB_PCH -#define P2PVRLIB_PCH - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#endif -#endif - diff --git a/p2pvr/devices/sampleSiData/events1.datxz b/p2pvr/devices/sampleSiData/events1.datxz index a84d777..43358a9 100644 Binary files a/p2pvr/devices/sampleSiData/events1.datxz and b/p2pvr/devices/sampleSiData/events1.datxz differ diff --git a/p2pvr/devices/tuner.cpp b/p2pvr/devices/tuner.cpp index f6df896..148790b 100644 --- a/p2pvr/devices/tuner.cpp +++ b/p2pvr/devices/tuner.cpp @@ -1,10 +1,8 @@ -#include #include "tuner.h" #include #include #include #include -#include #include #include #include @@ -14,6 +12,8 @@ #include "tunerSendSi.h" #include "tunerSendTs.h" +IceTray::Logging::LoggerPtr Tuner::logger = LOGMANAGER()->getLogger(); + Tuner::Tuner(const boost::filesystem::path & df) : deviceFrontend(df), deviceRoot(df.branch_path()), @@ -35,7 +35,7 @@ Tuner::Tuner(const boost::filesystem::path & df) : close(fd); throw; } - Logger()->messagebf(LOG_INFO, "%s: Attached to %s (%s, type %s)", __PRETTY_FUNCTION__, + logger->messagebf(LOG::INFO, "%s: Attached to %s (%s, type %s)", __PRETTY_FUNCTION__, deviceRoot, frontend->Info().name, frontend->Type()); } @@ -94,12 +94,12 @@ Tuner::ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, con } catch (const std::exception & ex) { char * buf = __cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL); - Logger()->messagebf(LOG_DEBUG, "%s: frequency scan lock event failed %s:%s", __PRETTY_FUNCTION__, buf, ex.what()); + logger->messagebf(LOG::DEBUG, "%s: frequency scan lock event failed %s:%s", __PRETTY_FUNCTION__, buf, ex.what()); free(buf); return false; } catch (...) { - Logger()->messagebf(LOG_DEBUG, "%s: frequency scan lock event failed", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: frequency scan lock event failed", __PRETTY_FUNCTION__); return false; } }); @@ -145,7 +145,7 @@ uint64_t Tuner::SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) const { time(&lastUsedTime); - Logger()->messagebf(LOG_DEBUG, "%s: pid = 0x%x", __PRETTY_FUNCTION__, pid); + logger->messagebf(LOG::DEBUG, "%s: pid = 0x%x", __PRETTY_FUNCTION__, pid); if (ice.con) { ice.con->createProxy(client->ice_getIdentity()); @@ -156,9 +156,9 @@ Tuner::SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Curre } void -Tuner::RequestPID(int pid, int demux) +Tuner::RequestPID(int pid, int demux) const { - setBufferSize(demux, DemuxTableBufferSize); + setBufferSize(demux, options->DemuxTableBufferSize); struct dmx_sct_filter_params sctFilterParams; memset(&sctFilterParams, 0, sizeof(dmx_sct_filter_params)); sctFilterParams.pid = pid; @@ -172,7 +172,7 @@ Tuner::RequestPID(int pid, int demux) uint64_t Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) const { - Logger()->messagebf(LOG_DEBUG, "%s: begin", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: begin", __PRETTY_FUNCTION__); struct pollfd ufd; memset(&ufd, 0, sizeof(pollfd)); ufd.fd = demux; @@ -180,13 +180,13 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) cons BackgroundClient client = BackgroundClient(new SendSi(_client)); do { // Wait for data to appear - switch (poll(&ufd, 1, DemuxReadTimeout)) { + switch (poll(&ufd, 1, options->DemuxReadTimeout)) { case -1: - Logger()->messagebf(LOG_DEBUG, "%s: poll error reading demux (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::DEBUG, "%s: poll error reading demux (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); throw P2PVR::DeviceError("demux", strerror(errno), errno); case 0: auto status = frontend->GetStatus(); - Logger()->messagebf(LOG_DEBUG, "%s: Timed out waiting for data (device status 0x%02x)", __PRETTY_FUNCTION__, status); + logger->messagebf(LOG::DEBUG, "%s: Timed out waiting for data (device status 0x%02x)", __PRETTY_FUNCTION__, status); throw P2PVR::DeviceError("demux", "timeout", 0); } @@ -194,7 +194,7 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) cons P2PVR::Data buf(1 << 12); int nr = read(demux, &buf.front(), buf.size()); if (nr < 0) { - Logger()->messagebf(LOG_DEBUG, "%s: error reading demux (%d:%s) status 0x%02x", + logger->messagebf(LOG::DEBUG, "%s: error reading demux (%d:%s) status 0x%02x", __PRETTY_FUNCTION__, errno, strerror(errno), frontend->GetStatus()); throw P2PVR::DeviceError("demux", strerror(errno), errno); } @@ -207,7 +207,7 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) cons } while (!client->IsFinished()); auto packetsSent = client->PacketsSent(); client.reset(); - Logger()->messagebf(LOG_DEBUG, "%s: end (sent %d packets)", __PRETTY_FUNCTION__, packetsSent); + logger->messagebf(LOG::DEBUG, "%s: end (sent %d packets)", __PRETTY_FUNCTION__, packetsSent); return packetsSent; } @@ -215,7 +215,7 @@ int Tuner::StartSendingSection(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &) { time(&lastUsedTime); - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); std::lock_guard g(lock); int demux = backgroundClients.insert(BackgroundClients::value_type(OpenDemux(), @@ -229,7 +229,7 @@ int Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) { time(&lastUsedTime); - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); if (pids.empty()) { throw P2PVR::DeviceError("demux", "Packet Id list cannot be empty", 0); } @@ -240,10 +240,10 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP std::lock_guard g(lock); int demux = backgroundClients.insert(BackgroundClients::value_type(OpenDemux(), BackgroundClient(new SendTs(client)))).first->first; - + struct dmx_pes_filter_params pesFilterParams; memset(&pesFilterParams, 0, sizeof(struct dmx_pes_filter_params)); - Logger()->messagebf(LOG_ERR, "%s: DMX_SET_PES_FILTER for pid %d", __PRETTY_FUNCTION__, pids[0]); + logger->messagebf(LOG::ERR, "%s: DMX_SET_PES_FILTER for pid %d", __PRETTY_FUNCTION__, pids[0]); pesFilterParams.pid = pids[0]; pesFilterParams.input = DMX_IN_FRONTEND; pesFilterParams.output = DMX_OUT_TSDEMUX_TAP; @@ -252,24 +252,24 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP if (ioctl(demux, DMX_SET_PES_FILTER, &pesFilterParams) < 0) { backgroundClients.erase(demux); - Logger()->messagebf(LOG_ERR, "%s: DMX_SET_PES_FILTER failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::ERR, "%s: DMX_SET_PES_FILTER failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); throw P2PVR::DeviceError("demux", strerror(errno), errno); } for (unsigned int x = 1; x < pids.size(); x += 1) { __u16 p = pids[x]; - Logger()->messagebf(LOG_ERR, "%s: DMX_ADD_PID for pid %d", __PRETTY_FUNCTION__, p); + logger->messagebf(LOG::ERR, "%s: DMX_ADD_PID for pid %d", __PRETTY_FUNCTION__, p); if (ioctl(demux, DMX_ADD_PID, &p) < 0) { backgroundClients.erase(demux); - Logger()->messagebf(LOG_ERR, "%s: DMX_ADD_PID failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::ERR, "%s: DMX_ADD_PID failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); throw P2PVR::DeviceError("demux", strerror(errno), errno); } } - setBufferSize(demux, DemuxStreamBufferSize); + setBufferSize(demux, options->DemuxStreamBufferSize); if (ioctl(demux, DMX_START) < 0) { backgroundClients.erase(demux); - Logger()->messagebf(LOG_ERR, "%s: DMX_START failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::ERR, "%s: DMX_START failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); throw P2PVR::DeviceError("demux", strerror(errno), errno); } @@ -281,17 +281,17 @@ void Tuner::setBufferSize(int demux, unsigned long size) { if (ioctl(demux, DMX_SET_BUFFER_SIZE, size)) { - Logger()->messagebf(LOG_ERR, "%s: DMX_SET_BUFFER_SIZE to %d failed (%d: %s)", __PRETTY_FUNCTION__, size, errno, strerror(errno)); + logger->messagebf(LOG::ERR, "%s: DMX_SET_BUFFER_SIZE to %d failed (%d: %s)", __PRETTY_FUNCTION__, size, errno, strerror(errno)); throw P2PVR::DeviceError("demux", strerror(errno), errno); } - Logger()->messagebf(LOG_DEBUG, "%s: DMX_SET_BUFFER_SIZE to %d", __PRETTY_FUNCTION__, size); + logger->messagebf(LOG::DEBUG, "%s: DMX_SET_BUFFER_SIZE to %d", __PRETTY_FUNCTION__, size); } void Tuner::StopSending(int handle, const Ice::Current &) { time(&lastUsedTime); - Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); std::lock_guard g(lock); if (backgroundClients.find(handle) != backgroundClients.end()) { close(handle); @@ -324,7 +324,7 @@ Tuner::senderThread() struct timeval tv { 2, 0 }; switch (select(n, &rfds, NULL, NULL, &tv)) { case -1: // error - Logger()->messagebf(LOG_DEBUG, "%s: select failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::DEBUG, "%s: select failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); case 0: // nothing to read, but all is well break; default: @@ -336,7 +336,7 @@ Tuner::senderThread() P2PVR::Data buf(1 << 16); int nr = read(c->first, &buf.front(), buf.size()); if (nr < 0) { - Logger()->messagebf(LOG_DEBUG, "%s: read failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); + logger->messagebf(LOG::DEBUG, "%s: read failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); close(c->first); c = backgroundClients.erase(c); } @@ -367,7 +367,7 @@ Tuner::senderThread() } } backgroundThread = NULL; - Logger()->messagebf(LOG_DEBUG, "%s: Unlocking", __PRETTY_FUNCTION__); + logger->messagebf(LOG::DEBUG, "%s: Unlocking", __PRETTY_FUNCTION__); lock.unlock(); } @@ -393,22 +393,23 @@ Tuner::IDataSender::PacketsSent() const return _packetsSent; } -int Tuner::TuningTimeout; -int Tuner::LockTimeout; -int Tuner::DemuxReadTimeout; -int Tuner::DemuxTableBufferSize; -int Tuner::DemuxStreamBufferSize; - -DECLARE_OPTIONS(Tuner, "P2PVR Tuner Options") -("p2pvr.tuner.tuningtimeout", Options::value(&TuningTimeout, 500), - "Timeout for a DVB frontend to tune (ms, default 500ms)") -("p2pvr.tuner.locktimeout", Options::value(&LockTimeout, 2000), - "Timeout for a DVB frontend to acquire lock (ms, default 2000ms)") -("p2pvr.tuner.demuxreadtimeout", Options::value(&DemuxReadTimeout, 20000), - "Timeout when reading from a demux device (ms, default 20s)") -("p2pvr.tuner.demuxtablebuffersize", Options::value(&DemuxTableBufferSize, 256*1024), - "Kernel buffer size for demux table data (bytes, default 256KB)") -("p2pvr.tuner.demuxstreambuffersize", Options::value(&DemuxStreamBufferSize, 1024*1024), - "Kernel buffer size for demux stream data (bytes, default 1MB)") -END_OPTIONS(Tuner); +Tuner::Options::Options() : + IceTray::Options("P2PVR Tuner Options") +{ +} + +namespace po = boost::program_options; + +ICETRAY_OPTIONS(Tuner::Options, + ("p2pvr.tuner.tuningtimeout", po::value(&TuningTimeout)->default_value(500), + "Timeout for a DVB frontend to tune (ms, default 500ms)") + ("p2pvr.tuner.locktimeout", po::value(&LockTimeout)->default_value(2000), + "Timeout for a DVB frontend to acquire lock (ms, default 2000ms)") + ("p2pvr.tuner.demuxreadtimeout", po::value(&DemuxReadTimeout)->default_value(20000), + "Timeout when reading from a demux device (ms, default 20s)") + ("p2pvr.tuner.demuxtablebuffersize", po::value(&DemuxTableBufferSize)->default_value(256*1024), + "Kernel buffer size for demux table data (bytes, default 256KB)") + ("p2pvr.tuner.demuxstreambuffersize", po::value(&DemuxStreamBufferSize)->default_value(1024*1024), + "Kernel buffer size for demux stream data (bytes, default 1MB)") +) diff --git a/p2pvr/devices/tuner.h b/p2pvr/devices/tuner.h index 670a17d..42f2948 100644 --- a/p2pvr/devices/tuner.h +++ b/p2pvr/devices/tuner.h @@ -11,6 +11,7 @@ #include #include #include +#include class Tuner : public P2PVR::PrivateTuner { public: @@ -51,12 +52,10 @@ class Tuner : public P2PVR::PrivateTuner { Ice::Long GetLastUsedTime(const Ice::Current&); - INITOPTIONS; - private: int OpenDemux() const; uint64_t SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &) const; - static void RequestPID(int pid, int fd); + void RequestPID(int pid, int fd) const; uint64_t ReadDemuxAndSend(int fd, const P2PVR::RawDataClientPrx & client) const; void startSenderThread(); void senderThread(); @@ -70,13 +69,25 @@ class Tuner : public P2PVR::PrivateTuner { mutable time_t lastUsedTime; FrontendPtr frontend; + static IceTray::Logging::LoggerPtr logger; public: - static int TuningTimeout; - static int LockTimeout; - static int DemuxReadTimeout; - static int DemuxTableBufferSize; - static int DemuxStreamBufferSize; + class Options : public IceTray::Options { + public: + Options(); + + ICETRAY_OPTIONS_DECLARE; + + int TuningTimeout; + int LockTimeout; + int DemuxReadTimeout; + int DemuxTableBufferSize; + int DemuxStreamBufferSize; + }; + + private: + friend class Frontend_OFDM; + IceTray::OptionsResolver options; }; #endif diff --git a/p2pvr/devices/tunerSendSi.cpp b/p2pvr/devices/tunerSendSi.cpp index e1f4637..c8a8310 100644 --- a/p2pvr/devices/tunerSendSi.cpp +++ b/p2pvr/devices/tunerSendSi.cpp @@ -1,9 +1,10 @@ -#include #include "tunerSendSi.h" #include #include #include "siParsers/table.h" +IceTray::Logging::LoggerPtr SendSi::logger(LOGMANAGER()->getLogger()); + SendSi::SendSi(const P2PVR::RawDataClientPrx & c) : Tuner::IDataSender(c->ice_collocationOptimized(false)) { @@ -41,7 +42,7 @@ SendSi::IsFinished() return false; } catch (const std::exception & ex) { - Logger()->messagebf(LOG_DEBUG, "%s: Client transmit error (%s)", __PRETTY_FUNCTION__, ex.what()); + logger->messagebf(LOG::DEBUG, "%s: Client transmit error (%s)", __PRETTY_FUNCTION__, ex.what()); return true; } } @@ -51,21 +52,21 @@ SendSi::IsValidSection(const P2PVR::Data & buf) { auto n = buf.size(); if (n < sizeof(SiTableHeader)) { - Logger()->messagebf(LOG_WARNING, "Received data too small to be an SI table."); + logger->messagebf(LOG::WARNING, "Received data too small to be an SI table."); return false; } auto * tab = (const SiTableHeader *)(&buf.front()); size_t l = sizeof(SiTableHeaderBase) + HILO(tab->section_length); if (n < l) { - Logger()->messagebf(LOG_WARNING, "Received data shorter than its defined length."); + logger->messagebf(LOG::WARNING, "Received data shorter than its defined length."); return false; } if (n > l) { - Logger()->messagebf(LOG_WARNING, "Received data longer than its defined length."); + logger->messagebf(LOG::WARNING, "Received data longer than its defined length."); return false; } if (!crc32(buf)) { - Logger()->messagebf(LOG_WARNING, "Received data is corrupted (crc32 failed)."); + logger->messagebf(LOG::WARNING, "Received data is corrupted (crc32 failed)."); return false; } return true; diff --git a/p2pvr/devices/tunerSendSi.h b/p2pvr/devices/tunerSendSi.h index df48f43..27d15af 100644 --- a/p2pvr/devices/tunerSendSi.h +++ b/p2pvr/devices/tunerSendSi.h @@ -2,6 +2,7 @@ #define TUNER_SENDSI_H #include "tuner.h" +#include class SendSi : public Tuner::IDataSender { public: @@ -17,6 +18,7 @@ class SendSi : public Tuner::IDataSender { std::set asyncs; bool finish; + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/devices/tunerSendTs.cpp b/p2pvr/devices/tunerSendTs.cpp index 70b6670..6d4e3e1 100644 --- a/p2pvr/devices/tunerSendTs.cpp +++ b/p2pvr/devices/tunerSendTs.cpp @@ -1,4 +1,3 @@ -#include #include "tunerSendTs.h" #include @@ -7,6 +6,8 @@ // About the ICE message size limit #define TARGET_BUFFER_LIMIT 512 * 1024 +IceTray::Logging::LoggerPtr SendTs::logger(LOGMANAGER()->getLogger()); + SendTs::SendTs(const P2PVR::RawDataClientPrx & c) : Tuner::IDataSender(c->ice_collocationOptimized(false)) { @@ -69,7 +70,7 @@ SendTs::IsFinished() } catch (const std::exception & ex) { async = NULL; - Logger()->messagebf(LOG_DEBUG, "%s: Client transmit error (%s)", __PRETTY_FUNCTION__, ex.what()); + logger->messagebf(LOG::DEBUG, "%s: Client transmit error (%s)", __PRETTY_FUNCTION__, ex.what()); return true; } } diff --git a/p2pvr/devices/tunerSendTs.h b/p2pvr/devices/tunerSendTs.h index ecf32fd..162248d 100644 --- a/p2pvr/devices/tunerSendTs.h +++ b/p2pvr/devices/tunerSendTs.h @@ -2,6 +2,7 @@ #define TUNER_SENDTS_H #include "tuner.h" +#include class SendTs : public Tuner::IDataSender { public: @@ -16,6 +17,7 @@ class SendTs : public Tuner::IDataSender { Ice::AsyncResultPtr async; P2PVR::Data buffer; + static IceTray::Logging::LoggerPtr logger; }; #endif diff --git a/p2pvr/dvb/Jamfile.jam b/p2pvr/dvb/Jamfile.jam index e71093a..e9a31f4 100644 --- a/p2pvr/dvb/Jamfile.jam +++ b/p2pvr/dvb/Jamfile.jam @@ -1,13 +1,9 @@ -cpp-pch pch : pch.hpp : - ../ice//p2pvrice -; - lib p2pvrdvb : - pch [ glob-tree *.cpp : unittests ] : ../ice//p2pvrice ..//adhocutil + ../..//glibmm ../ice//p2pvrice : : ../ice//p2pvrice diff --git a/p2pvr/dvb/bindDataHandler.h b/p2pvr/dvb/bindDataHandler.h index 3805d7f..bf2034a 100644 --- a/p2pvr/dvb/bindDataHandler.h +++ b/p2pvr/dvb/bindDataHandler.h @@ -2,9 +2,10 @@ #define BINDDATAHANDLER_H #include +#include #include -class BindDataHandler : public P2PVR::RawDataClient { +class DLL_PUBLIC BindDataHandler : public P2PVR::RawDataClient { public: typedef boost::function Callback; BindDataHandler(const Callback & cb); diff --git a/p2pvr/dvb/pch.hpp b/p2pvr/dvb/pch.hpp deleted file mode 100644 index 6a76256..0000000 --- a/p2pvr/dvb/pch.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifdef BOOST_BUILD_PCH_ENABLED -#ifndef P2PVRLIB_PCH -#define P2PVRLIB_PCH - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#endif -#endif - diff --git a/p2pvr/dvb/siParsers/event.cpp b/p2pvr/dvb/siParsers/event.cpp index 11c15e2..bea4747 100644 --- a/p2pvr/dvb/siParsers/event.cpp +++ b/p2pvr/dvb/siParsers/event.cpp @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/p2pvr/dvb/siParsers/network.cpp b/p2pvr/dvb/siParsers/network.cpp index fb21683..b00ddeb 100644 --- a/p2pvr/dvb/siParsers/network.cpp +++ b/p2pvr/dvb/siParsers/network.cpp @@ -1,9 +1,8 @@ -#include #include "network.h" #include #include #include -#include +#include struct NetworkStreamsHeader { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -157,8 +156,27 @@ SiNetworkInformationParser::parseDescriptor_NetworkName(DVBSI::NetworkPtr n, con n->Name = *convert((const char *)p, len); } +namespace AdHoc { + StreamWriterT('x') { + template + static void write(stream & s, const int & p, const Pn & ... pn) + { + s << std::hex << p; + StreamWriter::next(s, pn...); + } + }; +} + +AdHocFormatter(WhatIsntSupported, "%? %x"); +class NotSupported : public std::runtime_error { + public: + NotSupported(const char * what, int id) : std::runtime_error(WhatIsntSupported::get(what, id)) { } +}; + #define SINOTSUPPORTED(What) \ -class What##NotSupported : public NotSupported { public: What##NotSupported(short id) : NotSupported(stringbf(#What" 0x%2x", id)) { } }; +class What##NotSupported : public NotSupported { \ + public: What##NotSupported(short id) : NotSupported(#What, id) { } \ +}; std::map tbandwidths { {0, BANDWIDTH_8_MHZ}, diff --git a/p2pvr/dvb/siParsers/programAssociation.cpp b/p2pvr/dvb/siParsers/programAssociation.cpp index 7839b9e..0add29e 100644 --- a/p2pvr/dvb/siParsers/programAssociation.cpp +++ b/p2pvr/dvb/siParsers/programAssociation.cpp @@ -1,4 +1,3 @@ -#include #include "programAssociation.h" struct ProgramAssociation { diff --git a/p2pvr/dvb/siParsers/programMap.cpp b/p2pvr/dvb/siParsers/programMap.cpp index 1ba78c4..448bda0 100644 --- a/p2pvr/dvb/siParsers/programMap.cpp +++ b/p2pvr/dvb/siParsers/programMap.cpp @@ -1,7 +1,5 @@ -#include #include "programMap.h" #include -#include struct ProgramMapStream { uint8_t stream_type; diff --git a/p2pvr/dvb/siParsers/service.cpp b/p2pvr/dvb/siParsers/service.cpp index fbcd966..56452e9 100644 --- a/p2pvr/dvb/siParsers/service.cpp +++ b/p2pvr/dvb/siParsers/service.cpp @@ -1,4 +1,3 @@ -#include #include "service.h" #include diff --git a/p2pvr/dvb/siParsers/table.cpp b/p2pvr/dvb/siParsers/table.cpp index 9844814..455d0a4 100644 --- a/p2pvr/dvb/siParsers/table.cpp +++ b/p2pvr/dvb/siParsers/table.cpp @@ -1,14 +1,7 @@ -#include #include "table.h" #include #include #include -#include -#include - -SimpleMessageException(ErrorReadingData); -SimpleMessageException(TimeoutReadingData); -SimpleMessageException(DemuxOpenFailure); const std::string SiTableParserBase::ISO10646("ISO-10646"); const std::string SiTableParserBase::EitEncoding("ISO6937"); @@ -27,7 +20,6 @@ SiTableParserBase::~SiTableParserBase() bool SiTableParserBase::NewData(const P2PVR::Data & bytes, const Ice::Current&) { - //Logger()->messagebf(LOG_DEBUG, "%s: Got %d bytes", __PRETTY_FUNCTION__, bytes.size()); currentRawData = &bytes; return ParseInfoTable(&bytes.front(), bytes.size()); } @@ -66,8 +58,6 @@ SiTableParserBase::convert(const char * txt, size_t len) break; case 0x1F: // Values for the first byte of "0x00", "0x06" to "0x0F", and "0x12" to "0x1F" are reserved for future use. - //fprintf(stderr, "Reserved encoding: %02x\n", txt[0]); - //fprintf(stderr, "%d: %.*s\n", txt[1], len - 2, txt + 2); case 0x06 ... 0x0F: case 0x12 ... 0x1E: case 0x00: // empty string diff --git a/p2pvr/dvb/siParsers/table.h b/p2pvr/dvb/siParsers/table.h index 6333a2a..effcfa2 100644 --- a/p2pvr/dvb/siParsers/table.h +++ b/p2pvr/dvb/siParsers/table.h @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include typedef unsigned char u_char; @@ -94,7 +94,7 @@ class SiTableParser : public SiTableParserBase { virtual int SectionNumberShift() const { return 0; } virtual uint8_t LastTableId(const TableType * t) { return t->header.tableid; } virtual uint8_t FirstTableId(const TableType * t) { return t->header.tableid; } - + bool ParseInfoTable(const u_char * data, size_t len) { const u_char * dataEnd = data + len; diff --git a/p2pvr/dvb/unittests/Jamfile.jam b/p2pvr/dvb/unittests/Jamfile.jam index 699cfcd..616be7b 100644 --- a/p2pvr/dvb/unittests/Jamfile.jam +++ b/p2pvr/dvb/unittests/Jamfile.jam @@ -1,5 +1,6 @@ import testing ; +lib adhocutil ; lib boost_system ; lib boost_filesystem ; lib IceUtil ; @@ -11,6 +12,7 @@ exe createSamples : createSamples.cpp : BOOST_TEST_DYN_LINK + adhocutil ..//p2pvrdvb ../../ice//p2pvrice IceUtil @@ -33,7 +35,6 @@ exe createBroadcast : boost_system boost_filesystem ../..//boost_utf - ../..//p2ut ROOT=\"$(me)\" ; diff --git a/p2pvr/dvb/unittests/createBroadcast.cpp b/p2pvr/dvb/unittests/createBroadcast.cpp index c009fe2..b910744 100644 --- a/p2pvr/dvb/unittests/createBroadcast.cpp +++ b/p2pvr/dvb/unittests/createBroadcast.cpp @@ -1,5 +1,4 @@ #define BOOST_TEST_MODULE CreateSamples -#include #include #include #include @@ -28,7 +27,6 @@ class Core { ic(Ice::initialize(params)), adapter(ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12003")) { - TestOptionsSource::LoadTestOptions({ }); adapter->activate(); devs = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); diff --git a/p2pvr/dvb/unittests/createSamples.cpp b/p2pvr/dvb/unittests/createSamples.cpp index 94cfd50..f9909af 100644 --- a/p2pvr/dvb/unittests/createSamples.cpp +++ b/p2pvr/dvb/unittests/createSamples.cpp @@ -70,7 +70,7 @@ CaptureAndSave(const boost::filesystem::path & fileName, const boost::function(icp); auto adap = boost::get<1>(icp); auto p = boost::get<2>(icp); - ScopeExit _([&ic]{ ic->destroy(); }); + AdHoc::ScopeExit _([&ic]{ ic->destroy(); }); auto devs = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); auto parser = P2PVR::RawDataClientPrx::checkedCast(adap->createProxy(ic->stringToIdentity("parser"))); diff --git a/p2pvr/etc/init.d/p2pvrcardd b/p2pvr/etc/init.d/p2pvrcardd deleted file mode 100755 index 4014ef9..0000000 --- a/p2pvr/etc/init.d/p2pvrcardd +++ /dev/null @@ -1,26 +0,0 @@ -#!/sbin/runscript - -depend() { - use net -} - -start() { - ebegin "Starting P2PVR card daemon" - start-stop-daemon --start --exec /usr/bin/p2daemon --pidfile /run/p2pvr/p2pvrcarddaemon.pid -- \ - --library libp2pvrcarddaemon.so \ - --daemon.type p2pvrcarddaemon \ - --file.options.read /etc/p2pvr/p2config \ - --daemon.setuser p2pvr \ - --daemon.setgroup video \ - --daemon.pidfile /run/p2pvr/p2pvrcarddaemon.pid \ - --daemon.daemonize - eend $? -} - -stop() { - ebegin "Stopping P2PVR card daemon" - start-stop-daemon --signal TERM /usr/bin/p2daemon --pidfile /run/p2pvr/p2pvrcarddaemon.pid - eend $? -} - - diff --git a/p2pvr/etc/init.d/p2pvrd b/p2pvr/etc/init.d/p2pvrd deleted file mode 100755 index 04aeaa8..0000000 --- a/p2pvr/etc/init.d/p2pvrd +++ /dev/null @@ -1,26 +0,0 @@ -#!/sbin/runscript - -depend() { - use net -} - -start() { - ebegin "Starting P2PVR daemon" - start-stop-daemon --start --exec /usr/bin/p2daemon --pidfile /run/p2pvr/p2pvrdaemon.pid -- \ - --library libp2pvrdaemon.so \ - --daemon.type p2pvrdaemon \ - --file.options.read /etc/p2pvr/p2config \ - --daemon.setuser p2pvr \ - --daemon.setgroup video \ - --daemon.pidfile /run/p2pvr/p2pvrdaemon.pid \ - --daemon.daemonize - eend $? -} - -stop() { - ebegin "Stopping P2PVR daemon" - start-stop-daemon --signal TERM /usr/bin/p2daemon --pidfile /run/p2pvr/p2pvrdaemon.pid - eend $? -} - - diff --git a/p2pvr/etc/p2config b/p2pvr/etc/p2config deleted file mode 100644 index 07c2e76..0000000 --- a/p2pvr/etc/p2config +++ /dev/null @@ -1,8 +0,0 @@ -common.datasourceRoot = /etc/p2pvr/datasources -p2pvr.localdevices.frontend = /dev/dvb/adapter0/frontend0 -p2pvr.globaldevices.carddaemon = Devices:default -h localhost -p 10000 -p2pvr.storage.root = /var/store/p2pvr/recordings -p2pvr.recorder.muxercommand = /usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy - -p2pvr.recorder.extension = mpg -common.syslog.level = 4 -common.syslog.ident = p2pvr diff --git a/p2pvr/etc/p2pvrcd/icebox.config b/p2pvr/etc/p2pvrcd/icebox.config new file mode 100644 index 0000000..f79bda1 --- /dev/null +++ b/p2pvr/etc/p2pvrcd/icebox.config @@ -0,0 +1,7 @@ +IceBox.Service.P2PVRCD=p2pvrcd:createIceTrayService +IceBox.InheritProperties=1 +P2PVRCD.ThreadPool.Size=2 +P2PVRCD.ThreadPool.SizeMax=10 +P2PVRCD.Endpoints=tcp -p 10001 +p2pvr.localdevices.frontend = /dev/dvb/adapter0/frontend0 + diff --git a/p2pvr/etc/p2pvrd/icebox.config b/p2pvr/etc/p2pvrd/icebox.config new file mode 100644 index 0000000..07ae1bc --- /dev/null +++ b/p2pvr/etc/p2pvrd/icebox.config @@ -0,0 +1,11 @@ +IceBox.Service.P2PVRD=p2pvrd:createIceTrayService +IceBox.InheritProperties=1 +P2PVRD.ThreadPool.Size=2 +P2PVRD.ThreadPool.SizeMax=10 +P2PVRD.Database.ConnectionString=user=p2pvr dbname=p2pvr +P2PVRD.Endpoints=tcp -p 10001 +p2pvr.localdevices.frontend = /dev/dvb/adapter0/frontend0 +p2pvr.globaldevices.carddaemon = Devices:default -h localhost -p 10000 +p2pvr.storage.root = /var/store/p2pvr/recordings +p2pvr.recorder.muxercommand = /usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy - +p2pvr.recorder.extension = mpg diff --git a/p2pvr/etc/systemd/p2pvrcardd.service b/p2pvr/etc/systemd/p2pvrcardd.service index 4ac9088..f5e6ca1 100644 --- a/p2pvr/etc/systemd/p2pvrcardd.service +++ b/p2pvr/etc/systemd/p2pvrcardd.service @@ -4,13 +4,3 @@ Description=Project2 PVR Card Daemon [Service] User=p2pvr Group=video -Type=simple -StandardOutput=journal -StandardError=journal -Restart=always -StartLimitInterval=10 -StartLimitBurst=5 -ExecStart=/usr/bin/p2daemon --library libp2pvrcarddaemon.so --daemon.type p2pvrcarddaemon --file.options.read /etc/p2pvr/p2config - -[Install] -WantedBy=multi-user.target diff --git a/p2pvr/etc/systemd/p2pvrd.service b/p2pvr/etc/systemd/p2pvrd.service index d42aff9..44d94cb 100644 --- a/p2pvr/etc/systemd/p2pvrd.service +++ b/p2pvr/etc/systemd/p2pvrd.service @@ -1,17 +1,7 @@ [Unit] Description=Project2 PVR Daemon -After=postgresql-9.4.service +After=postgresql-9.6.service [Service] User=p2pvr Group=video -Type=simple -StandardOutput=journal -StandardError=journal -Restart=always -StartLimitInterval=10 -StartLimitBurst=5 -ExecStart=/usr/bin/p2daemon --library libp2pvrdaemon.so --daemon.type p2pvrdaemon --file.options.read /etc/p2pvr/p2config - -[Install] -WantedBy=multi-user.target diff --git a/p2pvr/ice/Jamfile.jam b/p2pvr/ice/Jamfile.jam index ca27324..2283438 100644 --- a/p2pvr/ice/Jamfile.jam +++ b/p2pvr/ice/Jamfile.jam @@ -8,9 +8,7 @@ lib p2pvrice : Ice IceUtil pthread - ..//p2common ..//adhocutil - ..//p2ice slicer yes : : diff --git a/p2pvr/ice/converters.cpp b/p2pvr/ice/converters.cpp index 2b5f653..c4e9332 100644 --- a/p2pvr/ice/converters.cpp +++ b/p2pvr/ice/converters.cpp @@ -1,36 +1,6 @@ -#include #include -#include #include "commonHelpers.h" -template<> -VariableType -DLL_PUBLIC IceConvert::ToVariable(const Common::DateTime & dt) -{ - return *dt; -} - -template<> -VariableType -DLL_PUBLIC IceConvert::ToVariable(const Common::Duration & d) -{ - return *d; -} - -template<> -Common::DateTime -DLL_PUBLIC IceConvert::FromVariable(const VariableType & dt) -{ - return *dt.as(); -} - -template<> -Common::Duration -DLL_PUBLIC IceConvert::FromVariable(const VariableType & d) -{ - return *d.as(); -} - namespace Slicer { Common::DateTime DLL_PUBLIC ptimeToDateTime(boost::posix_time::ptime const & p) diff --git a/p2pvr/ice/dvb.ice b/p2pvr/ice/dvb.ice index 7565d33..b306d1e 100644 --- a/p2pvr/ice/dvb.ice +++ b/p2pvr/ice/dvb.ice @@ -41,7 +41,7 @@ module P2PVR { idempotent void TuneTo(DVBSI::Delivery d) throws DeviceError; idempotent void ScanAndSendNetworkInformation(RawDataClient * client) throws DeviceError, DataHandlingException; }; - + exception NoSuitableDeviceAvailable { }; interface Devices { @@ -65,7 +65,6 @@ module P2PVR { // Remove a device idempotent void Remove(string frontend); }; - }; #endif diff --git a/p2pvr/ice/dvbsi.ice b/p2pvr/ice/dvbsi.ice index aae3fd2..732aa00 100644 --- a/p2pvr/ice/dvbsi.ice +++ b/p2pvr/ice/dvbsi.ice @@ -10,7 +10,7 @@ module DVBSI { // Descriptors class Delivery { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int TransportStreamId; long Frequency; }; @@ -48,7 +48,7 @@ module DVBSI { }; struct NetworkService { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int ServiceId; int TransportStreamId; short Type; @@ -57,51 +57,50 @@ module DVBSI { class NetworkTransportStream { int NetworkId; - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int TransportStreamId; int OriginalNetworkId; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] SatelliteDelivery Satellite; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] CableDelivery Cable; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] TerrestrialDelivery Terrestrial; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] NetworkServiceList Services; }; sequence NetworkTransportStreams; class Network { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int NetworkId; optional(1) string Name; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] NetworkTransportStreams TransportStreams; }; sequence Networks; class BouquetTransportStream { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int TransportStreamId; - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int OriginalNetworkId; }; sequence BouquetTransportStreamList; class Bouquet { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int BouquetId; optional(1) string Name; optional(2) string DefaultAuthority; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] BouquetTransportStreamList Streams; }; - ["project2:type"] class Service { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int ServiceId; - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int TransportStreamId; bool EitSchedule; bool EitPresentFollowing; @@ -115,10 +114,10 @@ module DVBSI { sequence ServiceList; class TransportStream { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int TransportStreamId; int OriginalNetworkId; - [ "slicer:merge:omit" ] + [ "slicer:db:ignore" ] ServiceList Services; }; @@ -140,11 +139,10 @@ module DVBSI { int OriginalNetworkId; }; - ["project2:type"] class Event { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int ServiceId; - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int EventId; string Title; string TitleLang; diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index 0c9cce3..2d3a7a5 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -6,19 +6,16 @@ #include "dvbsi.ice" module P2PVR { - ["project2:type"] class Event extends DVBSI::Event { - ["slicer:db:auto","slicer:db:pkey"] + ["slicer:db:auto"] int EventUid; bool Current = true; }; sequence Events; - ["project2:type"] exception NotFound { }; // Something that we have recorded. - ["project2:type"] class Recording { ["slicer:db:auto","slicer:db:pkey"] int RecordingId; @@ -30,7 +27,6 @@ module P2PVR { sequence RecordingList; // Something that defines what we would like to record. - ["project2:type"] class Schedule { ["slicer:db:auto","slicer:db:pkey"] int ScheduleId = 0; @@ -52,9 +48,8 @@ module P2PVR { }; // Ids for something to record - ["project2:type"] class ScheduledToRecord { - [ "slicer:merge:key" ] + [ "slicer:db:pkey" ] int EventUid; RecordStatuses RecordStatus; int ScheduleId; @@ -68,7 +63,6 @@ module P2PVR { idempotent void UpdateEvents(); }; - ["project2:type"] exception StorageException { string path; string message; @@ -84,24 +78,17 @@ module P2PVR { interface Recordings { idempotent int NewRecording(Recording rec); - ["project2:task"] idempotent void DeleteRecording(int recordingId); - ["project2:rows"] idempotent RecordingList GetRecordings(); }; interface Schedules { - ["project2:task"] idempotent void DeleteSchedule(int scheduleId); - ["project2:rows"] idempotent Schedule GetSchedule(int scheduleId) throws NotFound; - ["project2:rows"] idempotent ScheduleList GetSchedules(); - ["project2:rows"] idempotent ScheduledToRecordList GetScheduledToRecord(); idempotent int NewSchedule(Schedule newSchedule); idempotent void UpdateSchedule(Schedule newSchedule); - ["project2:task"] idempotent void DoReschedule(); }; @@ -116,28 +103,19 @@ module P2PVR { idempotent DVBSI::Delivery GetDeliveryForTransport(int id) throws NotFound; idempotent DVBSI::Delivery GetDeliveryForSi(); // Get services - ["project2:rows"] idempotent DVBSI::ServiceList GetServices(); - ["project2:rows"] idempotent DVBSI::Service GetService(int id) throws NotFound; // Get events idempotent Events GetEvents(IntSequence eventUids) throws NotFound; - ["project2:rows"] idempotent Event GetEvent(int serviceId, int eventId) throws NotFound; - ["project2:rows"] idempotent Events EventsOnNow(); - ["project2:rows"] idempotent Events EventsInSchedules(); - ["project2:rows"] idempotent Events EventsInSchedule(int scheduleId); - ["project2:rows"] idempotent Events EventsInRange(Common::DateTime from, Common::DateTime to); - ["project2:rows"] idempotent Events EventSearch(optional(1) string keywords, optional(2) int serviceId, optional(3) Common::DateTime from, optional(4) Common::DateTime to); }; interface Recorder { - ["project2:task"] idempotent void RefreshSchedules(); }; }; diff --git a/p2pvr/lib/Jamfile.jam b/p2pvr/lib/Jamfile.jam index 31974b7..0e15277 100644 --- a/p2pvr/lib/Jamfile.jam +++ b/p2pvr/lib/Jamfile.jam @@ -2,23 +2,14 @@ lib slicer : : slicer : : /usr/include/slicer ; lib boost_system ; lib boost_filesystem ; -cpp-pch pch : pch.hpp : - boost_system - boost_filesystem - ..//p2common - ..//adhocutil - ../ice//p2pvrice -; - lib p2pvrlib : - pch [ glob-tree *.cpp ] : boost_system boost_filesystem ../ice//p2pvrice ../dvb//p2pvrdvb - ..//p2common + ..//icetray ..//adhocutil ../ice//p2pvrice slicer diff --git a/p2pvr/lib/bindTimerTask.cpp b/p2pvr/lib/bindTimerTask.cpp index 588ccfc..b3a0150 100644 --- a/p2pvr/lib/bindTimerTask.cpp +++ b/p2pvr/lib/bindTimerTask.cpp @@ -1,4 +1,3 @@ -#include #include "bindTimerTask.h" BindTimerTask::BindTimerTask(const Event & e) : diff --git a/p2pvr/lib/fileHandle.cpp b/p2pvr/lib/fileHandle.cpp index b85d390..08575b3 100644 --- a/p2pvr/lib/fileHandle.cpp +++ b/p2pvr/lib/fileHandle.cpp @@ -1,4 +1,3 @@ -#include #include "fileHandle.h" #include #include diff --git a/p2pvr/lib/fileSink.cpp b/p2pvr/lib/fileSink.cpp new file mode 100644 index 0000000..d3fda8f --- /dev/null +++ b/p2pvr/lib/fileSink.cpp @@ -0,0 +1,26 @@ +#include "fileSink.h" + +FileSink::FileSink(const boost::filesystem::path & path) : + file(fopen(path.string().c_str(), "w")) +{ +} + +FileSink::FileSink(int fd) : + file(fdopen(fd, "w")) +{ +} + +FileSink::~FileSink() +{ + if (file) { + fclose(file); + } +} + +bool +FileSink::NewData(const P2PVR::Data & data, const Ice::Current &) +{ + fwrite(&data.front(), data.size(), 1, file); + return false; +} + diff --git a/p2pvr/lib/fileSink.h b/p2pvr/lib/fileSink.h new file mode 100644 index 0000000..fbd469c --- /dev/null +++ b/p2pvr/lib/fileSink.h @@ -0,0 +1,22 @@ +#ifndef FILESINK_H +#define FILESINK_H + +#include +#include +#include +#include + +class DLL_PUBLIC FileSink : public P2PVR::RawDataClient { + public: + FileSink(const boost::filesystem::path & path); + FileSink(int fd); + ~FileSink(); + + bool NewData(const P2PVR::Data & data, const Ice::Current &); + + private: + FILE * const file; +}; + +#endif + diff --git a/p2pvr/lib/muxer.cpp b/p2pvr/lib/muxer.cpp index cfec6d0..1f306cd 100644 --- a/p2pvr/lib/muxer.cpp +++ b/p2pvr/lib/muxer.cpp @@ -1,6 +1,4 @@ -#include #include "muxer.h" -#include #include #include #include @@ -8,6 +6,8 @@ #include #include +IceTray::Logging::LoggerPtr Muxer::log(LOGMANAGER()->getLogger()); + class MuxerFailure : public P2PVR::DataHandlingException { }; Muxer::Muxer(const P2PVR::RawDataClientPrx & t, const std::string & cmd) : @@ -17,7 +17,7 @@ Muxer::Muxer(const P2PVR::RawDataClientPrx & t, const std::string & cmd) : boost::algorithm::split(params, cmd, isspace, boost::algorithm::token_compress_on); fds = ProcessPipesPtr(new AdHoc::System::ProcessPipes(params, true, true, true)); fcntl(fds->fdIn(), F_SETFL, O_NONBLOCK); - Logger()->messagebf(LOG_INFO, "Muxer::%p started with command '%s'", this, cmd); + log->messagebf(LOG::INFO, "Muxer::%p started with command '%s'", this, cmd); } Muxer::~Muxer() @@ -27,7 +27,7 @@ Muxer::~Muxer() while (waitpid(fds->pid(), &status, WNOHANG) == 0) { ReadMuxerAndSend(5); } - Logger()->messagebf(LOG_INFO, "Muxer::%p finished with status %d", this, status); + log->messagebf(LOG::INFO, "Muxer::%p finished with status %d", this, status); } bool @@ -41,7 +41,7 @@ Muxer::NewData(const P2PVR::Data & data, const Ice::Current &) // Send some input auto w = write(fds->fdIn(), &data[off], data.size() - off); if (w == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { - Logger()->messagebf(LOG_ERR, "Muxer::%p write failed (%d:%s)", this, errno, strerror(errno)); + log->messagebf(LOG::ERR, "Muxer::%p write failed (%d:%s)", this, errno, strerror(errno)); throw MuxerFailure(); } off += w; @@ -125,7 +125,7 @@ Muxer::ReadMuxerAndSend(int waitTime) const boost::algorithm::split(lines, buf, boost::algorithm::is_any_of("\r\n\f"), boost::algorithm::token_compress_on); for (const auto & line : lines) { if (line.empty()) continue; - Logger()->messagebf(LOG_INFO, "Muxer::%p > %s", this, line); + log->messagebf(LOG::INFO, "Muxer::%p > %s", this, line); } } if (closed) return true; diff --git a/p2pvr/lib/muxer.h b/p2pvr/lib/muxer.h index f0563a4..354f229 100644 --- a/p2pvr/lib/muxer.h +++ b/p2pvr/lib/muxer.h @@ -6,6 +6,7 @@ #include #include #include +#include class DLL_PUBLIC Muxer : public P2PVR::RawDataClient { public: @@ -22,6 +23,8 @@ class DLL_PUBLIC Muxer : public P2PVR::RawDataClient { typedef boost::shared_ptr ProcessPipesPtr; ProcessPipesPtr fds; mutable std::mutex lock; + + static IceTray::Logging::LoggerPtr log; }; #endif diff --git a/p2pvr/lib/p2Helpers.cpp b/p2pvr/lib/p2Helpers.cpp deleted file mode 100644 index c58ff1a..0000000 --- a/p2pvr/lib/p2Helpers.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include "p2Helpers.h" -#include - -template <> -VariableType & -operator<<(VariableType & vt, const Common::Duration & d) -{ - return (vt = *d); -} - -template <> -VariableType & -operator<<(VariableType & vt, const Common::DateTime & dt) -{ - return (vt = *dt); -} - -template <> -const VariableType & -operator>>(const VariableType & vt, Common::Duration & d) -{ - const boost::posix_time::time_duration & dur = vt; - d = *dur; - return vt; -} - -template <> -const VariableType & -operator>>(const VariableType & vt, Common::DateTime & dt) -{ - const boost::posix_time::ptime & date = vt; - dt = *date; - return vt; -} - -template <> -const VariableType & -operator>>(const VariableType & vt, short int & v) -{ - v = (int)vt; - return vt; -} diff --git a/p2pvr/lib/p2Helpers.h b/p2pvr/lib/p2Helpers.h deleted file mode 100644 index d94d161..0000000 --- a/p2pvr/lib/p2Helpers.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef ICE_P2_HELPERS_H -#define ICE_P2_HELPERS_H - -#include -#include -#include - -template -DLL_PUBLIC -const VariableType & -operator>>(const VariableType & vt, T & v) -{ - v = vt.as(); - return vt; -} - -template <> -DLL_PUBLIC -const VariableType & -operator>>(const VariableType & vt, Common::Duration & d); - -template <> -DLL_PUBLIC -const VariableType & -operator>>(const VariableType & vt, Common::DateTime & dt); - -template -DLL_PUBLIC -const VariableType & -operator>>(const VariableType & vt, IceUtil::Optional & v) -{ - if (vt.isNull()) { - v = IceUtil::Optional(); - } - else { - v = T(); - vt >> *v; - } - return vt; -} - -template <> -DLL_PUBLIC -const VariableType & -operator>>(const VariableType & vt, short int & v); - -template -DLL_PUBLIC -VariableType & -operator<<(VariableType & vt, const T & v) -{ - vt = v; - return vt; -} - -template <> -DLL_PUBLIC -VariableType & -operator<<(VariableType & vt, const Common::Duration & d); - -template <> -DLL_PUBLIC -VariableType & -operator<<(VariableType & vt, const Common::DateTime & dt); - -template -DLL_PUBLIC -VariableType & -operator<<(VariableType & vt, const IceUtil::Optional & v) -{ - if (v) { - vt << *v; - } - else { - vt = Null(); - } - return vt; -} - -#endif - diff --git a/p2pvr/lib/pch.hpp b/p2pvr/lib/pch.hpp deleted file mode 100644 index 7c96f52..0000000 --- a/p2pvr/lib/pch.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef BOOST_BUILD_PCH_ENABLED -#ifndef P2PVRLIB_PCH -#define P2PVRLIB_PCH - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#endif -#endif - diff --git a/p2pvr/lib/serviceStreamer.cpp b/p2pvr/lib/serviceStreamer.cpp index c80f942..2729ca0 100644 --- a/p2pvr/lib/serviceStreamer.cpp +++ b/p2pvr/lib/serviceStreamer.cpp @@ -1,13 +1,5 @@ -#include #include "serviceStreamer.h" -ServiceStreamer::ServiceStreamer(int sid, P2PVR::RawDataClientPrx t, const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & a) : - ServiceStreamerCore(sid, t, t, t, - P2PVR::DevicesPrx::checkedCast(a->createProxy(ic->stringToIdentity("GlobalDevices"))), a), - si(P2PVR::SIPrx::checkedCast(a->createProxy(ic->stringToIdentity("SI")))) -{ -} - ServiceStreamer::ServiceStreamer(int sid, P2PVR::RawDataClientPrx t, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a) : ServiceStreamerCore(sid, t, t, t, d, a), si(s) diff --git a/p2pvr/lib/serviceStreamer.h b/p2pvr/lib/serviceStreamer.h index c4aa93e..230764e 100644 --- a/p2pvr/lib/serviceStreamer.h +++ b/p2pvr/lib/serviceStreamer.h @@ -6,7 +6,6 @@ class DLL_PUBLIC ServiceStreamer : public ServiceStreamerCore { public: - ServiceStreamer(int sid, P2PVR::RawDataClientPrx, const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & a); ServiceStreamer(int sid, P2PVR::RawDataClientPrx, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a); ~ServiceStreamer(); diff --git a/p2pvr/lib/serviceStreamerCore.cpp b/p2pvr/lib/serviceStreamerCore.cpp index 4e253d2..2667569 100644 --- a/p2pvr/lib/serviceStreamerCore.cpp +++ b/p2pvr/lib/serviceStreamerCore.cpp @@ -1,8 +1,9 @@ -#include #include "serviceStreamerCore.h" #include #include "bindSiParserHandler.h" +IceTray::Logging::LoggerPtr ServiceStreamerCore::log(LOGMANAGER()->getLogger()); + ServiceStreamerCore::ServiceStreamerCore(int sid, P2PVR::RawDataClientPrx pat, P2PVR::RawDataClientPrx pmt, P2PVR::RawDataClientPrx ser, P2PVR::DevicesPrx d, Ice::ObjectAdapterPtr a) : adapter(a), @@ -28,7 +29,7 @@ ServiceStreamerCore::HandlePAT(ProgramAssociationMapPtr pam) const auto p = pam->find(serviceId); if (p != pam->end() && p->second != pmtStream) { pmtStream = p->second; - Logger()->messagef(LOG_DEBUG, "%s: Got ProgramAssociationMap, pmtStream now = %d", __PRETTY_FUNCTION__, pmtStream); + log->messagef(LOG::DEBUG, "%s: Got ProgramAssociationMap, pmtStream now = %d", __PRETTY_FUNCTION__, pmtStream); stopHandle(pmtHandle); pmtHandle = tuner->StartSendingSection(pmtStream, pmtParser); } @@ -47,7 +48,7 @@ ServiceStreamerCore::HandlePMT(DVBSI::ProgramMapPtr pmp) } if (strms != streams) { streams = strms; - Logger()->messagebf(LOG_DEBUG, "%s: Got ProgramMap, switching to %d streams", __PRETTY_FUNCTION__, streams.size()); + log->messagebf(LOG::DEBUG, "%s: Got ProgramMap, switching to %d streams", __PRETTY_FUNCTION__, streams.size()); stopHandle(serviceHandle); serviceHandle = tuner->StartSendingTS(P2PVR::PacketIds(streams.begin(), streams.end()), serTarget); } diff --git a/p2pvr/lib/serviceStreamerCore.h b/p2pvr/lib/serviceStreamerCore.h index 1db80f8..2654193 100644 --- a/p2pvr/lib/serviceStreamerCore.h +++ b/p2pvr/lib/serviceStreamerCore.h @@ -9,6 +9,7 @@ #include #include #include +#include class DLL_PUBLIC ServiceStreamerCore { public: @@ -40,6 +41,8 @@ class DLL_PUBLIC ServiceStreamerCore { typedef std::set Streams; Streams streams; int serviceHandle; + + static IceTray::Logging::LoggerPtr log; }; #endif -- cgit v1.2.3