From 212efb21d95ba89b6231497cfd57f81f5c69d444 Mon Sep 17 00:00:00 2001 From: randomdan Date: Thu, 13 Mar 2014 21:10:29 +0000 Subject: Remove the pointless maint functions for program map and program associations, along with the pointless programid column --- p2pvr/daemon/maintenance.cpp | 2 - p2pvr/daemon/maintenance.h | 2 - p2pvr/daemon/maintenance/programAssociations.cpp | 80 -------------- p2pvr/daemon/maintenance/programMap.cpp | 133 ----------------------- p2pvr/datasources/schema.sql | 3 +- p2pvr/ice/p2pvr.ice | 2 - 6 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 p2pvr/daemon/maintenance/programAssociations.cpp delete mode 100644 p2pvr/daemon/maintenance/programMap.cpp diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp index 3475544..8e204f7 100644 --- a/p2pvr/daemon/maintenance.cpp +++ b/p2pvr/daemon/maintenance.cpp @@ -49,8 +49,6 @@ Maintenance::UpdateAll(short type, const Ice::Current & ice) { UpdateNetwork(type, ice); UpdateServices(type, ice); - UpdateProgramAssociations(type, ice); - UpdateProgramMaps(type, ice); UpdateEvents(type, ice); } diff --git a/p2pvr/daemon/maintenance.h b/p2pvr/daemon/maintenance.h index 563455a..9859c83 100644 --- a/p2pvr/daemon/maintenance.h +++ b/p2pvr/daemon/maintenance.h @@ -12,8 +12,6 @@ class Maintenance : public P2PVR::Maintenance, public DatabaseClient { void UpdateAll(short type, const Ice::Current &); void UpdateNetwork(short type, const Ice::Current &); void UpdateServices(short type, const Ice::Current &); - void UpdateProgramAssociations(short type, const Ice::Current &); - void UpdateProgramMaps(short type, const Ice::Current &); void UpdateEvents(short type, const Ice::Current &); INITOPTIONS; diff --git a/p2pvr/daemon/maintenance/programAssociations.cpp b/p2pvr/daemon/maintenance/programAssociations.cpp deleted file mode 100644 index ad6438c..0000000 --- a/p2pvr/daemon/maintenance/programAssociations.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include "../maintenance.h" -#include -#include -#include -#include -#include -#include -#include - -class SiProgramAssociationHandler : public SiProgramAssociationParser { - public: - bool HandleTable(ProgramAssociationMapPtr pam) - { - Logger()->messagebf(LOG_DEBUG, "Program association table"); - BOOST_FOREACH(const auto & pa, *pam) { - Logger()->messagebf(LOG_DEBUG, " %d -> %d", pa.first, pa.second); - } - BOOST_FOREACH(const auto & pa, *pam) { - map[pa.first] = pa.second; - } - return false; - } - - ProgramAssociationMap map; -}; - -static -void -CreatePATColumns(const ColumnCreator & cc) -{ - cc("serviceId", true); - cc("programId", false); -} - -void -Maintenance::UpdateProgramAssociations(short type, const Ice::Current & ice) -{ - auto ic = ice.adapter->getCommunicator(); - auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); - - if (!devs || !si) { - throw std::runtime_error("bad proxy(s)"); - } - - auto siparser = new SiProgramAssociationHandler(); - TemporarayIceAdapterObject parser(ice.adapter, siparser); - - const auto deliveries = si->GetAllDeliveries(type); - if (deliveries.empty()) { - throw std::runtime_error("no delivery methods"); - } - - BOOST_FOREACH(const auto & transport, deliveries) { - try { - Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); - auto tuner = devs->GetTunerSpecific(transport); - Logger()->messagebf(LOG_DEBUG, "%s: Fetching associations", __PRETTY_FUNCTION__); - tuner->SendProgramAssociationTable(parser); - Logger()->messagebf(LOG_INFO, "%s: Updated associations", __PRETTY_FUNCTION__); - devs->ReleaseTuner(tuner); - } - catch (...) { - // Tuning can fail - } - } - - TxHelper tx(this); - SqlMergeTask mergeServices("postgres", "services"); - CreatePATColumns(boost::bind(SqlMergeColumnsInserter, &mergeServices, _1, _2)); - // Don't change the list of services available from the network - mergeServices.doDelete = VariableType(false); - mergeServices.doInsert = VariableType(false); - Columns cols; - mergeServices.sources.insert(new MapIterator(CreatePATColumns, &siparser->map)); - mergeServices.loadComplete(this); - mergeServices.execute(NULL); -} - diff --git a/p2pvr/daemon/maintenance/programMap.cpp b/p2pvr/daemon/maintenance/programMap.cpp deleted file mode 100644 index 94d7752..0000000 --- a/p2pvr/daemon/maintenance/programMap.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include -#include "../maintenance.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class SiProgramMapHandler : public SiProgramMapParser { - public: - SiProgramMapHandler(const RowProcessorCallback & cb) : - callBack(cb) {} - - bool HandleTable(DVBSI::ProgramMapPtr pmp) - { - Logger()->messagebf(LOG_DEBUG, "Program map: serviceId = %d", pmp->ServiceId); - BOOST_FOREACH(const auto & s, pmp->Streams) { - Logger()->messagef(LOG_DEBUG, "type: %02x id: %d", s->Type, s->Id); - } - BOOST_FOREACH(const auto & s, pmp->Streams) { - BindColumns(rowState, s); - rowState.process(callBack); - } - return false; - } - - private: - ObjectRowState rowState; - const RowProcessorCallback callBack; -}; - -typedef boost::shared_ptr SelectPtr; - -template -void -operator<<(T & val, const DB::Column & col) -{ - HandleAsVariableType havt; - col.apply(havt); - val = havt.variable; -} - -class SiProgramMapMerger : public IHaveSubTasks { - public: - SiProgramMapMerger(short t, CommonObjects * co, const Ice::Current & i) : - SourceObject(__PRETTY_FUNCTION__), - IHaveSubTasks(NULL), - commonObjects(co), - type(t), - ice(i) { } - - void execute(ExecContext * ec) const - { - auto ic = ice.adapter->getCommunicator(); - auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); - - if (!devs || !si) { - throw std::runtime_error("bad proxy(s)"); - } - - TemporarayIceAdapterObject parser(ice.adapter, - new SiProgramMapHandler(boost::bind(&SiProgramMapMerger::executeChildren, this, ec))); - - const auto deliveries = si->GetAllDeliveries(type); - if (deliveries.empty()) { - throw std::runtime_error("no delivery methods"); - } - - auto db = commonObjects->dataSource("postgres")->getReadonly(); - SelectPtr sel = SelectPtr(db->newSelectCommand("select d.frequency, s.programid \ - from delivery_dvbt d, services s \ - where d.transportstreamid = s.transportstreamid \ - and s.programid is not null \ - order by s.transportstreamid, s.serviceid")); - int64_t curFreq = 0; - P2PVR::TunerPrx tuner; - while (sel->fetch()) { - int64_t freq, pid; - freq << (*sel)[0]; - pid << (*sel)[1]; - - if (freq != curFreq) { - if (tuner) { - devs->ReleaseTuner(tuner); - } - Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); - const auto transport = *std::find_if(deliveries.begin(), deliveries.end(), - [freq](const DVBSI::DeliveryPtr & del) { return del->Frequency == freq; }); - tuner = devs->GetTunerSpecific(transport); - curFreq = freq; - } - - Logger()->messagebf(LOG_DEBUG, "%s: Fetching associations", __PRETTY_FUNCTION__); - tuner->SendProgramMap(pid, parser); - Logger()->messagebf(LOG_INFO, "%s: Updated associations", __PRETTY_FUNCTION__); - } - if (tuner) { - devs->ReleaseTuner(tuner); - } - } - - private: - CommonObjects * commonObjects; - const short type; - const Ice::Current & ice; - - void executeChildren(ExecContext * ec) const - { - BOOST_FOREACH(const Tasks::value_type & sq, normal) { - sq->execute(ec); - } - } -}; - -void -Maintenance::UpdateProgramMaps(short type, const Ice::Current & ice) -{ - TxHelper tx(this); - SqlMergeTask mergeServiceStreams("postgres", "servicestreams"); - CreateColumns(boost::bind(SqlMergeColumnsInserter, &mergeServiceStreams, _1, _2)); - mergeServiceStreams.sources.insert(new SiProgramMapMerger(type, this, ice)); - mergeServiceStreams.loadComplete(this); - mergeServiceStreams.execute(NULL); -} - diff --git a/p2pvr/datasources/schema.sql b/p2pvr/datasources/schema.sql index 53c0e08..df65cfa 100644 --- a/p2pvr/datasources/schema.sql +++ b/p2pvr/datasources/schema.sql @@ -281,8 +281,7 @@ CREATE TABLE services ( eitschedule boolean, eitpresentfollowing boolean, freecamode boolean, - transportstreamid integer NOT NULL, - programid integer + transportstreamid integer NOT NULL ); diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index bd79cb1..08356ae 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -52,8 +52,6 @@ module P2PVR { idempotent void UpdateAll(); idempotent void UpdateNetwork(short type); idempotent void UpdateServices(short type); - idempotent void UpdateProgramAssociations(short type); - idempotent void UpdateProgramMaps(short type); idempotent void UpdateEvents(short type); }; -- cgit v1.2.3