summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-12-10 22:23:38 +0000
committerrandomdan <randomdan@localhost>2013-12-10 22:23:38 +0000
commit82ed8beb41e9b9c96f4f16177578544dd02c6a79 (patch)
treeeb28bd8be824da2613545eeb1acf5a73665d0200
parentExtend interface to support getting a tuner device count (diff)
downloadp2pvr-82ed8beb41e9b9c96f4f16177578544dd02c6a79.tar.bz2
p2pvr-82ed8beb41e9b9c96f4f16177578544dd02c6a79.tar.xz
p2pvr-82ed8beb41e9b9c96f4f16177578544dd02c6a79.zip
Centralise the DB code
-rw-r--r--p2pvr/lib/dbClient.cpp22
-rw-r--r--p2pvr/lib/dbClient.h18
-rw-r--r--p2pvr/lib/si.cpp19
-rw-r--r--p2pvr/lib/si.h10
4 files changed, 42 insertions, 27 deletions
diff --git a/p2pvr/lib/dbClient.cpp b/p2pvr/lib/dbClient.cpp
new file mode 100644
index 0000000..e085c86
--- /dev/null
+++ b/p2pvr/lib/dbClient.cpp
@@ -0,0 +1,22 @@
+#include "dbClient.h"
+#include <rdbmsDataSource.h>
+#include <sqlVariableBinder.h>
+
+DatabaseClient::SelectPtr
+DatabaseClient::Select(const std::string & sql) const
+{
+ auto db = dataSource<RdbmsDataSource>("postgres");
+ return SelectPtr(db->getReadonly().newSelectCommand(sql));
+}
+DatabaseClient::SelectPtr
+DatabaseClient::Select(const std::string & sql, const std::list<VariableType> & vs) const
+{
+ SelectPtr sel(Select(sql));
+ unsigned int offset = 0;
+ BOOST_FOREACH(const auto & v, vs) {
+ boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(sel.get(), offset++), v);
+ }
+ return sel;
+}
+
+
diff --git a/p2pvr/lib/dbClient.h b/p2pvr/lib/dbClient.h
new file mode 100644
index 0000000..62dafef
--- /dev/null
+++ b/p2pvr/lib/dbClient.h
@@ -0,0 +1,18 @@
+#ifndef DBCLIENT_H
+#define DBCLIENT_H
+
+#include <commonObjects.h>
+#include <variableType.h>
+#include <list>
+#include <selectcommand.h>
+
+class DatabaseClient : public virtual CommonObjects {
+ public:
+ typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
+ protected:
+ SelectPtr Select(const std::string &) const;
+ SelectPtr Select(const std::string &, const std::list<VariableType> &) const;
+};
+
+#endif
+
diff --git a/p2pvr/lib/si.cpp b/p2pvr/lib/si.cpp
index 98b2316..e63e060 100644
--- a/p2pvr/lib/si.cpp
+++ b/p2pvr/lib/si.cpp
@@ -2,26 +2,7 @@
#include "dvbsiHelpers.h"
#include "sqlContainerCreator.h"
#include <linux/dvb/frontend.h>
-#include <rdbmsDataSource.h>
#include <logger.h>
-#include <sqlVariableBinder.h>
-
-SI::SelectPtr
-SI::Select(const std::string & sql) const
-{
- auto db = dataSource<RdbmsDataSource>("postgres");
- return SelectPtr(db->getReadonly().newSelectCommand(sql));
-}
-SI::SelectPtr
-SI::Select(const std::string & sql, const std::list<VariableType> & vs) const
-{
- SelectPtr sel(Select(sql));
- unsigned int offset = 0;
- BOOST_FOREACH(const auto & v, vs) {
- boost::apply_visitor<const SqlVariableBinder, const VariableType>(SqlVariableBinder(sel.get(), offset++), v);
- }
- return sel;
-}
P2PVR::Deliveries
SI::GetAllDeliveries(short type, const Ice::Current &)
diff --git a/p2pvr/lib/si.h b/p2pvr/lib/si.h
index 508c0fe..053ac77 100644
--- a/p2pvr/lib/si.h
+++ b/p2pvr/lib/si.h
@@ -2,21 +2,15 @@
#define P2PVR_SI_H
#include <p2pvr.h>
-#include <commonObjects.h>
-#include <selectcommand.h>
+#include "dbClient.h"
-class SI : public P2PVR::SI, public virtual CommonObjects {
+class SI : public P2PVR::SI, public DatabaseClient {
public:
- typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
-
P2PVR::Deliveries GetAllDeliveries(short type, const Ice::Current &);
DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &);
DVBSI::DeliveryPtr GetDeliveryForTransport(int id, const Ice::Current &);
DVBSI::ServiceList GetServices(const Ice::Current &);
DVBSI::ServicePtr GetService(int id, const Ice::Current &);
- protected:
- SelectPtr Select(const std::string &) const;
- SelectPtr Select(const std::string &, const std::list<VariableType> &) const;
};
#endif