summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/si.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/daemon/si.cpp')
-rw-r--r--p2pvr/daemon/si.cpp172
1 files changed, 89 insertions, 83 deletions
diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp
index 3259888..9164a62 100644
--- a/p2pvr/daemon/si.cpp
+++ b/p2pvr/daemon/si.cpp
@@ -1,14 +1,19 @@
#include <pch.hpp>
#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_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);
@@ -16,32 +21,20 @@ ResourceString(SI_eventsInSchedules, sql_SI_eventsInSchedules);
ResourceString(SI_eventsInRange, sql_SI_eventsInRange);
ResourceString(SI_eventSearch, sql_SI_eventSearch);
+DVBSI::Networks
+SI::GetNetworks(const Ice::Current &)
+{
+ Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::Networks>(
+ *Select(SI_allNetworks).second);
+}
+
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;
}
@@ -49,109 +42,122 @@ 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();
+ try {
+ Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_deliveryForTransport, id).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ throw P2PVR::NotFound();
+ }
}
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.front();
+ try {
+ Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_serviceNextUsed).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ return NULL;
+ }
}
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();
+ try {
+ Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_deliveryForService, id).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ throw P2PVR::NotFound();
+ }
}
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();
}
-DVBSI::EventPtr
+P2PVR::Events
+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>(
+ *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;
+}
+
+P2PVR::EventPtr
SI::GetEvent(int serviceId, int eventId, const Ice::Current &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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();
}
-DVBSI::Events
+P2PVR::Events
SI::EventsOnNow(const Ice::Current &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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);
}
-DVBSI::Events
+P2PVR::Events
SI::EventsInRange(const Common::DateTime & from, const Common::DateTime & to, const Ice::Current &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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);
}
-DVBSI::Events
+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 &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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);
}
-DVBSI::Events
+P2PVR::Events
SI::EventsInSchedules(const Ice::Current &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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);
}
-DVBSI::Events
+P2PVR::Events
SI::EventsInSchedule(int scheduleId, const Ice::Current &)
{
- DVBSI::Events rtn;
- SqlContainerCreator<DVBSI::Events, DVBSI::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);
}