diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-27 02:41:29 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-13 17:29:49 +0100 |
commit | 33a8b31afd92bf6c51b665fa95cb3662e8e60038 (patch) | |
tree | 579067c3603768d7972f218364ef0ac3679a74cf /p2pvr/daemon | |
parent | Add deps on sql (diff) | |
download | p2pvr-33a8b31afd92bf6c51b665fa95cb3662e8e60038.tar.bz2 p2pvr-33a8b31afd92bf6c51b665fa95cb3662e8e60038.tar.xz p2pvr-33a8b31afd92bf6c51b665fa95cb3662e8e60038.zip |
Move some bits from lib into more focused parts
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r-- | p2pvr/daemon/Jamfile.jam | 1 | ||||
-rw-r--r-- | p2pvr/daemon/containerIterator.h | 40 | ||||
-rw-r--r-- | p2pvr/daemon/objectRowState.cpp | 89 | ||||
-rw-r--r-- | p2pvr/daemon/objectRowState.h | 48 | ||||
-rw-r--r-- | p2pvr/daemon/resources.h | 12 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/Jamfile.jam | 2 |
6 files changed, 191 insertions, 1 deletions
diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam index e9c7327..8a9bc7f 100644 --- a/p2pvr/daemon/Jamfile.jam +++ b/p2pvr/daemon/Jamfile.jam @@ -22,6 +22,7 @@ lib p2pvrdaemon : <library>../daemonbase//p2pvrdaemonbase <implicit-dependency>../../libtmdb//tmdb <library>slicer + <include>. : : <include>. <library>../ice//p2pvrice diff --git a/p2pvr/daemon/containerIterator.h b/p2pvr/daemon/containerIterator.h new file mode 100644 index 0000000..14c339d --- /dev/null +++ b/p2pvr/daemon/containerIterator.h @@ -0,0 +1,40 @@ +#ifndef CONTAINERITERATOR_H +#define CONTAINERITERATOR_H + +#include <iHaveSubTasks.h> +#include "objectRowState.h" + +template <typename T> +class ContainerIterator : public IHaveSubTasks { + public: + ContainerIterator(const T * con, const SelectedColumns & sc) : + SourceObject(__PRETTY_FUNCTION__), + IHaveSubTasks(NULL), + binder(boost::bind(&BindColumns<typename T::value_type>, _1, sc, _2)), + container(con) + { + } + + void execute(ExecContext * ec) const + { + ObjectRowStateTmpl<typename T::value_type> rs; + for (const auto & i : *container) { + binder(rs, i); + rs.process(boost::bind(&ContainerIterator::executeChildren, this, ec)); + } + } + + private: + boost::function<void(RowState &, const typename T::value_type &)> binder; + const T * container; + + void executeChildren(ExecContext * ec) const + { + for (const Tasks::value_type & sq : normal) { + sq->execute(ec); + } + } +}; + +#endif + diff --git a/p2pvr/daemon/objectRowState.cpp b/p2pvr/daemon/objectRowState.cpp new file mode 100644 index 0000000..89e5ac8 --- /dev/null +++ b/p2pvr/daemon/objectRowState.cpp @@ -0,0 +1,89 @@ +#include "objectRowState.h" +#include <logger.h> + +const std::string md_mergeKey("merge:key"); +const std::string md_mergeOmit("merge:omit"); + +bool +mdHasFlag(const std::list<std::string> & md, const std::string & flag) +{ + return std::find(md.begin(), md.end(), flag) != md.end(); +} + +SelectedColumns +CreateColumns(Slicer::ModelPartPtr mp, const ColumnCreator & cc) +{ + SelectedColumns cols; + mp->OnEachChild([cc,&cols](const std::string & name, Slicer::ModelPartPtr, Slicer::HookCommonPtr h) { + auto & md = h->GetMetadata(); + 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, + public Slicer::TValueTarget<boost::posix_time::time_duration>, + public Slicer::TValueTarget<boost::posix_time::ptime> { + public: + SqlTarget(VariableType & v) : vt(v) {} + +#define BIND(Type) \ + virtual void get(const Type & t) const override { vt = t; } + BIND(bool); + BIND(::Ice::Byte); + BIND(::Ice::Short); + BIND(::Ice::Int); + BIND(::Ice::Long); + BIND(::Ice::Float); + BIND(::Ice::Double); + BIND(::std::string); + BIND(boost::posix_time::ptime); + BIND(boost::posix_time::time_duration); + + private: + VariableType & vt; +}; +typedef IceUtil::Handle<SqlTarget> SqlTargetPtr; + +void +BindColumns(Slicer::ModelPartPtr mp, const SelectedColumns & sc, RowState & rs) +{ + unsigned int field = 0; + 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); + } + else { + rs.fields[field++] = Null(); + } + }); +} + +ObjectRowState::ObjectRowState(const ColumnSpecifier & cs) : + columns(ColumnCreatorHelper(cs)) +{ + fields.resize(columns.size()); +} + +const Columns & +ObjectRowState::getColumns() const +{ + return columns; +} + +Columns +ObjectRowState::ColumnCreatorHelper(const ColumnSpecifier & cs) +{ + int index = 0; + Columns columns; + cs([&columns, &index](const std::string & name, bool) { + columns.insert(new Column(index++, name)); + }); + return columns; +} + diff --git a/p2pvr/daemon/objectRowState.h b/p2pvr/daemon/objectRowState.h new file mode 100644 index 0000000..3e3fd2f --- /dev/null +++ b/p2pvr/daemon/objectRowState.h @@ -0,0 +1,48 @@ +#ifndef OBJECT_ROW_STATE_H +#define OBJECT_ROW_STATE_H + +#include <boost/function.hpp> +#include <string> +#include <rowSet.h> +#include <slicer/modelParts.h> + +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, const SelectedColumns &, RowState &); + +template <typename V> +void BindColumns(RowState & rs, const SelectedColumns & sc, const V & v) +{ + BindColumns(Slicer::ModelPartFor(const_cast<V &>(v)), sc, rs); +} + +SelectedColumns CreateColumns(Slicer::ModelPartPtr, const ColumnCreator &); + +template <typename V> +SelectedColumns CreateColumns(const ColumnCreator & cc) +{ + V v; + return CreateColumns(Slicer::ModelPartFor(v), cc); +} + +class ObjectRowState : public RowState { + public: + ObjectRowState(const ColumnSpecifier & cs); + const Columns & getColumns() const; + + private: + static Columns ColumnCreatorHelper(const ColumnSpecifier & cs); + + Columns columns; +}; + +template <typename T> +class ObjectRowStateTmpl : public ObjectRowState { + public: + ObjectRowStateTmpl(const ColumnSpecifier & cs = CreateColumns<T>) : ObjectRowState(cs) {} +}; + +#endif + diff --git a/p2pvr/daemon/resources.h b/p2pvr/daemon/resources.h new file mode 100644 index 0000000..18b1de2 --- /dev/null +++ b/p2pvr/daemon/resources.h @@ -0,0 +1,12 @@ +#ifndef RESOURCES_H +#define RESOURCES_H + +#define ResourceString(name, resource) \ +extern "C" { \ + extern char resource##_start, resource##_end;\ + extern unsigned int resource##_len; \ +} \ +static const std::string name(&resource##_start, &resource##_end); + +#endif + diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index d95db07..28d4fbd 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -26,7 +26,7 @@ run : : : <define>BOOST_TEST_DYN_LINK <library>../..//boost_utf - <library>../../lib//p2pvrlib + <include>.. : testEmbedding ; run |