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.cpp122
1 files changed, 63 insertions, 59 deletions
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);
}