summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-07-30 00:15:33 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-07-30 00:15:33 +0100
commitadd5644f64c86b635b62d560187c993aa7072b76 (patch)
tree70aaf1ae49ef4f27c4b20809250d5f5d63921d0e
parentSingle definition of glibmm (diff)
downloadp2pvr-add5644f64c86b635b62d560187c993aa7072b76.tar.bz2
p2pvr-add5644f64c86b635b62d560187c993aa7072b76.tar.xz
p2pvr-add5644f64c86b635b62d560187c993aa7072b76.zip
BIG migration from Project2 based to IceTray/Slicer :D
-rw-r--r--libtmdb/testCallMockApi.cpp7
-rw-r--r--p2pvr/.p2config8
-rw-r--r--p2pvr/Jamfile.jam58
-rw-r--r--p2pvr/carddaemon/Jamfile.jam3
-rw-r--r--p2pvr/carddaemon/carddaemon.cpp16
-rw-r--r--p2pvr/daemon/Jamfile.jam23
-rw-r--r--p2pvr/daemon/containerIterator.h40
-rw-r--r--p2pvr/daemon/daemon.cpp61
-rw-r--r--p2pvr/daemon/dbClient.cpp56
-rw-r--r--p2pvr/daemon/dbClient.h111
-rw-r--r--p2pvr/daemon/globalDevices.cpp29
-rw-r--r--p2pvr/daemon/globalDevices.h12
-rw-r--r--p2pvr/daemon/maintenance.cpp90
-rw-r--r--p2pvr/daemon/maintenance.h26
-rw-r--r--p2pvr/daemon/maintenance/events.cpp118
-rw-r--r--p2pvr/daemon/maintenance/network.cpp80
-rw-r--r--p2pvr/daemon/maintenance/services.cpp48
-rw-r--r--p2pvr/daemon/muxedFileSink.cpp12
-rw-r--r--p2pvr/daemon/muxedFileSink.h3
-rw-r--r--p2pvr/daemon/objectRowState.cpp89
-rw-r--r--p2pvr/daemon/objectRowState.h48
-rw-r--r--p2pvr/daemon/p2pvr-int.ice4
-rw-r--r--p2pvr/daemon/pch.hpp20
-rw-r--r--p2pvr/daemon/privateExecContext.cpp14
-rw-r--r--p2pvr/daemon/privateExecContext.h13
-rw-r--r--p2pvr/daemon/recorder.cpp44
-rw-r--r--p2pvr/daemon/recorder.h17
-rw-r--r--p2pvr/daemon/recordings.cpp49
-rw-r--r--p2pvr/daemon/recordings.h10
-rw-r--r--p2pvr/daemon/resources.h12
-rw-r--r--p2pvr/daemon/schedulers/bitDumbScheduler.cpp1
-rw-r--r--p2pvr/daemon/schedules.cpp111
-rw-r--r--p2pvr/daemon/schedules.h21
-rw-r--r--p2pvr/daemon/si.cpp122
-rw-r--r--p2pvr/daemon/si.h9
-rw-r--r--p2pvr/daemon/storage.cpp40
-rw-r--r--p2pvr/daemon/storage.h19
-rw-r--r--p2pvr/daemon/unittests/Jamfile.jam221
-rw-r--r--p2pvr/daemon/unittests/datasources/postgres.xml4
-rw-r--r--p2pvr/daemon/unittests/dummySelect.sql1
-rw-r--r--p2pvr/daemon/unittests/mockDefs.cpp12
-rw-r--r--p2pvr/daemon/unittests/mockDefs.h18
-rw-r--r--p2pvr/daemon/unittests/mockDevices.h3
-rw-r--r--p2pvr/daemon/unittests/mockRecorder.h3
-rw-r--r--p2pvr/daemon/unittests/mockScheduler.h3
-rw-r--r--p2pvr/daemon/unittests/testEmbedding.cpp14
-rw-r--r--p2pvr/daemon/unittests/testErrorHandling.cpp66
-rw-r--r--p2pvr/daemon/unittests/testMaint.cpp115
-rw-r--r--p2pvr/daemon/unittests/testRecording.cpp54
-rw-r--r--p2pvr/daemon/unittests/testRecordings.cpp48
-rw-r--r--p2pvr/daemon/unittests/testSched.cpp53
-rw-r--r--p2pvr/daemon/unittests/testSi.cpp34
-rw-r--r--p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp86
-rw-r--r--p2pvr/daemon/unittests/testStorage.cpp69
-rw-r--r--p2pvr/daemonbase/Jamfile.jam23
-rw-r--r--p2pvr/daemonbase/daemonBase.cpp64
-rw-r--r--p2pvr/daemonbase/daemonBase.h32
-rw-r--r--p2pvr/daemonbase/p2LoggerWrapper.cpp45
-rw-r--r--p2pvr/daemonbase/p2LoggerWrapper.h25
-rw-r--r--p2pvr/daemonbase/pch.hpp9
-rw-r--r--p2pvr/datasources/postgres.xml4
-rw-r--r--p2pvr/devices/Jamfile.jam25
-rw-r--r--p2pvr/devices/frontend.cpp9
-rw-r--r--p2pvr/devices/frontend.h4
-rw-r--r--p2pvr/devices/frontends/ofdm.cpp29
-rw-r--r--p2pvr/devices/localDevices.cpp56
-rw-r--r--p2pvr/devices/localDevices.h13
-rw-r--r--p2pvr/devices/mockTuner.cpp27
-rw-r--r--p2pvr/devices/mockTuner.h4
-rw-r--r--p2pvr/devices/pch.hpp20
-rw-r--r--p2pvr/devices/sampleSiData/events1.datxzbin1112856 -> 1112857 bytes
-rw-r--r--p2pvr/devices/tuner.cpp95
-rw-r--r--p2pvr/devices/tuner.h27
-rw-r--r--p2pvr/devices/tunerSendSi.cpp13
-rw-r--r--p2pvr/devices/tunerSendSi.h2
-rw-r--r--p2pvr/devices/tunerSendTs.cpp5
-rw-r--r--p2pvr/devices/tunerSendTs.h2
-rw-r--r--p2pvr/dvb/Jamfile.jam6
-rw-r--r--p2pvr/dvb/bindDataHandler.h3
-rw-r--r--p2pvr/dvb/pch.hpp22
-rw-r--r--p2pvr/dvb/siParsers/event.cpp1
-rw-r--r--p2pvr/dvb/siParsers/network.cpp24
-rw-r--r--p2pvr/dvb/siParsers/programAssociation.cpp1
-rw-r--r--p2pvr/dvb/siParsers/programMap.cpp2
-rw-r--r--p2pvr/dvb/siParsers/service.cpp1
-rw-r--r--p2pvr/dvb/siParsers/table.cpp10
-rw-r--r--p2pvr/dvb/siParsers/table.h4
-rw-r--r--p2pvr/dvb/unittests/Jamfile.jam3
-rw-r--r--p2pvr/dvb/unittests/createBroadcast.cpp2
-rw-r--r--p2pvr/dvb/unittests/createSamples.cpp2
-rwxr-xr-xp2pvr/etc/init.d/p2pvrcardd26
-rwxr-xr-xp2pvr/etc/init.d/p2pvrd26
-rw-r--r--p2pvr/etc/p2pvrcd/icebox.config7
-rw-r--r--p2pvr/etc/p2pvrd/icebox.config (renamed from p2pvr/etc/p2config)9
-rw-r--r--p2pvr/etc/systemd/p2pvrcardd.service10
-rw-r--r--p2pvr/etc/systemd/p2pvrd.service12
-rw-r--r--p2pvr/ice/Jamfile.jam2
-rw-r--r--p2pvr/ice/converters.cpp30
-rw-r--r--p2pvr/ice/dvb.ice3
-rw-r--r--p2pvr/ice/dvbsi.ice40
-rw-r--r--p2pvr/ice/p2pvr.ice26
-rw-r--r--p2pvr/lib/Jamfile.jam11
-rw-r--r--p2pvr/lib/bindTimerTask.cpp1
-rw-r--r--p2pvr/lib/fileHandle.cpp1
-rw-r--r--p2pvr/lib/fileSink.cpp (renamed from p2pvr/daemonbase/fileSink.cpp)1
-rw-r--r--p2pvr/lib/fileSink.h (renamed from p2pvr/daemonbase/fileSink.h)0
-rw-r--r--p2pvr/lib/muxer.cpp12
-rw-r--r--p2pvr/lib/muxer.h3
-rw-r--r--p2pvr/lib/p2Helpers.cpp43
-rw-r--r--p2pvr/lib/p2Helpers.h81
-rw-r--r--p2pvr/lib/pch.hpp20
-rw-r--r--p2pvr/lib/serviceStreamer.cpp8
-rw-r--r--p2pvr/lib/serviceStreamer.h1
-rw-r--r--p2pvr/lib/serviceStreamerCore.cpp7
-rw-r--r--p2pvr/lib/serviceStreamerCore.h3
115 files changed, 984 insertions, 2261 deletions
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 : : <name>boost_unit_test_framework ;
lib adhocutil : : : : <include>/usr/include/adhocutil ;
+lib icetray : : : : <include>/usr/include/dbpp <include>/usr/include/adhocutil <include>/usr/include/icetray ;
+lib IceBox ;
-alias p2common : ..//glibmm : : :
- <include>/usr/include/project2/common
- <include>/usr/include/project2/lib
- <linkflags>"-lp2common"
-;
-alias p2cgi : ..//glibmm : : :
- <include>/usr/include/project2/cgi
- <linkflags>"-lp2cgicommon"
-;
-alias p2xml : ..//glibmm : : :
- <include>/usr/include/project2/xml
- <linkflags>"-lp2xml"
-;
-alias p2sql : ..//glibmm : : :
- <include>/usr/include/dbpp
- <include>/usr/include/project2/sql
- <include>/usr/include/project2/basics
- <linkflags>"-lp2sql -ldbppcore"
-;
-alias p2streams : ..//glibmm : : :
- <include>/usr/include/project2/streams
- <linkflags>"-lp2streams"
-;
-alias p2ut : ..//glibmm : : :
- <include>/usr/include/project2/ut
- <linkflags>"-lp2ut -lp2ut"
-;
-alias p2basics : ..//glibmm : : :
- <include>/usr/include/project2/basics
- <linkflags>"-lp2basics"
-;
-alias p2ice : ..//glibmm : : :
- <include>/usr/include/project2/ice
- <linkflags>"-lp2ice -lp2iceclient"
-;
-alias p2daemonlib : ..//glibmm : : :
- <cflags>"-I /usr/include/project2/daemon/lib"
- <linkflags>"-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 : <location>./testing ;
+install debuginstall : dvb//p2pvrdvb devices//p2pvrdevices lib//p2pvrlib carddaemon//p2pvrcarddaemon daemon//p2pvrdaemon ice//p2pvrice ../libtmdb//tmdb : <location>./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 :
:
<library>..//adhocutil
<library>../ice//p2pvrice
+ <library>..//icetray
+ <library>..//IceBox
<library>../devices//p2pvrdevices
- <library>../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 <daemonBase.h>
+#include <icetrayService.h>
#include "localDevices.h"
#include <Ice/ObjectAdapter.h>
+#include <Ice/Communicator.h>
+#include <IceUtil/Timer.h>
-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 : : <name>slicer : : <include>/usr/include/slicer ;
lib slicer-db : : <name>slicer-db : : <include>/usr/include/slicer ;
+lib boost_program_options ;
+lib dbppcore ;
-cpp-pch pch : pch.hpp :
- <library>../ice//p2pvrice
- <library>../lib//p2pvrlib
- <library>../dvb//p2pvrdvb
- <library>..//p2sql
- <library>../devices//p2pvrdevices
- <library>../daemonbase//p2pvrdaemonbase
- <slicer>yes
-;
+path-constant me : . ;
lib p2pvrdaemon :
- pch
[ glob-tree *.ice *.cpp *.sql : bin unittests ]
:
<library>../ice//p2pvrice
<library>../lib//p2pvrlib
<library>../dvb//p2pvrdvb
<library>../../libtmdb//tmdb
- <library>..//p2sql
<library>../devices//p2pvrdevices
- <library>../daemonbase//p2pvrdaemonbase
+ <library>boost_program_options
+ <library>dbppcore
<library>..//adhocutil
+ <library>..//icetray
+ <library>..//IceBox
<implicit-dependency>../../libtmdb//tmdb
<library>slicer
<library>slicer-db
<slicer>yes
<include>.
+ <icetray.sql.basedir>$(me)
+ <icetray.sql.namespace>P2PVR
: :
<include>.
<library>../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 <iHaveSubTasks.h>
-#include "objectRowState.h"
-
-template <typename T>
-class ContainerIterator : public IHaveSubTasks {
- public:
- ContainerIterator(const T * con, const SelectedColumns & sc) :
- SourceObject(__PRETTY_FUNCTION__),
- IHaveSubTasks(NULL),
- binder(boost::bind(&BindColumns<typename T::value_type>, _1, sc, _2)),
- container(con)
- {
- }
-
- void execute(ExecContext * ec) const
- {
- ObjectRowStateTmpl<typename T::value_type> rs;
- for (const auto & i : *container) {
- binder(rs, i);
- rs.process(ec, boost::bind(&ContainerIterator::executeChildren, this, ec));
- }
- }
-
- private:
- boost::function<void(RowState &, const typename T::value_type &)> 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 <daemonBase.h>
-#include <options.h>
#include "localDevices.h"
#include "globalDevices.h"
#include "maintenance.h"
@@ -10,44 +8,51 @@
#include "recordings.h"
#include <Ice/ObjectAdapter.h>
#include <tmdb-proxy.h>
+#include <icetrayService.h>
// 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<P2PVRTMDb> tmdbOpts;
+
+ IceUtil::TimerPtr timer = new IceUtil::Timer();
+ auto db = getConnectionPool(ic, "postgresql", "postgres");
+ auto localDevices = add<P2PVR::LocalDevices>(ic, adapter, new LocalDevices(adapter, timer), "Devices");
+ auto globalDevices = add<P2PVR::Devices>(ic, adapter, new GlobalDevices(), "GlobalDevices");
+ auto maintenance = add<P2PVR::Maintenance>(ic, adapter, new Maintenance(db, adapter, timer), "Maintenance");
+ auto si = add<P2PVR::SI>(ic, adapter, new SI(db), "SI");
+ auto schedules = add<P2PVR::Schedules>(ic, adapter, new Schedules(db), "Schedules");
+ auto storage = add<P2PVR::Storage>(ic, adapter, new Storage(), "Storage");
+ auto recorder = add<P2PVR::Recorder>(ic, adapter, new Recorder(adapter, timer), "Recorder");
+ auto recordings = add<P2PVR::Recordings>(ic, adapter, new Recordings(db), "Recordings");
+ auto tmdb = add<TMDb::Proxy>(ic, adapter, new TMDb::Proxy(tmdbOpts->baseUrl, tmdbOpts->apikey), "TMDb");
}
- void addServants(const Ice::ObjectAdapterPtr & adapter, const IceUtil::TimerPtr & timer) const
+ template<typename Object>
+ typename Object::ProxyType add(const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & adapter, const IceUtil::Handle<Object> & 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 <pch.hpp>
-#include "dbClient.h"
-#include <sqlMergeTask.h>
-
-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 <commonObjects.h>
-#include <variableType.h>
-#include <list>
-#include <selectcommand.h>
-#include <modifycommand.h>
-#include <scopeExit.h>
-#include <rdbmsDataSource.h>
-#include <sqlVariableBinder.h>
-#include <sqlHandleAsVariableType.h>
-#include "p2Helpers.h"
-#include <slicer/slicer.h>
-
-class SqlMergeTask;
-
-class DatabaseClient : public virtual CommonObjects {
- public:
- typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
- typedef boost::shared_ptr<DB::ModifyCommand> 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 <typename... Args>
- std::pair<RdbmsDataSource::ConnectionRef, ModifyPtr> Modify(const std::string & sql, const Args & ... args) const
- {
- auto db = dataSource<RdbmsDataSource>("postgres")->getWritable();
- auto cmd = ModifyPtr(db->newModifyCommand(sql));
- Bind(cmd.get(), 0, args...);
- return {db, cmd};
- }
-
- template <typename SerializerType, typename Obj, typename ... ExtraArgs>
- void Store(const Obj & o, const ExtraArgs & ... ea) const
- {
- auto db = dataSource<RdbmsDataSource>("postgres")->getWritable();
- Slicer::SerializeAny<SerializerType>(o, db.get(), ea...);
- }
-
- template <typename... Args>
- std::pair<RdbmsDataSource::ConnectionRef, SelectPtr> Select(const std::string & sql, const Args & ... args) const
- {
- auto db = dataSource<RdbmsDataSource>("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 <typename Rtn, typename... Args>
- Rtn SelectScalar(const std::string & sql, const Args & ... args) const
- {
- auto db = dataSource<RdbmsDataSource>("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 <typename Arg>
- static void Bind(DB::Command * cmd, unsigned int offset, const Arg & arg)
- {
- VariableType v;
- v << arg;
- boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(cmd, offset), v);
- }
-
- template <typename Arg, typename... Args>
- 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<void(DataSourcePtr)> 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 <pch.hpp>
#include "globalDevices.h"
#include <Ice/Ice.h>
-std::vector<std::string> 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 (<adapter>:<endpoint>)")
-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 (<object>:<endpoint>)")
+)
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<std::string> 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<std::string> Devices;
+ IceTray::OptionsResolver<Options> 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 <pch.hpp>
#include <logger.h>
#include <thread>
#include "maintenance.h"
@@ -6,24 +5,26 @@
#include "bindTimerTask.h"
#include <linux/dvb/frontend.h>
#include <cxxabi.h>
+#include <scopeExit.h>
-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::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 <p2pvr.h>
#include <IceUtil/Timer.h>
-#include "dbClient.h"
+#include <abstractDatabaseClient.h>
+#include <options.h>
+#include <logger.h>
#include <visibility.h>
-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> 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 <pch.hpp>
#include "../maintenance.h"
#include <siParsers/event.h>
-#include <sqlMergeTask.h>
#include <Ice/Communicator.h>
-#include <p2Helpers.h>
-#include <containerIterator.h>
#include <temporaryIceAdapterObject.h>
#include <commonHelpers.h>
-#include <resources.h>
-#include <privateExecContext.h>
+#include <db/sqlTablePatchSerializer.h>
+#include <tablepatch.h>
+#include <sqlWriter.h>
+#include <slicer/modelPartsTypes.impl.h>
+#include "sql/Maint_pruneEvents.sql.h"
-ResourceString(Maint_pruneEvents, sql_Maint_pruneEvents);
+class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> {
+ 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<DVBSI::EventPtr>(rowState, ecs, e);
- rowState.process(ec, callBack);
- return false;
- }
+ private:
+ const Consumer & consumer;
+ const IceTray::Logging::LoggerPtr logger;
+ };
- private:
- ObjectRowStateTmpl<DVBSI::EventPtr> 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<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> 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<DVBSI::EventPtr>(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<Slicer::SqlTablePatchSerializer>(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 <pch.hpp>
#include "../maintenance.h"
#include <siParsers/network.h>
-#include <sqlMergeTask.h>
#include <Ice/Communicator.h>
-#include <p2Helpers.h>
-#include <containerIterator.h>
#include <temporaryIceAdapterObject.h>
-#include <privateExecContext.h>
+#include <tablepatch.h>
+#include <db/sqlInsertSerializer.h>
+#include <db/sqlTablePatchSerializer.h>
-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<DVBSI::NetworkPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2));
- std::vector<DVBSI::NetworkPtr> networks = { n };
- mergeNetwork.sources.insert(new ContainerIterator<std::vector<DVBSI::NetworkPtr>>(&networks, ncs));
- mergeNetwork.loadComplete(commonObjects);
- mergeNetwork.execute(this);
+ DB::TablePatch mergeNetwork;
+ mergeNetwork.dest = "networks";
+ Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(n, dbc, mergeNetwork);
- SqlMergeTask mergeTransports("postgres", "transportstreams");
- auto tscs = CreateColumns<DVBSI::NetworkTransportStreamPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2));
- mergeTransports.sources.insert(new ContainerIterator<DVBSI::NetworkTransportStreams>(&n->TransportStreams, tscs));
- mergeTransports.loadComplete(commonObjects);
- mergeTransports.execute(this);
+ DB::TablePatch mergeTransportStreams;
+ mergeTransportStreams.dest = "transportstreams";
+ Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(n->TransportStreams, dbc, mergeTransportStreams);
mergeDelivery<DVBSI::TerrestrialDeliveryPtr, &DVBSI::NetworkTransportStream::Terrestrial>("delivery_dvbt", n);
mergeDelivery<DVBSI::SatelliteDeliveryPtr, &DVBSI::NetworkTransportStream::Satellite>("delivery_dvbs", n);
mergeDelivery<DVBSI::CableDeliveryPtr, &DVBSI::NetworkTransportStream::Cable>("delivery_dvbc", n);
- SqlMergeTask mergeServices("postgres", "services");
- auto scs = CreateColumns<DVBSI::NetworkService>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2));
- for (const auto & s : n->TransportStreams) {
- mergeServices.sources.insert(new ContainerIterator<DVBSI::NetworkServiceList>(&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<Slicer::SqlTablePatchSerializer>(services, dbc, mergeServices);
+
return false;
}
private:
template <class Delivery, Delivery DVBSI::NetworkTransportStream::*member>
void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n)
{
- SqlMergeTask merge("postgres", table);
- auto dcs = CreateColumns<Delivery>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2));
+ DB::TablePatch tp;
+ tp.dest = table;
std::vector<Delivery> dels;
for (const auto & s : n->TransportStreams) {
if (auto d = s.get()->*member) {
dels.push_back(d);
}
}
- merge.sources.insert(new ContainerIterator<decltype(dels)>(&dels, dcs));
- merge.loadComplete(commonObjects);
- merge.execute(this);
+ Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(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<P2PVR::RawDataClient> 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 <pch.hpp>
#include "../maintenance.h"
#include <siParsers/service.h>
-#include <sqlMergeTask.h>
+#include <tablepatch.h>
#include <Ice/Communicator.h>
-#include <p2Helpers.h>
-#include <containerIterator.h>
#include <temporaryIceAdapterObject.h>
-#include <privateExecContext.h>
+#include <slicer/slicer.h>
+#include <db/sqlTablePatchSerializer.h>
+#include <tablepatch.h>
-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<DVBSI::ServicePtr>(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<DVBSI::ServiceList>(&ts->Services, scs));
- mergeServices.loadComplete(commonObjects);
- mergeServices.execute(this);
+ DB::TablePatch mergeServices;
+ mergeServices.dest = "services";
+ mergeServices.doDeletes = false;
+ mergeServices.doInserts = false;
+ Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(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<P2PVR::RawDataClient> 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 <pch.hpp>
#include "muxedFileSink.h"
#include <logger.h>
#include <poll.h>
@@ -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<MuxedFileSink>())
{
std::vector<std::string> 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 <boost/filesystem/path.hpp>
#include <boost/shared_ptr.hpp>
#include <processPipes.h>
+#include <logger.h>
class MuxedFileSink : public P2PVR::RawDataClient {
public:
@@ -21,6 +22,8 @@ class MuxedFileSink : public P2PVR::RawDataClient {
typedef boost::shared_ptr<AdHoc::System::ProcessPipes> 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 <logger.h>
-
-const std::string md_mergeKey("merge:key");
-const std::string md_mergeOmit("merge:omit");
-
-bool
-mdHasFlag(const std::list<std::string> & 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<boost::posix_time::time_duration>,
- public Slicer::TValueTarget<boost::posix_time::ptime> {
- 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<SqlTarget> 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 <boost/function.hpp>
-#include <string>
-#include <rowSet.h>
-#include <slicer/modelParts.h>
-
-typedef boost::function<void(const std::string &, bool)> ColumnCreator;
-typedef boost::function<void(const ColumnCreator &)> ColumnSpecifier;
-typedef std::vector<bool> SelectedColumns;
-
-void BindColumns(Slicer::ModelPartPtr, const SelectedColumns &, RowState &);
-
-template <typename V>
-void BindColumns(RowState & rs, const SelectedColumns & sc, const V & v)
-{
- BindColumns(Slicer::ModelPart::CreateFor(const_cast<V &>(v)), sc, rs);
-}
-
-SelectedColumns CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &);
-
-template <typename V>
-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 <typename T>
-class ObjectRowStateTmpl : public ObjectRowState {
- public:
- ObjectRowStateTmpl(const ColumnSpecifier & cs = CreateColumns<T>) : 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 <common.ice>
+#include <dvbsi.ice>
module P2PVR {
class ScheduleCandidate {
@@ -12,5 +13,8 @@ module P2PVR {
};
sequence<ScheduleCandidate> ScheduleCandidates;
+ sequence<DVBSI::SatelliteDelivery> SatelliteDeliverySeq;
+ sequence<DVBSI::CableDelivery> CableDeliverySeq;
+ sequence<DVBSI::TerrestrialDelivery> 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 <Ice/Ice.h>
-#include <glibmm.h>
-#include <boost/bind.hpp>
-#include <boost/function/function_fwd.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <list>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#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 <execContext.h>
-
-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 <pch.hpp>
#include "recorder.h"
#include "bindTimerTask.h"
#include <boost/bind.hpp>
@@ -10,22 +9,29 @@
#include "muxer.h"
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
+#include <boost/lexical_cast.hpp>
-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::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<std::mutex> 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<std::string>(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 : "<no 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<std::mutex> 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 <mutex>
#include "serviceStreamer.h"
#include <visibility.h>
+#include <logger.h>
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<IceUtil::TimerTaskPtr> 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> 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 <pch.hpp>
#include "recordings.h"
-#include "resources.h"
#include <Ice/Ice.h>
#include <logger.h>
#include <slicer/slicer.h>
#include <slicer/db/sqlSelectDeserializer.h>
#include <slicer/db/sqlInsertSerializer.h>
+#include <sql/Recordings_delete.sql.h>
+#include <sql/Recordings_getAll.sql.h>
+#include <sql/Recordings_getStorage.sql.h>
-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::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<Slicer::SqlFetchIdInsertSerializer>(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<Slicer::SqlFetchIdInsertSerializer>(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<Slicer::SqlSelectDeserializer, P2PVR::RecordingList>(
- *Select(Recording_GetAll).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::RecordingList>(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 <p2pvr.h>
#include <string>
-#include "dbClient.h"
#include <visibility.h>
+#include <logger.h>
+#include <abstractDatabaseClient.h>
-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 <pch.hpp>
#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 <pch.hpp>
#include "schedules.h"
-#include <rdbmsDataSource.h>
#include <logger.h>
#include <Ice/Ice.h>
-#include <sqlVariableBinder.h>
-#include <sqlMergeTask.h>
-#include "p2Helpers.h"
#include "commonHelpers.h"
-#include "containerIterator.h"
-#include "resources.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <factory.impl.h>
#include <slicer/db/sqlSelectDeserializer.h>
#include <slicer/db/sqlInsertSerializer.h>
#include <slicer/db/sqlUpdateSerializer.h>
+#include <slicer/db/sqlTablePatchSerializer.h>
+#include <tablepatch.h>
#include <p2pvr-int.h>
-#include <privateExecContext.h>
-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>());
+
+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<Slicer::SqlSelectDeserializer, P2PVR::ScheduleCandidates>(
- *Select(Schedules_getCandidates).second);
+ auto episodes = fetch<P2PVR::ScheduleCandidates>(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<ShowingPtr> 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<P2PVR::ScheduledToRecordPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2));
- mergeRecords.sources.insert(new ContainerIterator<P2PVR::ScheduledToRecordList>(&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<Slicer::SqlTablePatchSerializer>(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<Slicer::SqlSelectDeserializer, P2PVR::ScheduleList>(
- *Select(Schedules_selectAll).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::ScheduleList>(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<Slicer::SqlSelectDeserializer, P2PVR::ScheduleList>(
- *Select(Schedules_selectById, id).second);
+ logger->messagebf(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ auto schedules = fetch<P2PVR::ScheduleList>(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<Slicer::SqlSelectDeserializer, P2PVR::ScheduledToRecordList>(
- *Select(Schedules_scheduledToRecord).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::ScheduledToRecordList>(P2PVR::sql::Schedules_scheduledToRecord);
}
Ice::Int
Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
{
- TxHelper tx(this);
- Store<Slicer::SqlFetchIdInsertSerializer>(s, "schedules");
+ auto dbc = db->get();
+ Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(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<Slicer::SqlUpdateSerializer>(s, "schedules");
+ auto dbc = db->get();
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(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 <p2pvr.h>
#include <options.h>
-#include "dbClient.h"
+#include <abstractDatabaseClient.h>
#include <factory.h>
#include <visibility.h>
+#include <intrusivePtrBase.h>
+#include <logger.h>
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> options;
+ static IceTray::Logging::LoggerPtr logger;
};
typedef AdHoc::Factory<EpisodeGroup, const Episodes &> 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 <pch.hpp>
#include "si.h"
-#include "resources.h"
#include <slicer/db/sqlSelectDeserializer.h>
#include <slicer/common.h>
#include <slicer/db/sqlExceptions.h>
@@ -8,36 +6,41 @@
#include <slicer/slicer.h>
#include <logger.h>
-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::SI(IceTray::DatabasePoolPtr db) :
+ IceTray::AbstractDatabaseClient(db)
+{
+}
DVBSI::Networks
SI::GetNetworks(const Ice::Current &)
{
- Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::Networks>(
- *Select(SI_allNetworks).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<DVBSI::Networks>(P2PVR::sql::SI_allNetworks);
}
P2PVR::Deliveries
SI::GetAllDeliveries(const Ice::Current &)
{
- Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- auto rtn = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Deliveries>(
- *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<P2PVR::Deliveries>("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<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_deliveryForTransport, id).second, "delivery_type");
+ logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return fetch<DVBSI::DeliveryPtr>("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<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_serviceNextUsed).second, "delivery_type");
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<DVBSI::DeliveryPtr>("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<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_deliveryForService, id).second, "delivery_type");
+ logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return fetch<DVBSI::DeliveryPtr>("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<Slicer::SqlSelectDeserializer, DVBSI::ServiceList>(
- *Select(SI_servicesSelectAll).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<DVBSI::ServiceList>(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<Slicer::SqlSelectDeserializer, DVBSI::ServiceList>(
- *Select(SI_servicesSelectById, id).second);
+ logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ auto rtn = fetch<DVBSI::ServiceList>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventByUid, uid).second);
+ auto list = fetch<P2PVR::Events>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventById, serviceId, eventId).second);
+ logger->messagef(LOG::DEBUG, "%s(s=%d, e=%d)", __PRETTY_FUNCTION__, serviceId, eventId);
+ auto rtn = fetch<P2PVR::Events>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventsOnNow).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::Events>(P2PVR::sql::SI_eventsOnNow);
+}
+
+namespace IceTray {
+ template<>
+ void
+ AbstractDatabaseClient::bind1<Common::DateTime>(int x, DB::Command * cmd, const Common::DateTime &);
+}
+
+template<>
+void
+IceTray::AbstractDatabaseClient::bind1<Common::DateTime>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventsInRange, from, to).second);
+ logger->messagebf(LOG::DEBUG, "%s([%s]-[%s])", from, to, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::Events>(P2PVR::sql::SI_eventsInRange, from, to);
}
P2PVR::Events
SI::EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & 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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords).second);
+ return fetch<P2PVR::Events>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventsInSchedules).second);
+ logger->message(LOG::DEBUG, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::Events>(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<Slicer::SqlSelectDeserializer, P2PVR::Events>(
- *Select(SI_eventsInSchedule, scheduleId).second);
+ logger->messagebf(LOG::DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__);
+ return fetch<P2PVR::Events>(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 <p2pvr.h>
-#include "dbClient.h"
+#include <abstractDatabaseClient.h>
#include <visibility.h>
+#include <logger.h>
-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<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & 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 <pch.hpp>
#include "storage.h"
#include "fileSink.h"
#include "muxedFileSink.h"
@@ -7,34 +6,39 @@
#include <boost/filesystem/operations.hpp>
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<Storage>());
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<size_t>(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 <p2pvr.h>
#include <options.h>
#include <string>
+#include <set>
#include <boost/filesystem/path.hpp>
#include "temporaryIceAdapterObject.h"
#include <visibility.h>
+#include <logger.h>
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<P2PVR::RawDataClient> OpenFile;
typedef boost::shared_ptr<OpenFile> OpenFilePtr;
typedef std::set<OpenFilePtr> OpenFiles;
OpenFiles openFiles;
-
- static std::string muxerCommand;
- static boost::filesystem::path root;
+ IceTray::OptionsResolver<Options> 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 : : : : <include>/usr/include/dbpp ;
lib dbpp-postgresql : : : : <include>/usr/include/dbpp-postgresql ;
+lib dryice : : : : <include>/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 ]
:
- <library>dbpp-postgresql
- <library>../..//p2sql
- <library>../..//p2common
- <library>../..//adhocutil
- <library>../..//p2ut
<define>ROOT=\"$(me)\"
- <library>boost_system
- <library>boost_filesystem
- ;
-
-run
- testEmbedding.cpp
- dummySelect.sql
- : : :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//boost_utf
- <include>..
- : testEmbedding ;
-
-run
- testMaint.cpp mockDevices.cpp mockScheduler.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
<library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>../../devices//p2pvrMockTuner
- <library>IceUtil
+ <library>dryice
<library>Ice
+ <library>IceUtil
+ <library>IceBox
+ <library>dbppcore
+ <library>dbpp-postgresql
+ <library>../../devices//p2pvrMockTuner
<library>boost_system
<library>boost_filesystem
- <library>testCommon
- <library>../..//boost_utf
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testMaint ;
-
-run
- testRecording.cpp mockDevices.cpp mockScheduler.cpp
+ <implicit-dependency>../../ice
+ <library>../../ice
: :
- ../../datasources/schema.sql
- :
+ <define>ROOT=\"$(me)\"
<define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
<library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>../../devices//p2pvrMockTuner
- <library>IceUtil
+ <library>dryice
+ <library>../..//icetray
+ <library>dbppcore
+ <library>dbpp-postgresql
<library>Ice
+ <library>IceBox
+ <library>IceUtil
<library>boost_system
<library>boost_filesystem
- <library>testCommon
<library>../..//boost_utf
+ <library>../../devices//p2pvrMockTuner
+ <library>..//p2pvrdaemon
<dependency>test-data
- <define>ROOT=\"$(me)\"
- : testRecording ;
+ ;
run
- testErrorHandling.cpp mockDevices.cpp mockScheduler.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
- <library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>../../devices//p2pvrMockTuner
- <library>../../dvb//p2pvrdvb
- <library>IceUtil
- <library>Ice
- <library>boost_system
- <library>boost_filesystem
+ testMaint.cpp
+ : : :
<library>testCommon
- <library>../..//boost_utf
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testErrorHandling ;
+ : testMaint ;
-run
- testRecordings.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
- <library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>IceUtil
- <library>Ice
- <library>boost_system
- <library>boost_filesystem
+run testRecording.cpp
+ : : :
<library>testCommon
- <library>../..//boost_utf
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testRecordings ;
+ ;
-run
- testSi.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
- <library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>IceUtil
- <library>Ice
- <library>boost_system
- <library>boost_filesystem
+run testErrorHandling.cpp
+ : : :
<library>testCommon
- <library>../..//boost_utf
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testSi ;
+ <library>../../dvb//p2pvrdvb
+ ;
-run
- testSched.cpp mockDevices.cpp mockRecorder.cpp
- : :
- ../../datasources/schema.sql
- datasources/eventOffset.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
- <library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>IceUtil
- <library>Ice
- <library>boost_system
- <library>boost_filesystem
- <library>../../devices//p2pvrMockTuner
- <library>../..//boost_utf
+run testRecordings.cpp
+ : : :
<library>testCommon
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testSched ;
+ ;
-run
- testStorage.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2basics
- <library>../..//adhocutil
- <library>../..//p2xml
- <library>../..//p2ut
- <library>..//p2pvrdaemon
- <library>IceUtil
- <library>Ice
- <library>boost_system
- <library>boost_filesystem
+run testSi.cpp
+ : : :
<library>testCommon
- <library>../..//boost_utf
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testStorage ;
+ ;
-run
- testSqlSelectDeserializer.cpp
- : :
- ../../datasources/schema.sql
- :
- <define>BOOST_TEST_DYN_LINK
- <library>../..//p2common
- <library>../..//p2sql
- <library>../..//p2ut
- <library>../..//p2xml
- <library>..//p2pvrdaemon
- <library>IceUtil
- <library>Ice
- <library>../..//boost_utf
+run testSched.cpp
+ : : :
<library>testCommon
- <library>..//slicer-db
- <dependency>test-data
- <define>ROOT=\"$(me)\"
- : testSqlSelectDeserializer ;
+ <dependency>datasources/eventOffset.sql
+ ;
+
+run testStorage.cpp
+ : : :
+ <library>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 @@
-<?xml version="1.0"?>
-<project2:rdbmsdatasource xmlns:project2="http://project2.randomdan.homeip.net" name="postgres">
- <masterdsn provider="mock" dsn="postgres" />
-</project2:rdbmsdatasource>
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<P2PVR::LocalDevicesPrx>("Devices")),
+ devices(getProxy<P2PVR::DevicesPrx>("GlobalDevices")),
+ maint(getProxy<P2PVR::MaintenancePrx>("Maintenance")),
+ si(getProxy<P2PVR::SIPrx>("SI")),
+ schedules(getProxy<P2PVR::SchedulesPrx>("Schedules")),
+ storage(getProxy<P2PVR::StoragePrx>("Storage")),
+ recorder(getProxy<P2PVR::RecorderPrx>("Recorder")),
+ recordings(getProxy<P2PVR::RecordingsPrx>("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 <pq-mock.h>
#include <visibility.h>
+#include <dryice.h>
+#include <p2pvr.h>
-#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 <dvb.h>
+#include <visibility.h>
-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 <p2pvr.h>
+#include <visibility.h>
-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 <p2pvr.h>
+#include <visibility.h>
-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 <boost/test/unit_test.hpp>
-
-#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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -15,46 +15,16 @@
#include <siParsers/network.h>
#include <temporaryIceAdapterObject.h>
#include "mockDefs.h"
-#include <testAppInstance.h>
-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<P2PVR::RawDataClient> a(adapter, new TestClient());
+ auto del = si->GetDeliveryForSi();
+ auto gd = devices->GetTunerAny(del);
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> a(adapter, new TestNetworkParser());
+ auto del = si->GetDeliveryForSi();
+ auto gd = devices->GetTunerAny(del);
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> a(adapter, new FailingTestClient());
+ auto del = si->GetDeliveryForSi();
+ auto gd = devices->GetTunerAny(del);
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> a(adapter, new FailingTestNetworkParser());
+ auto del = si->GetDeliveryForSi();
+ auto gd = devices->GetTunerAny(del);
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> 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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string/predicate.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -17,54 +17,19 @@
#include <slicer/db/sqlSelectDeserializer.h>
#include "commonHelpers.h"
#include <slicer/slicer.h>
-#include <testAppInstance.h>
-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<RdbmsDataSource>("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<std::string>(), IceUtil::Optional<int>(),
+ maint->UpdateEvents();
+ auto dayOneEvents = si->EventSearch(IceUtil::Optional<std::string>(), IceUtil::Optional<int>(),
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::ModifyCommand>(
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<std::string>(), IceUtil::Optional<int>(),
+ auto dayOneEventsOnDayTwo = si->EventSearch(IceUtil::Optional<std::string>(), IceUtil::Optional<int>(),
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<int>(),
+ auto thingsWithNew = si->EventSearch("new", IceUtil::Optional<int>(),
IceUtil::Optional<Common::DateTime>(), IceUtil::Optional<Common::DateTime>());
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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -18,50 +18,14 @@
#include "serviceStreamer.h"
#include "temporaryIceAdapterObject.h"
#include <slicer/slicer.h>
-#include <testAppInstance.h>
-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<MockTarget> target = new MockTarget();
- TemporaryIceAdapterObject<P2PVR::RawDataClient> targetPrx(adapter, target);
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> 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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -14,50 +14,14 @@
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include "mockDefs.h"
-#include <testAppInstance.h>
-
-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<std::string>(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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -16,46 +16,23 @@
#include <boost/lexical_cast.hpp>
#include <commonHelpers.h>
#include "mockDefs.h"
-#include <testAppInstance.h>
-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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -13,40 +13,10 @@
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include "mockDefs.h"
-#include <testAppInstance.h>
-
-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 <boost/test/unit_test.hpp>
-#include <slicer/db/sqlSelectDeserializer.h>
-#include <slicer/slicer.h>
-#include <connection.h>
-#include <p2pvr.h>
-#include <rdbmsDataSource.h>
-#include <commonObjects.h>
-#include <testOptionsSource.h>
-#include <boost/filesystem/operations.hpp>
-#include <definedDirs.h>
-#include <commonHelpers.h>
-#include "mockDefs.h"
-#include <testAppInstance.h>
-
-typedef boost::shared_ptr<DB::SelectCommand> 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<RdbmsDataSource>("postgres")->getReadonly();
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 100"));
- auto res = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(*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<RdbmsDataSource>("postgres")->getReadonly();
- auto sel = SelectPtr(db->newSelectCommand("SELECT EventId FROM events ORDER BY serviceId, eventId LIMIT 1"));
- auto res = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, int>(*sel);
- BOOST_REQUIRE_EQUAL(res, 49741);
-}
-
-BOOST_AUTO_TEST_CASE( singleEvent )
-{
- auto db = dataSource<RdbmsDataSource>("postgres")->getReadonly();
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 1"));
- auto res = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::EventPtr>(*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<RdbmsDataSource>("postgres")->getReadonly();
- auto sel = SelectPtr(db->newSelectCommand("SELECT d.*, '::DVBSI::TerrestrialDelivery' \"typeid\" FROM delivery_dvbt d ORDER BY TransportStreamId"));
- auto res = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Deliveries>(*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 <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
-#include <testOptionsSource.h>
+#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
@@ -10,73 +10,60 @@
#include <storage.h>
#include <boost/lexical_cast.hpp>
#include <commonHelpers.h>
-#include <testAppInstance.h>
+#include <definedDirs.h>
+#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 :
- <library>..//p2common
- <library>..//p2daemonlib
- <implicit-dependency>../ice//p2pvrice
-;
-
-lib p2pvrdaemonbase :
- pch
- [ glob-tree *.cpp ]
- :
- <library>..//p2common
- <library>../lib//p2pvrlib
- <library>../ice//p2pvrice
- <library>..//adhocutil
- <implicit-dependency>../ice//p2pvrice
- : :
- <implicit-dependency>../ice//p2pvrice
- <library>..//p2daemonlib
- <include>.
- ;
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 <pch.hpp>
-#include "daemonBase.h"
-#include "p2LoggerWrapper.h"
-#include <logger.h>
-#include <Ice/ObjectAdapter.h>
-
-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 <Ice/Communicator.h>
-#include <Ice/Initialize.h>
-#include <daemon.h>
-#include <options.h>
-#include <visibility.h>
-
-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/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 <pch.hpp>
-#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 <Ice/Logger.h>
-#include <visibility.h>
-
-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 <Ice/Ice.h>
-
-#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 @@
-<?xml version="1.0"?>
-<project2:rdbmsdatasource xmlns:project2="http://project2.randomdan.homeip.net" name="postgres">
- <masterdsn provider="postgresql" dsn="user=gentoo dbname=p2pvr" />
-</project2:rdbmsdatasource>
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 :
- <library>boost_system
- <library>boost_filesystem
- <library>..//p2common
- <implicit-dependency>../ice//p2pvrice
-;
-
lib p2pvrdevices :
- pch
[ glob-tree *.cpp : mockTuner.cpp ]
:
<library>boost_system
<library>boost_filesystem
+ <library>boost_program_options
<library>../dvb//p2pvrdvb
<library>../ice//p2pvrice
<library>../lib//p2pvrlib
- <library>..//p2common
<library>..//adhocutil
+ <library>..//icetray
<implicit-dependency>../ice//p2pvrice
: :
<library>boost_filesystem
@@ -32,12 +26,12 @@ lib p2pvrdevices :
<include>.
;
-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 :
<library>../dvb//p2pvrdvb
<library>../ice//p2pvrice
<library>../lib//p2pvrlib
- <library>..//p2common
<library>..//adhocutil
+ <library>..//icetray
<implicit-dependency>../ice//p2pvrice
: :
<library>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 <pch.hpp>
#include "frontend.h"
#include "tuner.h"
-#include <logger.h>
#include <sys/ioctl.h>
#include <linux/dvb/frontend.h>
#include <factory.impl.h>
-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 <linux/dvb/frontend.h>
#include <factory.h>
#include <dvb.h>
+#include <logger.h>
class Tuner;
class Frontend {
public:
typedef boost::function<bool(long)> 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<Frontend, Tuner *, int, const struct dvb_frontend_info &> 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 <pch.hpp>
#include "../frontend.h"
#include "../tuner.h"
#include <sys/ioctl.h>
-#include <logger.h>
#include <linux/dvb/frontend.h>
#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<Frontend_OFDM>())
+ {
+ }
+
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 <pch.hpp>
#include "localDevices.h"
#include <Ice/Ice.h>
#include "tuner.h"
#include "bindTimerTask.h"
-#include <logger.h>
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<std::string>(), 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::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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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 <mutex>
#include <visibility.h>
#include <IceUtil/Timer.h>
+#include <logger.h>
class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices {
public:
+ class Options : public IceTray::Options {
+ public:
+ Options();
+
+ ICETRAY_OPTIONS_DECLARE;
+
+ std::vector<std::string> 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<std::string, OpenTunerPtr> Devices;
static Devices devices;
static std::mutex lock;
+ static IceTray::Logging::LoggerPtr logger;
+ IceTray::OptionsResolver<Options> 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<MockTuner>();
+
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<Ice::ByteSeq> 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<Ice::ByteSeq> 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 <visibility.h>
#include <Ice/BuiltinSequences.h>
#include <boost/thread.hpp>
+#include <logger.h>
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<int, boost::thread *> 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 <Ice/Ice.h>
-#include <boost/bind.hpp>
-#include <boost/function/function_fwd.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <list>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-#include <thread>
-
-#endif
-#endif
-
diff --git a/p2pvr/devices/sampleSiData/events1.datxz b/p2pvr/devices/sampleSiData/events1.datxz
index a84d777..43358a9 100644
--- a/p2pvr/devices/sampleSiData/events1.datxz
+++ b/p2pvr/devices/sampleSiData/events1.datxz
Binary files 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 <pch.hpp>
#include "tuner.h"
#include <fcntl.h>
#include <Ice/Ice.h>
#include <sys/ioctl.h>
#include <poll.h>
-#include <logger.h>
#include <factory.h>
#include <linux/dvb/frontend.h>
#include <linux/dvb/dmx.h>
@@ -14,6 +12,8 @@
#include "tunerSendSi.h"
#include "tunerSendTs.h"
+IceTray::Logging::LoggerPtr Tuner::logger = LOGMANAGER()->getLogger<Tuner>();
+
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<std::mutex> 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<std::mutex> 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<std::mutex> 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 <boost/function.hpp>
#include <boost/tuple/tuple.hpp>
#include <options.h>
+#include <logger.h>
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> 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 <pch.hpp>
#include "tunerSendSi.h"
#include <logger.h>
#include <boost/crc.hpp>
#include "siParsers/table.h"
+IceTray::Logging::LoggerPtr SendSi::logger(LOGMANAGER()->getLogger<SendSi>());
+
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 <logger.h>
class SendSi : public Tuner::IDataSender {
public:
@@ -17,6 +18,7 @@ class SendSi : public Tuner::IDataSender {
std::set<Ice::AsyncResultPtr> 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 <pch.hpp>
#include "tunerSendTs.h"
#include <logger.h>
@@ -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::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 <logger.h>
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 :
- <implicit-dependency>../ice//p2pvrice
-;
-
lib p2pvrdvb :
- pch
[ glob-tree *.cpp : unittests ]
:
<library>../ice//p2pvrice
<library>..//adhocutil
+ <library>../..//glibmm
<implicit-dependency>../ice//p2pvrice
: :
<implicit-dependency>../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 <boost/function.hpp>
+#include <visibility.h>
#include <dvb.h>
-class BindDataHandler : public P2PVR::RawDataClient {
+class DLL_PUBLIC BindDataHandler : public P2PVR::RawDataClient {
public:
typedef boost::function<bool(const P2PVR::Data &)> 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 <Ice/Ice.h>
-#include <glibmm.h>
-#include <boost/bind.hpp>
-#include <boost/function/function_fwd.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <list>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#include <dvbsi.h>
-
-#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 <pch.hpp>
#include <time.h>
#include <glibmm/regex.h>
#include <boost/regex.hpp>
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 <pch.hpp>
#include "network.h"
#include <boost/bind.hpp>
#include <linux/dvb/frontend.h>
#include <safeMapFind.h>
-#include <exceptions.h>
+#include <compileTimeFormatter.h>
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<typename ... Pn>
+ 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<short, fe_bandwidth_t> 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 <pch.hpp>
#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 <pch.hpp>
#include "programMap.h"
#include <boost/bind.hpp>
-#include <logger.h>
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 <pch.hpp>
#include "service.h"
#include <boost/bind.hpp>
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 <pch.hpp>
#include "table.h"
#include <string.h>
#include <stdio.h>
#include <glibmm.h>
-#include <exceptions.h>
-#include <logger.h>
-
-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 <boost/tuple/tuple_comparison.hpp>
#include <arpa/inet.h>
#include <dvb.h>
-#include <logger.h>
#include <mutex>
+#include <set>
#include <visibility.h>
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
:
<define>BOOST_TEST_DYN_LINK
+ <library>adhocutil
<library>..//p2pvrdvb
<library>../../ice//p2pvrice
<library>IceUtil
@@ -33,7 +35,6 @@ exe createBroadcast :
<library>boost_system
<library>boost_filesystem
<library>../..//boost_utf
- <library>../..//p2ut
<define>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 <testOptionsSource.h>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/function.hpp>
@@ -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<v
auto ic = boost::get<0>(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/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/p2config b/p2pvr/etc/p2pvrd/icebox.config
index 07c2e76..07ae1bc 100644
--- a/p2pvr/etc/p2config
+++ b/p2pvr/etc/p2pvrd/icebox.config
@@ -1,8 +1,11 @@
-common.datasourceRoot = /etc/p2pvr/datasources
+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
-common.syslog.level = 4
-common.syslog.ident = p2pvr
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 :
<library>Ice
<library>IceUtil
<library>pthread
- <library>..//p2common
<library>..//adhocutil
- <library>..//p2ice
<library>slicer
<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 <variableType.h>
#include <common.h>
-#include <iceConvert.h>
#include "commonHelpers.h"
-template<>
-VariableType
-DLL_PUBLIC IceConvert<Common::DateTime>::ToVariable(const Common::DateTime & dt)
-{
- return *dt;
-}
-
-template<>
-VariableType
-DLL_PUBLIC IceConvert<Common::Duration>::ToVariable(const Common::Duration & d)
-{
- return *d;
-}
-
-template<>
-Common::DateTime
-DLL_PUBLIC IceConvert<Common::DateTime>::FromVariable(const VariableType & dt)
-{
- return *dt.as<boost::posix_time::ptime>();
-}
-
-template<>
-Common::Duration
-DLL_PUBLIC IceConvert<Common::Duration>::FromVariable(const VariableType & d)
-{
- return *d.as<boost::posix_time::time_duration>();
-}
-
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<NetworkTransportStream> NetworkTransportStreams;
class Network {
- [ "slicer:merge:key" ]
+ [ "slicer:db:pkey" ]
int NetworkId;
optional(1) string Name;
- [ "slicer:merge:omit" ]
+ [ "slicer:db:ignore" ]
NetworkTransportStreams TransportStreams;
};
sequence<Network> Networks;
class BouquetTransportStream {
- [ "slicer:merge:key" ]
+ [ "slicer:db:pkey" ]
int TransportStreamId;
- [ "slicer:merge:key" ]
+ [ "slicer:db:pkey" ]
int OriginalNetworkId;
};
sequence <BouquetTransportStream> 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<Service> 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<Event> 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<Recording> 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 : : <name>slicer : : <include>/usr/include/slicer ;
lib boost_system ;
lib boost_filesystem ;
-cpp-pch pch : pch.hpp :
- <library>boost_system
- <library>boost_filesystem
- <library>..//p2common
- <library>..//adhocutil
- <implicit-dependency>../ice//p2pvrice
-;
-
lib p2pvrlib :
- pch
[ glob-tree *.cpp ]
:
<library>boost_system
<library>boost_filesystem
<library>../ice//p2pvrice
<library>../dvb//p2pvrdvb
- <library>..//p2common
+ <library>..//icetray
<library>..//adhocutil
<implicit-dependency>../ice//p2pvrice
<library>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 <pch.hpp>
#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 <pch.hpp>
#include "fileHandle.h"
#include <unistd.h>
#include <stdexcept>
diff --git a/p2pvr/daemonbase/fileSink.cpp b/p2pvr/lib/fileSink.cpp
index dade921..d3fda8f 100644
--- a/p2pvr/daemonbase/fileSink.cpp
+++ b/p2pvr/lib/fileSink.cpp
@@ -1,4 +1,3 @@
-#include <pch.hpp>
#include "fileSink.h"
FileSink::FileSink(const boost::filesystem::path & path) :
diff --git a/p2pvr/daemonbase/fileSink.h b/p2pvr/lib/fileSink.h
index fbd469c..fbd469c 100644
--- a/p2pvr/daemonbase/fileSink.h
+++ b/p2pvr/lib/fileSink.h
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 <pch.hpp>
#include "muxer.h"
-#include <logger.h>
#include <processPipes.h>
#include <poll.h>
#include <sys/wait.h>
@@ -8,6 +6,8 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
+IceTray::Logging::LoggerPtr Muxer::log(LOGMANAGER()->getLogger<Muxer>());
+
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 <boost/shared_ptr.hpp>
#include <processPipes.h>
#include <visibility.h>
+#include <logger.h>
class DLL_PUBLIC Muxer : public P2PVR::RawDataClient {
public:
@@ -22,6 +23,8 @@ class DLL_PUBLIC Muxer : public P2PVR::RawDataClient {
typedef boost::shared_ptr<AdHoc::System::ProcessPipes> 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 <pch.hpp>
-#include "p2Helpers.h"
-#include <commonHelpers.h>
-
-template <>
-VariableType &
-operator<<<Common::Duration>(VariableType & vt, const Common::Duration & d)
-{
- return (vt = *d);
-}
-
-template <>
-VariableType &
-operator<<<Common::DateTime>(VariableType & vt, const Common::DateTime & dt)
-{
- return (vt = *dt);
-}
-
-template <>
-const VariableType &
-operator>><Common::Duration>(const VariableType & vt, Common::Duration & d)
-{
- const boost::posix_time::time_duration & dur = vt;
- d = *dur;
- return vt;
-}
-
-template <>
-const VariableType &
-operator>><Common::DateTime>(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 <variableType.h>
-#include <common.h>
-#include <visibility.h>
-
-template <typename T>
-DLL_PUBLIC
-const VariableType &
-operator>>(const VariableType & vt, T & v)
-{
- v = vt.as<T>();
- return vt;
-}
-
-template <>
-DLL_PUBLIC
-const VariableType &
-operator>><Common::Duration>(const VariableType & vt, Common::Duration & d);
-
-template <>
-DLL_PUBLIC
-const VariableType &
-operator>><Common::DateTime>(const VariableType & vt, Common::DateTime & dt);
-
-template <typename T>
-DLL_PUBLIC
-const VariableType &
-operator>>(const VariableType & vt, IceUtil::Optional<T> & v)
-{
- if (vt.isNull()) {
- v = IceUtil::Optional<T>();
- }
- else {
- v = T();
- vt >> *v;
- }
- return vt;
-}
-
-template <>
-DLL_PUBLIC
-const VariableType &
-operator>>(const VariableType & vt, short int & v);
-
-template <typename T>
-DLL_PUBLIC
-VariableType &
-operator<<(VariableType & vt, const T & v)
-{
- vt = v;
- return vt;
-}
-
-template <>
-DLL_PUBLIC
-VariableType &
-operator<<<Common::Duration>(VariableType & vt, const Common::Duration & d);
-
-template <>
-DLL_PUBLIC
-VariableType &
-operator<<<Common::DateTime>(VariableType & vt, const Common::DateTime & dt);
-
-template <typename T>
-DLL_PUBLIC
-VariableType &
-operator<<(VariableType & vt, const IceUtil::Optional<T> & 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 <Ice/Ice.h>
-#include <glibmm.h>
-#include <boost/bind.hpp>
-#include <boost/function/function_fwd.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <list>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#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 <pch.hpp>
#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 <pch.hpp>
#include "serviceStreamerCore.h"
#include <boost/bind.hpp>
#include "bindSiParserHandler.h"
+IceTray::Logging::LoggerPtr ServiceStreamerCore::log(LOGMANAGER()->getLogger<ServiceStreamerCore>());
+
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 <p2pvr.h>
#include <set>
#include <visibility.h>
+#include <logger.h>
class DLL_PUBLIC ServiceStreamerCore {
public:
@@ -40,6 +41,8 @@ class DLL_PUBLIC ServiceStreamerCore {
typedef std::set<int> Streams;
Streams streams;
int serviceHandle;
+
+ static IceTray::Logging::LoggerPtr log;
};
#endif