diff options
-rw-r--r-- | p2pvr/daemon/maintenance/events.cpp | 16 | ||||
-rw-r--r-- | p2pvr/daemon/maintenance/network.cpp | 16 | ||||
-rw-r--r-- | p2pvr/daemon/maintenance/services.cpp | 4 | ||||
-rw-r--r-- | p2pvr/daemon/schedules.cpp | 9 | ||||
-rw-r--r-- | p2pvr/lib/containerIterator.h | 4 | ||||
-rw-r--r-- | p2pvr/lib/objectRowState.cpp | 17 | ||||
-rw-r--r-- | p2pvr/lib/objectRowState.h | 13 |
7 files changed, 44 insertions, 35 deletions
diff --git a/p2pvr/daemon/maintenance/events.cpp b/p2pvr/daemon/maintenance/events.cpp index 92b214c..8c0834b 100644 --- a/p2pvr/daemon/maintenance/events.cpp +++ b/p2pvr/daemon/maintenance/events.cpp @@ -13,29 +13,32 @@ ResourceString(Maint_pruneEvents, sql_Maint_pruneEvents); class SiEventsHandler : public SiEpgParser { public: - SiEventsHandler(const RowProcessorCallback & cb) : + SiEventsHandler(const RowProcessorCallback & cb, const SelectedColumns & sc) : + ecs(sc), callBack(cb) {} bool HandleTable(DVBSI::EventPtr e) { Logger()->messagebf(LOG_DEBUG, "Service Id: %d Program Id: %d Title: %s Time: %s - %s", e->ServiceId, e->EventId, e->Title, e->StartTime, e->StopTime); - BindColumns<DVBSI::EventPtr>(rowState, e); + BindColumns<DVBSI::EventPtr>(rowState, ecs, e); rowState.process(callBack); return false; } private: ObjectRowState<DVBSI::EventPtr> rowState; + const SelectedColumns & ecs; const RowProcessorCallback callBack; }; class SiEventsMerger : public IHaveSubTasks { public: - SiEventsMerger(short t, const Ice::Current & i) : + SiEventsMerger(short t, const Ice::Current & i, const SelectedColumns & sc) : SourceObject(__PRETTY_FUNCTION__), IHaveSubTasks(NULL), type(t), + ecs(sc), ice(i) { } void execute(ExecContext * ec) const @@ -49,7 +52,7 @@ class SiEventsMerger : public IHaveSubTasks { } TemporarayIceAdapterObject<P2PVR::RawDataClient> parser(ice.adapter, - new SiEventsHandler(boost::bind(&SiEventsMerger::executeChildren, this, ec))); + new SiEventsHandler(boost::bind(&SiEventsMerger::executeChildren, this, ec), ecs)); auto delivery = si->GetDeliveryForSi(); if (!delivery) { @@ -65,6 +68,7 @@ class SiEventsMerger : public IHaveSubTasks { private: const short type; + const SelectedColumns & ecs; const Ice::Current & ice; void executeChildren(ExecContext * ec) const @@ -80,8 +84,8 @@ Maintenance::UpdateEvents(short type, const Ice::Current & ice) { TxHelper tx(this); SqlMergeTask mergeEvents("postgres", "events"); - CreateColumns<DVBSI::EventPtr>(boost::bind(SqlMergeColumnsInserter, &mergeEvents, _1, _2)); - mergeEvents.sources.insert(new SiEventsMerger(type, ice)); + auto ecs = CreateColumns<DVBSI::EventPtr>(boost::bind(SqlMergeColumnsInserter, &mergeEvents, _1, _2)); + mergeEvents.sources.insert(new SiEventsMerger(type, ice, ecs)); mergeEvents.insteadOfDelete = new DynamicSql::SqlText("SET current = false"); mergeEvents.updateWhere = new DynamicSql::SqlText("a.current"); mergeEvents.loadComplete(this); diff --git a/p2pvr/daemon/maintenance/network.cpp b/p2pvr/daemon/maintenance/network.cpp index 3c21639..97598ad 100644 --- a/p2pvr/daemon/maintenance/network.cpp +++ b/p2pvr/daemon/maintenance/network.cpp @@ -26,15 +26,15 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { DatabaseClient::TxHelper tx(commonObjects); SqlMergeTask mergeNetwork("postgres", "networks"); - CreateColumns<DVBSI::NetworkPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2)); + auto ncs = CreateColumns<DVBSI::NetworkPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeNetwork, _1, _2)); std::vector<DVBSI::NetworkPtr> networks = { n }; - mergeNetwork.sources.insert(new ContainerIterator<std::vector<DVBSI::NetworkPtr>>(&networks)); + mergeNetwork.sources.insert(new ContainerIterator<std::vector<DVBSI::NetworkPtr>>(&networks, ncs)); mergeNetwork.loadComplete(commonObjects); mergeNetwork.execute(NULL); SqlMergeTask mergeTransports("postgres", "transportstreams"); - CreateColumns<DVBSI::NetworkTransportStreamPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2)); - mergeTransports.sources.insert(new ContainerIterator<DVBSI::NetworkTransportStreams>(&n->TransportStreams)); + auto tscs = CreateColumns<DVBSI::NetworkTransportStreamPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeTransports, _1, _2)); + mergeTransports.sources.insert(new ContainerIterator<DVBSI::NetworkTransportStreams>(&n->TransportStreams, tscs)); mergeTransports.loadComplete(commonObjects); mergeTransports.execute(NULL); @@ -43,9 +43,9 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { mergeDelivery<DVBSI::CableDeliveryPtr, &DVBSI::NetworkTransportStream::Cable>("delivery_dvbc", n); SqlMergeTask mergeServices("postgres", "services"); - CreateColumns<DVBSI::NetworkService>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); + auto scs = CreateColumns<DVBSI::NetworkService>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); for (const auto & s : n->TransportStreams) { - mergeServices.sources.insert(new ContainerIterator<DVBSI::NetworkServiceList>(&s->Services)); + mergeServices.sources.insert(new ContainerIterator<DVBSI::NetworkServiceList>(&s->Services, scs)); } mergeServices.loadComplete(commonObjects); mergeServices.execute(NULL); @@ -56,14 +56,14 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n) { SqlMergeTask merge("postgres", table); - CreateColumns<Delivery>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2)); + auto dcs = CreateColumns<Delivery>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &merge, _1, _2)); std::vector<Delivery> dels; for (const auto & s : n->TransportStreams) { if (auto d = s.get()->*member) { dels.push_back(d); } } - merge.sources.insert(new ContainerIterator<decltype(dels)>(&dels)); + merge.sources.insert(new ContainerIterator<decltype(dels)>(&dels, dcs)); merge.loadComplete(commonObjects); merge.execute(NULL); } diff --git a/p2pvr/daemon/maintenance/services.cpp b/p2pvr/daemon/maintenance/services.cpp index 50056ff..afa8084 100644 --- a/p2pvr/daemon/maintenance/services.cpp +++ b/p2pvr/daemon/maintenance/services.cpp @@ -23,11 +23,11 @@ class SiServicesMerger : public SiServicesParser { DatabaseClient::TxHelper tx(commonObjects); SqlMergeTask mergeServices("postgres", "services"); - CreateColumns<DVBSI::ServicePtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); + auto scs = CreateColumns<DVBSI::ServicePtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2)); // Don't change the list of services available from the network mergeServices.doDelete = VariableType(false); mergeServices.doInsert = VariableType(false); - mergeServices.sources.insert(new ContainerIterator<DVBSI::ServiceList>(&ts->Services)); + mergeServices.sources.insert(new ContainerIterator<DVBSI::ServiceList>(&ts->Services, scs)); mergeServices.loadComplete(commonObjects); mergeServices.execute(NULL); return false; diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 4ced9a7..5b0b5cd 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -54,17 +54,18 @@ typedef boost::shared_ptr<Record> RecordPtr; typedef std::vector<RecordPtr> Records; template<> -void +SelectedColumns CreateColumns<RecordPtr>(const ColumnCreator & cc) { cc("eventuid", true); cc("recordstatus", false); cc("scheduleid", false); + return {true, true, true}; } template<> void -BindColumns(RowState & rs, RecordPtr const & s) +BindColumns(RowState & rs, const SelectedColumns &, RecordPtr const & s) { rs.fields[0] << s->EventUid; rs.fields[1] << (int)s->RecordStatus; @@ -325,8 +326,8 @@ Schedules::DoReschedule(const Ice::Current & ice) TxHelper tx(this); SqlMergeTask mergeRecords("postgres", "record"); - CreateColumns<RecordPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); - mergeRecords.sources.insert(new ContainerIterator<Records>(&records)); + auto rcs = CreateColumns<RecordPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); + mergeRecords.sources.insert(new ContainerIterator<Records>(&records, rcs)); mergeRecords.loadComplete(this); mergeRecords.execute(NULL); tx.Commit(); diff --git a/p2pvr/lib/containerIterator.h b/p2pvr/lib/containerIterator.h index 03af88c..dac2639 100644 --- a/p2pvr/lib/containerIterator.h +++ b/p2pvr/lib/containerIterator.h @@ -7,10 +7,10 @@ template <typename T> class ContainerIterator : public IHaveSubTasks { public: - ContainerIterator(const T * con) : + ContainerIterator(const T * con, const SelectedColumns & sc) : SourceObject(__PRETTY_FUNCTION__), IHaveSubTasks(NULL), - binder(boost::bind(&BindColumns<typename T::value_type>, _1, _2)), + binder(boost::bind(&BindColumns<typename T::value_type>, _1, sc, _2)), container(con) { } diff --git a/p2pvr/lib/objectRowState.cpp b/p2pvr/lib/objectRowState.cpp index c882405..3f04cda 100644 --- a/p2pvr/lib/objectRowState.cpp +++ b/p2pvr/lib/objectRowState.cpp @@ -10,14 +10,18 @@ mdHasFlag(const std::list<std::string> & md, const std::string & flag) return std::find(md.begin(), md.end(), flag) != md.end(); } -void +SelectedColumns CreateColumns(Slicer::ModelPartPtr mp, const ColumnCreator & cc) { - mp->OnEachChild([cc](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { + SelectedColumns cols; + mp->OnEachChild([cc,&cols](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { auto & md = h->GetMetadata(); - if (mdHasFlag(md, md_mergeOmit)) return; + auto omitted = mdHasFlag(md, md_mergeOmit); + cols.push_back(!omitted); + if (omitted) return; cc(name, mdHasFlag(md, md_mergeKey)); }); + return cols; } class SqlTarget : public Slicer::ValueTarget, @@ -45,12 +49,11 @@ class SqlTarget : public Slicer::ValueTarget, typedef IceUtil::Handle<SqlTarget> SqlTargetPtr; void -BindColumns(Slicer::ModelPartPtr mp, RowState & rs) +BindColumns(Slicer::ModelPartPtr mp, const SelectedColumns & sc, RowState & rs) { unsigned int field = 0; - mp->OnEachChild([&rs,&field](const std::string &, Slicer::ModelPartPtr mp, Slicer::HookCommonPtr h) { - auto & md = h->GetMetadata(); - if (mdHasFlag(md, md_mergeOmit)) return; + mp->OnEachChild([&rs,&field,&sc](const std::string &, Slicer::ModelPartPtr mp, Slicer::HookCommonPtr) { + if (!sc[field]) return; if (mp && mp->HasValue()) { SqlTargetPtr st = new SqlTarget(rs.fields[field++]); mp->GetValue(st); diff --git a/p2pvr/lib/objectRowState.h b/p2pvr/lib/objectRowState.h index d98380b..142e5cb 100644 --- a/p2pvr/lib/objectRowState.h +++ b/p2pvr/lib/objectRowState.h @@ -8,22 +8,23 @@ typedef boost::function<void(const std::string &, bool)> ColumnCreator; typedef boost::function<void(const ColumnCreator &)> ColumnSpecifier; +typedef std::vector<bool> SelectedColumns; -void BindColumns(Slicer::ModelPartPtr, RowState &); +void BindColumns(Slicer::ModelPartPtr, const SelectedColumns &, RowState &); template <typename V> -void BindColumns(RowState & rs, const V & v) +void BindColumns(RowState & rs, const SelectedColumns & sc, const V & v) { - BindColumns(Slicer::ModelPartFor(const_cast<V &>(v)), rs); + BindColumns(Slicer::ModelPartFor(const_cast<V &>(v)), sc, rs); } -void CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); +SelectedColumns CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); template <typename V> -void CreateColumns(const ColumnCreator & cc) +SelectedColumns CreateColumns(const ColumnCreator & cc) { V v; - CreateColumns(Slicer::ModelPartFor(v), cc); + return CreateColumns(Slicer::ModelPartFor(v), cc); } template <typename T> |