summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/daemon/maintenance/network.cpp28
-rw-r--r--p2pvr/lib/singleIterator.h38
2 files changed, 18 insertions, 48 deletions
diff --git a/p2pvr/daemon/maintenance/network.cpp b/p2pvr/daemon/maintenance/network.cpp
index 4ecb7d1..3c21639 100644
--- a/p2pvr/daemon/maintenance/network.cpp
+++ b/p2pvr/daemon/maintenance/network.cpp
@@ -5,7 +5,6 @@
#include <Ice/Communicator.h>
#include <p2Helpers.h>
#include <containerIterator.h>
-#include <singleIterator.h>
#include <temporaryIceAdapterObject.h>
class SiNetworkInformationMerger : public SiNetworkInformationParser {
@@ -39,15 +38,9 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser {
mergeTransports.loadComplete(commonObjects);
mergeTransports.execute(NULL);
- SqlMergeTask mergeDvbt("postgres", "delivery_dvbt");
- CreateColumns<DVBSI::TerrestrialDeliveryPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeDvbt, _1, _2));
- for (const auto & s : n->TransportStreams) {
- if (s->Terrestrial) {
- mergeDvbt.sources.insert(new SingleIterator<DVBSI::TerrestrialDeliveryPtr>(&s->Terrestrial));
- }
- }
- mergeDvbt.loadComplete(commonObjects);
- mergeDvbt.execute(NULL);
+ mergeDelivery<DVBSI::TerrestrialDeliveryPtr, &DVBSI::NetworkTransportStream::Terrestrial>("delivery_dvbt", n);
+ mergeDelivery<DVBSI::SatelliteDeliveryPtr, &DVBSI::NetworkTransportStream::Satellite>("delivery_dvbs", n);
+ mergeDelivery<DVBSI::CableDeliveryPtr, &DVBSI::NetworkTransportStream::Cable>("delivery_dvbc", n);
SqlMergeTask mergeServices("postgres", "services");
CreateColumns<DVBSI::NetworkService>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeServices, _1, _2));
@@ -59,6 +52,21 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser {
return false;
}
private:
+ template <class Delivery, Delivery DVBSI::NetworkTransportStream::*member>
+ void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n)
+ {
+ SqlMergeTask merge("postgres", table);
+ 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.loadComplete(commonObjects);
+ merge.execute(NULL);
+ }
DatabaseClient * commonObjects;
};
diff --git a/p2pvr/lib/singleIterator.h b/p2pvr/lib/singleIterator.h
deleted file mode 100644
index acbe50b..0000000
--- a/p2pvr/lib/singleIterator.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef SINGLEITERATOR_H
-#define SINGLEITERATOR_H
-
-#include <iHaveSubTasks.h>
-#include "objectRowState.h"
-
-template <typename T>
-class SingleIterator : public IHaveSubTasks {
- public:
- SingleIterator(const T * i) :
- SourceObject(__PRETTY_FUNCTION__),
- IHaveSubTasks(NULL),
- binder(boost::bind(&BindColumns<T>, _1, _2)),
- item(i)
- {
- }
-
- void execute(ExecContext * ec) const
- {
- ObjectRowState<T> rs;
- binder(rs, *item);
- rs.process(boost::bind(&SingleIterator::executeChildren, this, ec));
- }
-
- private:
- boost::function<void(RowState &, const T &)> binder;
- const T * item;
-
- void executeChildren(ExecContext * ec) const
- {
- for (const Tasks::value_type & sq : normal) {
- sq->execute(ec);
- }
- }
-};
-
-#endif
-