diff options
Diffstat (limited to 'p2pvr/daemon/si.cpp')
-rw-r--r-- | p2pvr/daemon/si.cpp | 128 |
1 files changed, 49 insertions, 79 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); } |