diff options
-rw-r--r-- | p2pvr/daemon/si.cpp | 128 | ||||
-rw-r--r-- | p2pvr/daemon/si.h | 2 | ||||
-rw-r--r-- | p2pvr/daemon/sql/SI_allDeliveries.sql | 3 | ||||
-rw-r--r-- | p2pvr/daemon/sql/SI_deliveryForService.sql | 4 | ||||
-rw-r--r-- | p2pvr/daemon/sql/SI_deliveryForTransport.sql | 3 | ||||
-rw-r--r-- | p2pvr/daemon/sql/SI_serviceNextUsed.sql | 7 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSi.cpp | 61 | ||||
-rw-r--r-- | p2pvr/ice/p2pvr.ice | 6 |
8 files changed, 128 insertions, 86 deletions
diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp index ad33109..fc58f8e 100644 --- a/p2pvr/daemon/si.cpp +++ b/p2pvr/daemon/si.cpp @@ -2,10 +2,14 @@ #include "si.h" #include "resources.h" #include "dvbsiHelpers.h" -#include "sqlContainerCreator.h" -#include <linux/dvb/frontend.h> +#include "sqlSelectDeserializer.h" +#include "commonHelpers.h" +#include <slicer/slicer.h> #include <logger.h> +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); @@ -18,31 +22,11 @@ ResourceString(SI_eventsInRange, sql_SI_eventsInRange); ResourceString(SI_eventSearch, sql_SI_eventSearch); P2PVR::Deliveries -SI::GetAllDeliveries(short type, const Ice::Current &) +SI::GetAllDeliveries(const Ice::Current &) { - Logger()->messagebf(LOG_DEBUG, "%s(type %d)", __PRETTY_FUNCTION__, type); - P2PVR::Deliveries rtn; - SelectPtr sel; - switch (type) { - case FE_OFDM: - { - SqlContainerCreator<P2PVR::Deliveries, DVBSI::TerrestrialDelivery> cc(rtn); - cc.populate(Select("SELECT * FROM delivery_dvbt ORDER BY transportStreamId").second); - break; - } - case FE_QAM: - { - SqlContainerCreator<P2PVR::Deliveries, DVBSI::CableDelivery> cc(rtn); - cc.populate(Select("SELECT * FROM delivery_dvbc ORDER BY transportStreamId").second); - break; - } - case FE_QPSK: - { - SqlContainerCreator<P2PVR::Deliveries, DVBSI::SatelliteDelivery> cc(rtn); - cc.populate(Select("SELECT * FROM delivery_dvbs ORDER BY transportStreamId").second); - break; - } - } + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + auto rtn = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Deliveries>( + *Select(SI_allDeliveries).second, "delivery_type"); Logger()->messagebf(LOG_DEBUG, "%s: Found %d delivery methods", __PRETTY_FUNCTION__, rtn.size()); return rtn; } @@ -50,53 +34,41 @@ SI::GetAllDeliveries(short type, const Ice::Current &) DVBSI::DeliveryPtr SI::GetDeliveryForTransport(int id, const Ice::Current&) { - P2PVR::Deliveries rtn; - SqlContainerCreator<P2PVR::Deliveries, DVBSI::TerrestrialDelivery> cct(rtn); - cct.populate(Select("SELECT * FROM delivery_dvbt WHERE transportStreamId = ?", id).second); - SqlContainerCreator<P2PVR::Deliveries, DVBSI::CableDelivery> ccc(rtn); - ccc.populate(Select("SELECT * FROM delivery_dvbc WHERE transportStreamId = ?", id).second); - SqlContainerCreator<P2PVR::Deliveries, DVBSI::SatelliteDelivery> ccs(rtn); - ccs.populate(Select("SELECT * FROM delivery_dvbs WHERE transportStreamId = ?", id).second); - return rtn.front(); + Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>( + *Select(SI_deliveryForTransport, id).second, "delivery_type"); } DVBSI::DeliveryPtr SI::GetDeliveryForSi(const Ice::Current&) { - P2PVR::Deliveries rtn; - SqlContainerCreator<P2PVR::Deliveries, DVBSI::TerrestrialDelivery> cct(rtn); - cct.populate(Select(SI_serviceNextUsed).second); - return rtn.empty() ? DVBSI::DeliveryPtr() : rtn.front(); + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>( + *Select(SI_serviceNextUsed).second, "delivery_type"); } DVBSI::DeliveryPtr SI::GetDeliveryForService(int id, const Ice::Current&) { - P2PVR::Deliveries rtn; - SqlContainerCreator<P2PVR::Deliveries, DVBSI::TerrestrialDelivery> cct(rtn); - cct.populate(Select("SELECT d.* FROM services s, delivery_dvbt d WHERE serviceid = ? AND s.transportstreamid = d.transportstreamid", id).second); - SqlContainerCreator<P2PVR::Deliveries, DVBSI::CableDelivery> ccc(rtn); - ccc.populate(Select("SELECT d.* FROM services s, delivery_dvbc d WHERE serviceid = ? AND s.transportstreamid = d.transportstreamid", id).second); - SqlContainerCreator<P2PVR::Deliveries, DVBSI::SatelliteDelivery> ccs(rtn); - ccs.populate(Select("SELECT d.* FROM services s, delivery_dvbs d WHERE serviceid = ? AND s.transportstreamid = d.transportstreamid", id).second); - return rtn.front(); + Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>( + *Select(SI_deliveryForService, id).second, "delivery_type"); } DVBSI::ServiceList SI::GetServices(const Ice::Current&) { - DVBSI::ServiceList rtn; - SqlContainerCreator<DVBSI::ServiceList, DVBSI::Service> cc(rtn); - cc.populate(Select(SI_servicesSelectAll).second); - return rtn; + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::ServiceList>( + *Select(SI_servicesSelectAll).second); } DVBSI::ServicePtr SI::GetService(int id, const Ice::Current&) { - DVBSI::ServiceList rtn; - SqlContainerCreator<DVBSI::ServiceList, DVBSI::Service> cc(rtn); - cc.populate(Select(SI_servicesSelectById, id).second); + Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); + auto rtn = Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::ServiceList>( + *Select(SI_servicesSelectById, id).second); if (rtn.empty()) throw P2PVR::NotFound(); return rtn.front(); } @@ -104,10 +76,12 @@ SI::GetService(int id, const Ice::Current&) P2PVR::Events SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &) { + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - for (const auto & uid : eventUids){ - cc.populate(Select(SI_eventByUid, uid).second); + for (const auto & uid : eventUids) { + auto list = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventByUid, uid).second); + std::copy(list.begin(), list.end(), std::back_inserter(rtn)); } if (rtn.size() != eventUids.size()) throw P2PVR::NotFound(); return rtn; @@ -116,9 +90,9 @@ SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &) P2PVR::EventPtr SI::GetEvent(int serviceId, int eventId, const Ice::Current &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventById, serviceId, eventId).second); + Logger()->messagef(LOG_DEBUG, "%s(s=%d, e=%d)", __PRETTY_FUNCTION__, serviceId, eventId); + auto rtn = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventById, serviceId, eventId).second); if (rtn.empty()) throw P2PVR::NotFound(); return rtn.front(); } @@ -126,45 +100,41 @@ SI::GetEvent(int serviceId, int eventId, const Ice::Current &) P2PVR::Events SI::EventsOnNow(const Ice::Current &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventsOnNow).second); - return rtn; + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventsOnNow).second); } P2PVR::Events SI::EventsInRange(const Common::DateTime & from, const Common::DateTime & to, const Ice::Current &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventsInRange, from, to).second); - return rtn; + Logger()->messagebf(LOG_DEBUG, "%s([%s]-[%s])", from, to, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventsInRange, from, to).second); } 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 &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords).second); - return rtn; + 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>( + *Select(SI_eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords).second); } P2PVR::Events SI::EventsInSchedules(const Ice::Current &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventsInSchedules).second); - return rtn; + Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventsInSchedules).second); } P2PVR::Events SI::EventsInSchedule(int scheduleId, const Ice::Current &) { - P2PVR::Events rtn; - SqlContainerCreator<P2PVR::Events, P2PVR::Event> cc(rtn); - cc.populate(Select(SI_eventsInSchedule, scheduleId).second); - return rtn; + Logger()->messagebf(LOG_DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__); + return Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>( + *Select(SI_eventsInSchedule, scheduleId).second); } diff --git a/p2pvr/daemon/si.h b/p2pvr/daemon/si.h index 21b78e1..d87b3b5 100644 --- a/p2pvr/daemon/si.h +++ b/p2pvr/daemon/si.h @@ -6,7 +6,7 @@ class SI : public P2PVR::SI, public DatabaseClient { public: - P2PVR::Deliveries GetAllDeliveries(short type, const Ice::Current &); + P2PVR::Deliveries GetAllDeliveries(const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForTransport(int id, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForSi(const Ice::Current &); diff --git a/p2pvr/daemon/sql/SI_allDeliveries.sql b/p2pvr/daemon/sql/SI_allDeliveries.sql new file mode 100644 index 0000000..2efa70a --- /dev/null +++ b/p2pvr/daemon/sql/SI_allDeliveries.sql @@ -0,0 +1,3 @@ +SELECT * +FROM allDeliveries +ORDER BY transportStreamId diff --git a/p2pvr/daemon/sql/SI_deliveryForService.sql b/p2pvr/daemon/sql/SI_deliveryForService.sql new file mode 100644 index 0000000..cf4115f --- /dev/null +++ b/p2pvr/daemon/sql/SI_deliveryForService.sql @@ -0,0 +1,4 @@ +SELECT d.* +FROM allDeliveries d, services s +WHERE d.transportStreamId = s.transportStreamId +AND s.serviceId = ? diff --git a/p2pvr/daemon/sql/SI_deliveryForTransport.sql b/p2pvr/daemon/sql/SI_deliveryForTransport.sql new file mode 100644 index 0000000..1805d7a --- /dev/null +++ b/p2pvr/daemon/sql/SI_deliveryForTransport.sql @@ -0,0 +1,3 @@ +SELECT * +FROM allDeliveries +WHERE transportStreamId = ? diff --git a/p2pvr/daemon/sql/SI_serviceNextUsed.sql b/p2pvr/daemon/sql/SI_serviceNextUsed.sql index 1bf2053..385462d 100644 --- a/p2pvr/daemon/sql/SI_serviceNextUsed.sql +++ b/p2pvr/daemon/sql/SI_serviceNextUsed.sql @@ -1,11 +1,12 @@ -SELECT dd.* -FROM delivery_dvbt dd, services s +SELECT d.* +FROM allDeliveries d + LEFT OUTER JOIN services s + ON d.transportstreamid = s.transportstreamid LEFT OUTER JOIN events e ON s.serviceid = e.serviceid AND e.starttime > NOW() LEFT OUTER JOIN record r ON r.eventuid = e.eventuid AND r.recordstatus = 0 -WHERE dd.transportstreamid = s.transportstreamid ORDER BY e.starttime, s.serviceid LIMIT 1 diff --git a/p2pvr/daemon/unittests/testSi.cpp b/p2pvr/daemon/unittests/testSi.cpp index d191b38..7030c0a 100644 --- a/p2pvr/daemon/unittests/testSi.cpp +++ b/p2pvr/daemon/unittests/testSi.cpp @@ -69,6 +69,11 @@ BOOST_AUTO_TEST_CASE( si_getEvent ) BOOST_REQUIRE_EQUAL(event->Current, true); } +BOOST_AUTO_TEST_CASE( si_getEvent_missing ) +{ + BOOST_REQUIRE_THROW(si->GetEvent(0, 0), P2PVR::NotFound); +} + BOOST_AUTO_TEST_CASE( si_getEventsOnNow ) { si->EventsOnNow(); @@ -101,5 +106,61 @@ BOOST_AUTO_TEST_CASE( si_getEventSearch ) Common::DateTime {2014, 12, 19, 3, 0}, Common::DateTime {2014, 12, 20, 3, 0}); } +BOOST_AUTO_TEST_CASE( si_getAllDeliveries ) +{ + auto dels = si->GetAllDeliveries(); + BOOST_REQUIRE_EQUAL(dels.size(), 6); +} + +BOOST_AUTO_TEST_CASE( si_getDeliveryForTransport ) +{ + auto del = si->GetDeliveryForTransport(4170); + BOOST_REQUIRE(del); + auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del); + BOOST_REQUIRE(dvbt); + BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170); +} + +BOOST_AUTO_TEST_CASE( si_getDeliveryForSI ) +{ + auto del = si->GetDeliveryForSi(); + BOOST_REQUIRE(del); + auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del); + BOOST_REQUIRE(dvbt); +} + +BOOST_AUTO_TEST_CASE( si_getDeliveryForService ) +{ + auto del = si->GetDeliveryForService(4170); + BOOST_REQUIRE(del); + auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del); + BOOST_REQUIRE(dvbt); + BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170); +} + +BOOST_AUTO_TEST_CASE( si_getServices ) +{ + auto services = si->GetServices(); + BOOST_REQUIRE_EQUAL(services.size(), 145); + BOOST_REQUIRE_EQUAL(services[0]->Name, "BBC ONE Yorks"); + BOOST_REQUIRE_EQUAL(services[0]->DefaultAuthority, "fp.bbc.co.uk"); + BOOST_REQUIRE_EQUAL(services[0]->EitSchedule, true); + BOOST_REQUIRE_EQUAL(services[0]->EitPresentFollowing, true); +} + +BOOST_AUTO_TEST_CASE( si_getService ) +{ + auto service = si->GetService(4170); + BOOST_REQUIRE_EQUAL(service->Name, "BBC ONE Yorks"); + BOOST_REQUIRE_EQUAL(service->DefaultAuthority, "fp.bbc.co.uk"); + BOOST_REQUIRE_EQUAL(service->EitSchedule, true); + BOOST_REQUIRE_EQUAL(service->EitPresentFollowing, true); +} + +BOOST_AUTO_TEST_CASE( si_getServiceMissing ) +{ + BOOST_REQUIRE_THROW(si->GetService(0), P2PVR::NotFound); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index 0d287d5..f191ab8 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -78,7 +78,7 @@ module P2PVR { ["project2:rows"] idempotent RecordingList GetRecordings(); }; - + interface Schedules { ["project2:task"] idempotent void DeleteSchedule(int scheduleId); @@ -92,12 +92,12 @@ module P2PVR { ["project2:task"] idempotent void DoReschedule(); }; - + sequence<DVBSI::Delivery> Deliveries; sequence<int> IntSequence; interface SI { // Get delivery methods - idempotent Deliveries GetAllDeliveries(short type); + idempotent Deliveries GetAllDeliveries(); idempotent DVBSI::Delivery GetDeliveryForService(int id); idempotent DVBSI::Delivery GetDeliveryForTransport(int id); idempotent DVBSI::Delivery GetDeliveryForSi(); |