summaryrefslogtreecommitdiff
path: root/p2pvr/daemon
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-10-26 19:52:15 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-10-26 19:52:15 +0000
commitb5326ead7bdb119632c3dd2420a94a5da9d56b1d (patch)
treef3e939b8c28ed3e4cb4155efe81abe6607a564f0 /p2pvr/daemon
parentTidy up and alias glibmm and libxml++ refs (diff)
parentEnable hidden visibility and LTO (diff)
downloadp2pvr-b5326ead7bdb119632c3dd2420a94a5da9d56b1d.tar.bz2
p2pvr-b5326ead7bdb119632c3dd2420a94a5da9d56b1d.tar.xz
p2pvr-b5326ead7bdb119632c3dd2420a94a5da9d56b1d.zip
Merge branch 'p2pvr-slicer'p2pvr-0.1.3
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r--p2pvr/daemon/Jamfile.jam4
-rw-r--r--p2pvr/daemon/dbClient.h8
-rw-r--r--p2pvr/daemon/globalDevices.h3
-rw-r--r--p2pvr/daemon/maintenance.h6
-rw-r--r--p2pvr/daemon/recorder.h7
-rw-r--r--p2pvr/daemon/recordings.cpp13
-rw-r--r--p2pvr/daemon/recordings.h5
-rw-r--r--p2pvr/daemon/schedules.cpp36
-rw-r--r--p2pvr/daemon/schedules.h7
-rw-r--r--p2pvr/daemon/si.cpp37
-rw-r--r--p2pvr/daemon/si.h3
-rw-r--r--p2pvr/daemon/sql/Recordings_insert.sql2
-rw-r--r--p2pvr/daemon/sql/Recordings_insertNewId.sql2
-rw-r--r--p2pvr/daemon/sql/Schedules_insert.sql2
-rw-r--r--p2pvr/daemon/sql/Schedules_insertNewId.sql1
-rw-r--r--p2pvr/daemon/sql/Schedules_update.sql10
-rw-r--r--p2pvr/daemon/sqlSelectDeserializer.cpp176
-rw-r--r--p2pvr/daemon/sqlSelectDeserializer.h28
-rw-r--r--p2pvr/daemon/storage.h3
-rw-r--r--p2pvr/daemon/unittests/Jamfile.jam1
-rw-r--r--p2pvr/daemon/unittests/mockScheduler.cpp7
-rw-r--r--p2pvr/daemon/unittests/mockScheduler.h3
-rw-r--r--p2pvr/daemon/unittests/testMaint.cpp2
-rw-r--r--p2pvr/daemon/unittests/testRecording.cpp2
-rw-r--r--p2pvr/daemon/unittests/testRecordings.cpp5
-rw-r--r--p2pvr/daemon/unittests/testSched.cpp12
-rw-r--r--p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp10
-rw-r--r--p2pvr/daemon/unittests/testp2ice.cpp5
28 files changed, 102 insertions, 298 deletions
diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam
index c565234..05b0e9b 100644
--- a/p2pvr/daemon/Jamfile.jam
+++ b/p2pvr/daemon/Jamfile.jam
@@ -1,4 +1,5 @@
lib slicer : : <name>slicer : : <include>/usr/include/slicer ;
+lib slicer-db : : <name>slicer-db : : <include>/usr/include/slicer ;
cpp-pch pch : pch.hpp :
<library>../ice//p2pvrice
@@ -22,8 +23,11 @@ lib p2pvrdaemon :
<library>../devices//p2pvrdevices
<library>../daemonbase//p2pvrdaemonbase
<library>..//adhocutil
+ <cflags>-fvisibility=hidden
+ <variant>release:<cflags>-flto
<implicit-dependency>../../libtmdb//tmdb
<library>slicer
+ <library>slicer-db
<slicer>yes
<include>.
: :
diff --git a/p2pvr/daemon/dbClient.h b/p2pvr/daemon/dbClient.h
index cd846e5..1fc12e8 100644
--- a/p2pvr/daemon/dbClient.h
+++ b/p2pvr/daemon/dbClient.h
@@ -11,6 +11,7 @@
#include <sqlVariableBinder.h>
#include <sqlHandleAsVariableType.h>
#include "p2Helpers.h"
+#include <slicer/slicer.h>
class SqlMergeTask;
@@ -40,6 +41,13 @@ class DatabaseClient : public virtual CommonObjects {
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
{
diff --git a/p2pvr/daemon/globalDevices.h b/p2pvr/daemon/globalDevices.h
index 33f6231..86d80c5 100644
--- a/p2pvr/daemon/globalDevices.h
+++ b/p2pvr/daemon/globalDevices.h
@@ -6,8 +6,9 @@
#include <dvb.h>
#include <options.h>
+#include <visibility.h>
-class GlobalDevices : public P2PVR::Devices {
+class DLL_PUBLIC GlobalDevices : public P2PVR::Devices {
public:
P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &);
P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr &, const Ice::Current &);
diff --git a/p2pvr/daemon/maintenance.h b/p2pvr/daemon/maintenance.h
index 7ec0541..7c3e9b3 100644
--- a/p2pvr/daemon/maintenance.h
+++ b/p2pvr/daemon/maintenance.h
@@ -2,9 +2,11 @@
#define P2PVR_MAINTENANCE_H
#include <p2pvr.h>
+#include <IceUtil/Timer.h>
#include "dbClient.h"
+#include <visibility.h>
-class Maintenance : public P2PVR::Maintenance, public DatabaseClient {
+class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public DatabaseClient {
public:
Maintenance(Ice::ObjectAdapterPtr, IceUtil::TimerPtr);
@@ -17,7 +19,7 @@ class Maintenance : public P2PVR::Maintenance, public DatabaseClient {
INITOPTIONS;
private:
- void ScheduledUpdate();
+ DLL_PRIVATE void ScheduledUpdate();
Ice::ObjectAdapterPtr adapter;
IceUtil::TimerPtr timer;
diff --git a/p2pvr/daemon/recorder.h b/p2pvr/daemon/recorder.h
index bef331b..6a6940e 100644
--- a/p2pvr/daemon/recorder.h
+++ b/p2pvr/daemon/recorder.h
@@ -7,8 +7,9 @@
#include <p2pvr.h>
#include <mutex>
#include "serviceStreamer.h"
+#include <visibility.h>
-class Recorder : public P2PVR::Recorder {
+class DLL_PUBLIC Recorder : public P2PVR::Recorder {
public:
typedef std::vector<IceUtil::TimerTaskPtr> Pendings;
@@ -32,8 +33,8 @@ class Recorder : public P2PVR::Recorder {
INITOPTIONS;
private:
- void StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, P2PVR::EventPtr event);
- void StopRecording(CurrentPtr);
+ DLL_PRIVATE void StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, P2PVR::EventPtr event);
+ DLL_PRIVATE void StopRecording(CurrentPtr);
Ice::ObjectAdapterPtr adapter;
IceUtil::TimerPtr timer;
diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp
index 9b79d60..ac8f27a 100644
--- a/p2pvr/daemon/recordings.cpp
+++ b/p2pvr/daemon/recordings.cpp
@@ -4,22 +4,19 @@
#include <Ice/Ice.h>
#include <logger.h>
#include <slicer/slicer.h>
-#include "sqlSelectDeserializer.h"
+#include <slicer/db/sqlSelectDeserializer.h>
+#include <slicer/db/sqlInsertSerializer.h>
-ResourceString(Recording_Insert, sql_Recordings_insert);
-ResourceString(Recording_InsertNewId, sql_Recordings_insertNewId);
ResourceString(Recording_Delete, sql_Recordings_delete);
ResourceString(Recording_GetStorage, sql_Recordings_getStorage);
ResourceString(Recording_GetAll, sql_Recordings_getAll);
-int
+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);
- auto insert = Modify(Recording_Insert, r->StorageAddress, r->Guid, r->ScheduleId, r->EventUid);
- insert.second->execute();
- r->RecordingId = SelectScalar<int>(Recording_InsertNewId);
+ Store<Slicer::SqlFetchIdInsertSerializer>(r, "recordings");
Logger()->messagebf(LOG_INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId);
return r->RecordingId;
}
@@ -47,7 +44,7 @@ P2PVR::RecordingList
Recordings::GetRecordings(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::RecordingList>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::RecordingList>(
*Select(Recording_GetAll).second);
}
diff --git a/p2pvr/daemon/recordings.h b/p2pvr/daemon/recordings.h
index 0f18a36..482ce23 100644
--- a/p2pvr/daemon/recordings.h
+++ b/p2pvr/daemon/recordings.h
@@ -4,10 +4,11 @@
#include <p2pvr.h>
#include <string>
#include "dbClient.h"
+#include <visibility.h>
-class Recordings : public DatabaseClient, public P2PVR::Recordings {
+class DLL_PUBLIC Recordings : public DatabaseClient, public P2PVR::Recordings {
public:
- int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &);
+ Ice::Int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &);
void DeleteRecording(int recordingId, const Ice::Current &);
P2PVR::RecordingList GetRecordings(const Ice::Current &);
};
diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp
index 40d7863..90a42a9 100644
--- a/p2pvr/daemon/schedules.cpp
+++ b/p2pvr/daemon/schedules.cpp
@@ -11,15 +11,13 @@
#include "resources.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <factory.impl.h>
-#include "sqlSelectDeserializer.h"
-#include <slicer/slicer.h>
+#include <slicer/db/sqlSelectDeserializer.h>
+#include <slicer/db/sqlInsertSerializer.h>
+#include <slicer/db/sqlUpdateSerializer.h>
#include <p2pvr-int.h>
#include <privateExecContext.h>
ResourceString(Schedules_getCandidates, sql_Schedules_getCandidates);
-ResourceString(Schedules_insert, sql_Schedules_insert);
-ResourceString(Schedules_insertNewId, sql_Schedules_insertNewId);
-ResourceString(Schedules_update, sql_Schedules_update);
ResourceString(Schedules_delete, sql_Schedules_delete);
ResourceString(Schedules_selectAll, sql_Schedules_selectAll);
ResourceString(Schedules_selectById, sql_Schedules_selectById);
@@ -193,7 +191,7 @@ Schedules::DoReschedule(const Ice::Current & ice)
unsigned int tunerCount = devs->TunerCount();
// Load list from database
- auto episodes = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::ScheduleCandidates>(
+ auto episodes = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::ScheduleCandidates>(
*Select(Schedules_getCandidates).second);
Episodes scheduleList;
@@ -309,7 +307,7 @@ P2PVR::ScheduleList
Schedules::GetSchedules(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::ScheduleList>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::ScheduleList>(
*Select(Schedules_selectAll).second);
}
@@ -317,7 +315,7 @@ P2PVR::SchedulePtr
Schedules::GetSchedule(int id, const Ice::Current &)
{
Logger()->messagebf(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- auto schedules = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::ScheduleList>(
+ auto schedules = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::ScheduleList>(
*Select(Schedules_selectById, id).second);
if (schedules.empty()) throw P2PVR::NotFound();
return schedules.front();
@@ -327,24 +325,26 @@ P2PVR::ScheduledToRecordList
Schedules::GetScheduledToRecord(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::ScheduledToRecordList>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::ScheduledToRecordList>(
*Select(Schedules_scheduledToRecord).second);
}
-int
-Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
+Ice::Int
+Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
{
TxHelper tx(this);
- if (s->ScheduleId == 0) {
- Modify(Schedules_insert, s->ServiceId, s->EventUid, s->Title, s->Search, s->Priority, s->Early, s->Late, s->Repeats).second->execute();
- s->ScheduleId = SelectScalar<int>(Schedules_insertNewId);
- }
- else {
- Modify(Schedules_update, s->ServiceId, s->EventUid, s->Title, s->Search, s->Priority, s->Early, s->Late, s->Repeats, s->ScheduleId).second->execute();
- }
+ Store<Slicer::SqlFetchIdInsertSerializer>(s, "schedules");
DoReschedule(ice);
return s->ScheduleId;
}
+void
+Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice)
+{
+ TxHelper tx(this);
+ Store<Slicer::SqlUpdateSerializer>(s, "schedules");
+ DoReschedule(ice);
+}
+
INSTANTIATEFACTORY(EpisodeGroup, const Episodes &);
diff --git a/p2pvr/daemon/schedules.h b/p2pvr/daemon/schedules.h
index 07f2c23..122e214 100644
--- a/p2pvr/daemon/schedules.h
+++ b/p2pvr/daemon/schedules.h
@@ -5,6 +5,7 @@
#include <options.h>
#include "dbClient.h"
#include <factory.h>
+#include <visibility.h>
typedef boost::posix_time::ptime datetime;
class Episode;
@@ -61,18 +62,20 @@ class EpisodeGroup {
Showings selected;
};
-class Schedules : public P2PVR::Schedules, public DatabaseClient {
+class DLL_PUBLIC Schedules : public P2PVR::Schedules, public DatabaseClient {
public:
void DeleteSchedule(int id, const Ice::Current &);
P2PVR::SchedulePtr GetSchedule(int id, const Ice::Current &);
P2PVR::ScheduleList GetSchedules(const Ice::Current &);
P2PVR::ScheduledToRecordList GetScheduledToRecord(const Ice::Current &);
- int UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
+ Ice::Int NewSchedule(const P2PVR::SchedulePtr &, const Ice::Current &);
+ 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;
};
diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp
index 9164a62..d511c47 100644
--- a/p2pvr/daemon/si.cpp
+++ b/p2pvr/daemon/si.cpp
@@ -1,7 +1,8 @@
#include <pch.hpp>
#include "si.h"
#include "resources.h"
-#include "sqlSelectDeserializer.h"
+#include <slicer/db/sqlSelectDeserializer.h>
+#include <slicer/db/exceptions.h>
#include "commonHelpers.h"
#include <slicer/slicer.h>
#include <logger.h>
@@ -25,7 +26,7 @@ DVBSI::Networks
SI::GetNetworks(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::Networks>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::Networks>(
*Select(SI_allNetworks).second);
}
@@ -33,7 +34,7 @@ P2PVR::Deliveries
SI::GetAllDeliveries(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- auto rtn = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Deliveries>(
+ 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());
return rtn;
@@ -44,10 +45,10 @@ SI::GetDeliveryForTransport(int id, const Ice::Current&)
{
try {
Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
*Select(SI_deliveryForTransport, id).second, "delivery_type");
}
- catch (const NoRowsReturned &) {
+ catch (const Slicer::NoRowsReturned &) {
throw P2PVR::NotFound();
}
}
@@ -57,10 +58,10 @@ SI::GetDeliveryForSi(const Ice::Current&)
{
try {
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
*Select(SI_serviceNextUsed).second, "delivery_type");
}
- catch (const NoRowsReturned &) {
+ catch (const Slicer::NoRowsReturned &) {
return NULL;
}
}
@@ -70,10 +71,10 @@ SI::GetDeliveryForService(int id, const Ice::Current&)
{
try {
Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::DeliveryPtr>(
*Select(SI_deliveryForService, id).second, "delivery_type");
}
- catch (const NoRowsReturned &) {
+ catch (const Slicer::NoRowsReturned &) {
throw P2PVR::NotFound();
}
}
@@ -82,7 +83,7 @@ DVBSI::ServiceList
SI::GetServices(const Ice::Current&)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::ServiceList>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::ServiceList>(
*Select(SI_servicesSelectAll).second);
}
@@ -90,7 +91,7 @@ DVBSI::ServicePtr
SI::GetService(int id, const Ice::Current&)
{
Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- auto rtn = Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::ServiceList>(
+ auto rtn = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, DVBSI::ServiceList>(
*Select(SI_servicesSelectById, id).second);
if (rtn.empty()) throw P2PVR::NotFound();
return rtn.front();
@@ -102,7 +103,7 @@ SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &)
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
P2PVR::Events rtn;
for (const auto & uid : eventUids) {
- auto list = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(
+ auto list = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventByUid, uid).second);
std::copy(list.begin(), list.end(), std::back_inserter(rtn));
}
@@ -114,7 +115,7 @@ 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<SqlSelectDeserializer, P2PVR::Events>(
+ auto rtn = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventById, serviceId, eventId).second);
if (rtn.empty()) throw P2PVR::NotFound();
return rtn.front();
@@ -124,7 +125,7 @@ P2PVR::Events
SI::EventsOnNow(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventsOnNow).second);
}
@@ -132,7 +133,7 @@ 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<SqlSelectDeserializer, P2PVR::Events>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventsInRange, from, to).second);
}
@@ -141,7 +142,7 @@ SI::EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::
{
Logger()->messagebf(LOG_DEBUG, "%s(keywords=%s,serviceId=%s,from=%s,to=%s)",
keywords, serviceId, from, to, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords).second);
}
@@ -149,7 +150,7 @@ P2PVR::Events
SI::EventsInSchedules(const Ice::Current &)
{
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventsInSchedules).second);
}
@@ -157,7 +158,7 @@ P2PVR::Events
SI::EventsInSchedule(int scheduleId, const Ice::Current &)
{
Logger()->messagebf(LOG_DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(
+ return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, P2PVR::Events>(
*Select(SI_eventsInSchedule, scheduleId).second);
}
diff --git a/p2pvr/daemon/si.h b/p2pvr/daemon/si.h
index c57a018..0e388a1 100644
--- a/p2pvr/daemon/si.h
+++ b/p2pvr/daemon/si.h
@@ -3,8 +3,9 @@
#include <p2pvr.h>
#include "dbClient.h"
+#include <visibility.h>
-class SI : public P2PVR::SI, public DatabaseClient {
+class DLL_PUBLIC SI : public P2PVR::SI, public DatabaseClient {
public:
DVBSI::Networks GetNetworks(const Ice::Current &);
P2PVR::Deliveries GetAllDeliveries(const Ice::Current &);
diff --git a/p2pvr/daemon/sql/Recordings_insert.sql b/p2pvr/daemon/sql/Recordings_insert.sql
deleted file mode 100644
index ba0b9e2..0000000
--- a/p2pvr/daemon/sql/Recordings_insert.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO recordings(storageAddress, guid, scheduleId, eventUid)
-VALUES(?, ?, ?, ?)
diff --git a/p2pvr/daemon/sql/Recordings_insertNewId.sql b/p2pvr/daemon/sql/Recordings_insertNewId.sql
deleted file mode 100644
index 0583b49..0000000
--- a/p2pvr/daemon/sql/Recordings_insertNewId.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-SELECT currval('recordings_recordingid_seq');
-
diff --git a/p2pvr/daemon/sql/Schedules_insert.sql b/p2pvr/daemon/sql/Schedules_insert.sql
deleted file mode 100644
index 70c95bd..0000000
--- a/p2pvr/daemon/sql/Schedules_insert.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-INSERT INTO schedules(serviceId, eventUid, title, search, priority, early, late, repeats)
-VALUES(?, ?, ?, ?, ?, ?, ?, ?)
diff --git a/p2pvr/daemon/sql/Schedules_insertNewId.sql b/p2pvr/daemon/sql/Schedules_insertNewId.sql
deleted file mode 100644
index f66acd5..0000000
--- a/p2pvr/daemon/sql/Schedules_insertNewId.sql
+++ /dev/null
@@ -1 +0,0 @@
-SELECT currval('schedules_scheduleid_seq');
diff --git a/p2pvr/daemon/sql/Schedules_update.sql b/p2pvr/daemon/sql/Schedules_update.sql
deleted file mode 100644
index cf3ce49..0000000
--- a/p2pvr/daemon/sql/Schedules_update.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-UPDATE schedules SET
- serviceId = ?,
- eventUid = ?,
- title = ?,
- search = ?,
- priority = ?,
- early = ?,
- late = ?,
- repeats = ?
-WHERE scheduleId = ?
diff --git a/p2pvr/daemon/sqlSelectDeserializer.cpp b/p2pvr/daemon/sqlSelectDeserializer.cpp
deleted file mode 100644
index 5a59e3a..0000000
--- a/p2pvr/daemon/sqlSelectDeserializer.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-#include "sqlSelectDeserializer.h"
-#include <sqlHandleAsVariableType.h>
-#include <logger.h>
-#include <boost/algorithm/string/predicate.hpp>
-#include <stdexcept>
-
-VariableType
-operator/(DB::SelectCommand & cmd, unsigned int col)
-{
- HandleAsVariableType vt;
- cmd[col].apply(vt);
- return vt.variable;
-}
-
-class SqlSource : public DB::HandleField, public Slicer::ValueSource,
- public Slicer::TValueSource<boost::posix_time::time_duration>,
- public Slicer::TValueSource<boost::posix_time::ptime> {
- public:
- bool isNull() const
- {
- return vt.isNull();
- }
-
- void interval(const boost::posix_time::time_duration & d) override
- {
- vt = d;
- }
- void null() override
- {
- vt = Null();
- }
- void string(const char * s, size_t l) override
- {
- vt = std::string(s, l);
- }
- void integer(int64_t i) override
- {
- vt = i;
- }
- void floatingpoint(double fp) override
- {
- vt = fp;
- }
- void timestamp(const boost::posix_time::ptime & t)
- {
- vt = t;
- }
- void boolean(bool b) override
- {
- vt = b;
- }
-#define SET(Type) \
- void set(Type & b) const override { \
- b = vt.as<Type>(); \
- }
-#define SETNCONV(Type, CType) \
- void set(Type & b) const override { \
- b = boost::numeric_cast<Type>(vt.as<CType>()); \
- }
- SET(bool);
- SET(std::string);
- SETNCONV(Ice::Byte, int64_t);
- SETNCONV(Ice::Short, int64_t);
- SET(Ice::Int);
- SET(Ice::Long);
- SETNCONV(Ice::Float, double);
- SET(Ice::Double);
- SET(boost::posix_time::ptime);
- SET(boost::posix_time::time_duration);
-
- private:
- VariableType vt;
-};
-typedef IceUtil::Handle<SqlSource> SqlSourcePtr;
-
-SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand & c, IceUtil::Optional<std::string> tc) :
- cmd(c),
- typeIdColName(tc)
-{
-}
-
-void
-SqlSelectDeserializer::Deserialize(Slicer::ModelPartPtr mp)
-{
- cmd.execute();
- columnCount = cmd.columnCount();
- if (typeIdColName) {
- typeIdColIdx = cmd.getOrdinal(*typeIdColName);
- }
- switch (mp->GetType()) {
- case Slicer::mpt_Sequence:
- DeserializeSequence(mp);
- return;
- case Slicer::mpt_Complex:
- DeserializeObject(mp);
- return;
- case Slicer::mpt_Simple:
- DeserializeSimple(mp);
- return;
- default:
- throw std::invalid_argument("Unspported model type");
- }
-}
-
-void
-SqlSelectDeserializer::DeserializeSimple(Slicer::ModelPartPtr mp)
-{
- auto fmp = mp->GetAnonChild();
- if (!cmd.fetch()) {
- throw NoRowsReturned();
- }
- SqlSourcePtr h = new SqlSource();
- const DB::Column & c = cmd[0];
- c.apply(*h);
- if (!h->isNull()) {
- fmp->Create();
- fmp->SetValue(h);
- fmp->Complete();
- }
- if (cmd.fetch()) {
- throw std::invalid_argument("Too many rows returned");
- }
-}
-
-void
-SqlSelectDeserializer::DeserializeSequence(Slicer::ModelPartPtr mp)
-{
- mp = mp->GetAnonChild();
- SqlSourcePtr h = new SqlSource();
- while (cmd.fetch()) {
- DeserializeRow(mp);
- }
-}
-
-void
-SqlSelectDeserializer::DeserializeObject(Slicer::ModelPartPtr mp)
-{
- if (!cmd.fetch()) {
- throw NoRowsReturned();
- }
- DeserializeRow(mp);
- if (cmd.fetch()) {
- while (cmd.fetch()) ;
- throw std::invalid_argument("Too many rows returned");
- }
-}
-
-void
-SqlSelectDeserializer::DeserializeRow(Slicer::ModelPartPtr mp)
-{
- SqlSourcePtr h = new SqlSource();
- auto rmp = mp->GetAnonChild();
- if (rmp) {
- if (typeIdColIdx) {
- rmp = rmp->GetSubclassModelPart(cmd / *typeIdColIdx);
- }
- rmp->Create();
- for (auto col = 0u; col < columnCount; col += 1) {
- const DB::Column & c = cmd[col];
- auto fmpr = rmp->GetAnonChildRef([&c](Slicer::HookCommonPtr h) {
- return boost::iequals(c.name.raw(), h->PartName());
- });
- if (fmpr) {
- auto fmp = fmpr->Child();
- c.apply(*h);
- if (!h->isNull()) {
- fmp->Create();
- fmp->SetValue(h);
- fmp->Complete();
- }
- }
- }
- rmp->Complete();
- }
-}
-
diff --git a/p2pvr/daemon/sqlSelectDeserializer.h b/p2pvr/daemon/sqlSelectDeserializer.h
deleted file mode 100644
index 0c32811..0000000
--- a/p2pvr/daemon/sqlSelectDeserializer.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef P2PVR_SQL_DESERIALIZER_H
-#define P2PVR_SQL_DESERIALIZER_H
-
-#include <slicer/serializer.h>
-#include <selectcommand.h>
-
-class NoRowsReturned : public std::exception { };
-
-class SqlSelectDeserializer : public Slicer::Deserializer {
- public:
- SqlSelectDeserializer(DB::SelectCommand &, IceUtil::Optional<std::string> typeIdCol = IceUtil::Optional<std::string>());
-
- virtual void Deserialize(Slicer::ModelPartPtr) override;
-
- protected:
- void DeserializeSimple(Slicer::ModelPartPtr);
- void DeserializeObject(Slicer::ModelPartPtr);
- void DeserializeSequence(Slicer::ModelPartPtr);
- void DeserializeRow(Slicer::ModelPartPtr);
-
- DB::SelectCommand & cmd;
- unsigned int columnCount;
- IceUtil::Optional<std::string> typeIdColName;
- IceUtil::Optional<unsigned int> typeIdColIdx;
-};
-
-#endif
-
diff --git a/p2pvr/daemon/storage.h b/p2pvr/daemon/storage.h
index 144d6bd..982c3fd 100644
--- a/p2pvr/daemon/storage.h
+++ b/p2pvr/daemon/storage.h
@@ -6,8 +6,9 @@
#include <string>
#include <boost/filesystem/path.hpp>
#include "temporaryIceAdapterObject.h"
+#include <visibility.h>
-class Storage : public P2PVR::Storage {
+class DLL_PUBLIC Storage : public P2PVR::Storage {
public:
P2PVR::RawDataClientPrx OpenForWrite(const std::string &, const Ice::Current &) override;
void Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &) override;
diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam
index 86bb906..6f0f0dd 100644
--- a/p2pvr/daemon/unittests/Jamfile.jam
+++ b/p2pvr/daemon/unittests/Jamfile.jam
@@ -237,6 +237,7 @@ run
<library>Ice
<library>../..//boost_utf
<library>testCommon
+ <library>..//slicer-db
<dependency>test-data
<define>ROOT=\"$(me)\"
: testSqlSelectDeserializer ;
diff --git a/p2pvr/daemon/unittests/mockScheduler.cpp b/p2pvr/daemon/unittests/mockScheduler.cpp
index 2677df7..193630d 100644
--- a/p2pvr/daemon/unittests/mockScheduler.cpp
+++ b/p2pvr/daemon/unittests/mockScheduler.cpp
@@ -29,8 +29,13 @@ MockScheduler::GetScheduledToRecord(const::Ice::Current &)
}
Ice::Int
+MockScheduler::NewSchedule(const::P2PVR::SchedulePtr &, const::Ice::Current &)
+{
+ return 1;
+}
+
+void
MockScheduler::UpdateSchedule(const::P2PVR::SchedulePtr &, const::Ice::Current &)
{
- return 0;
}
diff --git a/p2pvr/daemon/unittests/mockScheduler.h b/p2pvr/daemon/unittests/mockScheduler.h
index 9176bb6..e90567b 100644
--- a/p2pvr/daemon/unittests/mockScheduler.h
+++ b/p2pvr/daemon/unittests/mockScheduler.h
@@ -10,7 +10,8 @@ class MockScheduler : public P2PVR::Schedules {
P2PVR::SchedulePtr GetSchedule(::Ice::Int, const ::Ice::Current&) override;
P2PVR::ScheduleList GetSchedules(const ::Ice::Current&) override;
P2PVR::ScheduledToRecordList GetScheduledToRecord(const ::Ice::Current&) override;
- Ice::Int UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
+ Ice::Int NewSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
+ void UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override;
};
#endif
diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp
index 38c9478..9926c2b 100644
--- a/p2pvr/daemon/unittests/testMaint.cpp
+++ b/p2pvr/daemon/unittests/testMaint.cpp
@@ -13,7 +13,7 @@
#include <linux/dvb/frontend.h>
#include <definedDirs.h>
#include "mockDefs.h"
-#include "sqlSelectDeserializer.h"
+#include <slicer/db/sqlSelectDeserializer.h>
#include "commonHelpers.h"
#include <slicer/slicer.h>
#include <testAppInstance.h>
diff --git a/p2pvr/daemon/unittests/testRecording.cpp b/p2pvr/daemon/unittests/testRecording.cpp
index d3ecee6..260bf82 100644
--- a/p2pvr/daemon/unittests/testRecording.cpp
+++ b/p2pvr/daemon/unittests/testRecording.cpp
@@ -13,7 +13,7 @@
#include <linux/dvb/frontend.h>
#include <definedDirs.h>
#include "mockDefs.h"
-#include "sqlSelectDeserializer.h"
+#include <slicer/db/sqlSelectDeserializer.h>
#include "commonHelpers.h"
#include "serviceStreamer.h"
#include "temporaryIceAdapterObject.h"
diff --git a/p2pvr/daemon/unittests/testRecordings.cpp b/p2pvr/daemon/unittests/testRecordings.cpp
index ff8f676..7415cb1 100644
--- a/p2pvr/daemon/unittests/testRecordings.cpp
+++ b/p2pvr/daemon/unittests/testRecordings.cpp
@@ -68,9 +68,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));
- auto id = r->NewRecording(rec);
+ rec->RecordingId = r->NewRecording(rec);
+ BOOST_REQUIRE_EQUAL(218, rec->RecordingId);
r->GetRecordings();
- r->DeleteRecording(id);
+ r->DeleteRecording(rec->RecordingId);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp
index 9afdaad..45414aa 100644
--- a/p2pvr/daemon/unittests/testSched.cpp
+++ b/p2pvr/daemon/unittests/testSched.cpp
@@ -79,11 +79,10 @@ BOOST_AUTO_TEST_CASE( sc_crud )
P2PVR::SchedulePtr schedule = new P2PVR::Schedule();
schedule->Search = "Top Gear";
- auto id = sc->UpdateSchedule(schedule);
- BOOST_REQUIRE(id > 0);
- schedule->ScheduleId = id;
+ schedule->ScheduleId = sc->NewSchedule(schedule);
+ BOOST_REQUIRE_EQUAL(187, schedule->ScheduleId);
- auto fetched = sc->GetSchedule(id);
+ auto fetched = sc->GetSchedule(schedule->ScheduleId);
BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId);
BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search);
BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority);
@@ -94,10 +93,9 @@ BOOST_AUTO_TEST_CASE( sc_crud )
schedule->Search = "Top Gear Special";
schedule->Early.Minutes = 5;
schedule->Late.Minutes = 15;
- auto updatedId = sc->UpdateSchedule(schedule);
+ sc->UpdateSchedule(schedule);
- fetched = sc->GetSchedule(id);
- BOOST_REQUIRE_EQUAL(updatedId, id);
+ fetched = sc->GetSchedule(schedule->ScheduleId);
BOOST_REQUIRE_EQUAL(schedule->ScheduleId, fetched->ScheduleId);
BOOST_REQUIRE_EQUAL(*schedule->Search, *fetched->Search);
BOOST_REQUIRE_EQUAL(schedule->Priority, fetched->Priority);
diff --git a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
index 077486c..47d36c5 100644
--- a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
+++ b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE SqlSelectDeserializer
#include <boost/test/unit_test.hpp>
-#include <sqlSelectDeserializer.h>
+#include <slicer/db/sqlSelectDeserializer.h>
#include <slicer/slicer.h>
#include <connection.h>
#include <p2pvr.h>
@@ -33,7 +33,7 @@ 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<SqlSelectDeserializer, P2PVR::Events>(*sel);
+ 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);
@@ -52,7 +52,7 @@ 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<SqlSelectDeserializer, int>(*sel);
+ auto res = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, int>(*sel);
BOOST_REQUIRE_EQUAL(res, 49741);
}
@@ -60,7 +60,7 @@ 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<SqlSelectDeserializer, P2PVR::EventPtr>(*sel);
+ 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");
@@ -74,7 +74,7 @@ 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<SqlSelectDeserializer, P2PVR::Deliveries>(*sel, "typeid");
+ 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);
diff --git a/p2pvr/daemon/unittests/testp2ice.cpp b/p2pvr/daemon/unittests/testp2ice.cpp
index dc584b6..6eece19 100644
--- a/p2pvr/daemon/unittests/testp2ice.cpp
+++ b/p2pvr/daemon/unittests/testp2ice.cpp
@@ -27,9 +27,8 @@ void
unloadTests()
{
BOOST_REQUIRE_THROW(RowSetFactory::get("P2PVR-SI-GetEvent"), AdHoc::NoSuchPluginException);
- // Known issue, these *should* unload, but for some reason, don't.
- BOOST_WARN_THROW(StreamFactory::get("p2pvrrecordingstream"), AdHoc::NoSuchPluginException);
- BOOST_WARN_THROW(StreamFactory::get("p2pvrservicestream"), AdHoc::NoSuchPluginException);
+ BOOST_REQUIRE_THROW(StreamFactory::get("p2pvrrecordingstream"), AdHoc::NoSuchPluginException);
+ BOOST_REQUIRE_THROW(StreamFactory::get("p2pvrservicestream"), AdHoc::NoSuchPluginException);
}
BOOST_GLOBAL_FIXTURE( TestAppInstance );