From aeac3cf27b1b0f016cee83e0a913316ae6d5c5bc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 13 Jan 2016 22:46:57 +0000 Subject: Basic by title folder --- mythfs/service/inodes/byDateDirectory.h | 16 --------- mythfs/service/inodes/byTitleDirectory.cpp | 22 ------------ mythfs/service/inodes/byTitleDirectory.h | 18 ---------- mythfs/service/inodes/filterByTitleDirectory.cpp | 42 ++++++++++++++++++++++ mythfs/service/inodes/filterByTitleDirectory.h | 23 ++++++++++++ mythfs/service/inodes/filteringDirectory.cpp | 27 ++++++++++++++ mythfs/service/inodes/filteringDirectory.h | 24 +++++++++++++ mythfs/service/inodes/groupingByDateDirectory.h | 16 +++++++++ mythfs/service/inodes/groupingByTitleDirectory.cpp | 22 ++++++++++++ mythfs/service/inodes/groupingByTitleDirectory.h | 18 ++++++++++ mythfs/service/recordingsVolume.cpp | 2 +- mythfs/unittests/testMain.cpp | 33 +++++++++++++++++ 12 files changed, 206 insertions(+), 57 deletions(-) delete mode 100644 mythfs/service/inodes/byDateDirectory.h delete mode 100644 mythfs/service/inodes/byTitleDirectory.cpp delete mode 100644 mythfs/service/inodes/byTitleDirectory.h create mode 100644 mythfs/service/inodes/filterByTitleDirectory.cpp create mode 100644 mythfs/service/inodes/filterByTitleDirectory.h create mode 100644 mythfs/service/inodes/filteringDirectory.cpp create mode 100644 mythfs/service/inodes/filteringDirectory.h create mode 100644 mythfs/service/inodes/groupingByDateDirectory.h create mode 100644 mythfs/service/inodes/groupingByTitleDirectory.cpp create mode 100644 mythfs/service/inodes/groupingByTitleDirectory.h diff --git a/mythfs/service/inodes/byDateDirectory.h b/mythfs/service/inodes/byDateDirectory.h deleted file mode 100644 index 945a9d0..0000000 --- a/mythfs/service/inodes/byDateDirectory.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MYTHFS_BYTITLEDIRECTORY_H -#define MYTHFS_BYTITLEDIRECTORY_H - -#include "groupingDirectory.h" - -namespace MythFS { - class ByDateDirectory : public GroupingDirectory { - - protected: - virtual std::string attribute(const MythFS::RecordedPtr &) const; - }; -} - -#endif - - diff --git a/mythfs/service/inodes/byTitleDirectory.cpp b/mythfs/service/inodes/byTitleDirectory.cpp deleted file mode 100644 index 148f441..0000000 --- a/mythfs/service/inodes/byTitleDirectory.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "byTitleDirectory.h" -#include "symlink.h" - -namespace MythFS { - ByTitleDirectory::ByTitleDirectory(DBPrx db) : - GroupingDirectory(db) - { - } - - std::string - ByTitleDirectory::attribute(const MythFS::RecordedPtr & r) const - { - return r->title; - } - - Node::PointerType - ByTitleDirectory::getChild(const std::string & ) const - { - return new Symlink("/"); - } -} - diff --git a/mythfs/service/inodes/byTitleDirectory.h b/mythfs/service/inodes/byTitleDirectory.h deleted file mode 100644 index 2d88b80..0000000 --- a/mythfs/service/inodes/byTitleDirectory.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MYTHFS_BYTITLEDIRECTORY_H -#define MYTHFS_BYTITLEDIRECTORY_H - -#include "groupingDirectory.h" - -namespace MythFS { - class ByTitleDirectory : public GroupingDirectory { - public: - ByTitleDirectory(DBPrx db); - - protected: - std::string attribute(const MythFS::RecordedPtr &) const override; - PointerType getChild(const std::string &) const override; - }; -} - -#endif - diff --git a/mythfs/service/inodes/filterByTitleDirectory.cpp b/mythfs/service/inodes/filterByTitleDirectory.cpp new file mode 100644 index 0000000..25b0e71 --- /dev/null +++ b/mythfs/service/inodes/filterByTitleDirectory.cpp @@ -0,0 +1,42 @@ +#include "filterByTitleDirectory.h" +#include "symlink.h" +#include +#include + +namespace MythFS { + FilterByTitleDirectory::FilterByTitleDirectory(DBPrx db, const std::string & t) : + FilteringDirectory(db), + title(t) + { + } + + std::string + FilterByTitleDirectory::attribute(const MythFS::RecordedPtr & r) const + { + AdHoc::Buffer n; + n.append(r->title); + if (!r->subtitle.empty()) { + n.appendbf(": %s", r->subtitle); + } + n.append(".mpg"); + return n; + } + + Node::PointerType + FilterByTitleDirectory::getChild(const std::string & n) const + { + for (auto r :db->getRecorded()) { + if (attribute(r) == n) { + return new Symlink("/var/store/mythrecordings/" + r->basename); + } + } + throw NetFS::SystemError(ENOENT); + } + + bool + FilterByTitleDirectory::matches(const MythFS::RecordedPtr & r) const + { + return (title == r->title); + } +} + diff --git a/mythfs/service/inodes/filterByTitleDirectory.h b/mythfs/service/inodes/filterByTitleDirectory.h new file mode 100644 index 0000000..31c35fa --- /dev/null +++ b/mythfs/service/inodes/filterByTitleDirectory.h @@ -0,0 +1,23 @@ +#ifndef MYTHFS_FILTERBYTITLE_H +#define MYTHFS_FILTERBYTITLE_H + +#include "filteringDirectory.h" +#include +#include + +namespace MythFS { + class FilterByTitleDirectory : public FilteringDirectory { + public: + FilterByTitleDirectory(DBPrx db, const std::string &); + + protected: + std::string attribute(const MythFS::RecordedPtr &) const; + bool matches(const MythFS::RecordedPtr &) const; + PointerType getChild(const std::string &) const; + + const std::string title; + }; +} + +#endif + diff --git a/mythfs/service/inodes/filteringDirectory.cpp b/mythfs/service/inodes/filteringDirectory.cpp new file mode 100644 index 0000000..efac165 --- /dev/null +++ b/mythfs/service/inodes/filteringDirectory.cpp @@ -0,0 +1,27 @@ +#include "filteringDirectory.h" +#include + +namespace MythFS { + template + FilteringDirectory::FilteringDirectory(DBPrx d) : + db(d) + { + } + + template + NetFS::NameList + FilteringDirectory::getContents() const + { + NetFS::NameList values; + for (auto r : db->getRecorded()) { + if (matches(r)) { + values.push_back(attribute(r)); + } + } + return values; + } + + template class FilteringDirectory; +} + + diff --git a/mythfs/service/inodes/filteringDirectory.h b/mythfs/service/inodes/filteringDirectory.h new file mode 100644 index 0000000..3f6fc68 --- /dev/null +++ b/mythfs/service/inodes/filteringDirectory.h @@ -0,0 +1,24 @@ +#ifndef MYTHFS_FILTERINGDIRECTORY_H +#define MYTHFS_FILTERINGDIRECTORY_H + +#include "abstractDynamicDirectory.h" +#include +#include + +namespace MythFS { + template + class FilteringDirectory : public AbstractDynamicDirectory { + public: + FilteringDirectory(DBPrx db); + + protected: + virtual bool matches(const MythFS::RecordedPtr &) const = 0; + virtual T attribute(const MythFS::RecordedPtr &) const = 0; + NetFS::NameList getContents() const override; + + DBPrx db; + }; +} + +#endif + diff --git a/mythfs/service/inodes/groupingByDateDirectory.h b/mythfs/service/inodes/groupingByDateDirectory.h new file mode 100644 index 0000000..945a9d0 --- /dev/null +++ b/mythfs/service/inodes/groupingByDateDirectory.h @@ -0,0 +1,16 @@ +#ifndef MYTHFS_BYTITLEDIRECTORY_H +#define MYTHFS_BYTITLEDIRECTORY_H + +#include "groupingDirectory.h" + +namespace MythFS { + class ByDateDirectory : public GroupingDirectory { + + protected: + virtual std::string attribute(const MythFS::RecordedPtr &) const; + }; +} + +#endif + + diff --git a/mythfs/service/inodes/groupingByTitleDirectory.cpp b/mythfs/service/inodes/groupingByTitleDirectory.cpp new file mode 100644 index 0000000..4ab4134 --- /dev/null +++ b/mythfs/service/inodes/groupingByTitleDirectory.cpp @@ -0,0 +1,22 @@ +#include "groupingByTitleDirectory.h" +#include "filterByTitleDirectory.h" + +namespace MythFS { + ByTitleDirectory::ByTitleDirectory(DBPrx db) : + GroupingDirectory(db) + { + } + + std::string + ByTitleDirectory::attribute(const MythFS::RecordedPtr & r) const + { + return r->title; + } + + Node::PointerType + ByTitleDirectory::getChild(const std::string & t) const + { + return new FilterByTitleDirectory(db, t); + } +} + diff --git a/mythfs/service/inodes/groupingByTitleDirectory.h b/mythfs/service/inodes/groupingByTitleDirectory.h new file mode 100644 index 0000000..2d88b80 --- /dev/null +++ b/mythfs/service/inodes/groupingByTitleDirectory.h @@ -0,0 +1,18 @@ +#ifndef MYTHFS_BYTITLEDIRECTORY_H +#define MYTHFS_BYTITLEDIRECTORY_H + +#include "groupingDirectory.h" + +namespace MythFS { + class ByTitleDirectory : public GroupingDirectory { + public: + ByTitleDirectory(DBPrx db); + + protected: + std::string attribute(const MythFS::RecordedPtr &) const override; + PointerType getChild(const std::string &) const override; + }; +} + +#endif + diff --git a/mythfs/service/recordingsVolume.cpp b/mythfs/service/recordingsVolume.cpp index c6d8a91..a7d5830 100644 --- a/mythfs/service/recordingsVolume.cpp +++ b/mythfs/service/recordingsVolume.cpp @@ -4,7 +4,7 @@ #include #include "inodes/allDirectory.h" -#include "inodes/byTitleDirectory.h" +#include "inodes/groupingByTitleDirectory.h" #include "openDirectory.h" namespace MythFS { diff --git a/mythfs/unittests/testMain.cpp b/mythfs/unittests/testMain.cpp index f6ec148..a2dfabe 100644 --- a/mythfs/unittests/testMain.cpp +++ b/mythfs/unittests/testMain.cpp @@ -96,5 +96,38 @@ BOOST_AUTO_TEST_CASE( listAll ) BOOST_REQUIRE_EQUAL("/var/store/mythrecordings/1001_20151220233900.mpg", l); } +BOOST_AUTO_TEST_CASE( statByTitle ) +{ + auto a = rv->getattr(re, "/by title"); + BOOST_REQUIRE(S_ISDIR(a.mode)); +} + +BOOST_AUTO_TEST_CASE( listByTitle ) +{ + auto d = rv->opendir(re, "/by title"); + auto ls = d->readdir(); + BOOST_REQUIRE_EQUAL(11, ls.size()); + BOOST_REQUIRE_EQUAL("Have I Got a Bit More News for You", ls.front()); + BOOST_REQUIRE_EQUAL("Insidious", ls.back()); + d->close(); + + auto a = rv->getattr(re, "/by title/Insidious"); + BOOST_REQUIRE(S_ISDIR(a.mode)); +} + +BOOST_AUTO_TEST_CASE( listByTitleInsidious ) +{ + auto d = rv->opendir(re, "/by title/Insidious"); + auto ls = d->readdir(); + BOOST_REQUIRE_EQUAL(1, ls.size()); + BOOST_REQUIRE_EQUAL("Insidious: Chapter 2.mpg", ls.front()); + d->close(); + + auto a = rv->getattr(re, "/by title/Insidious/Insidious: Chapter 2.mpg"); + BOOST_REQUIRE(S_ISLNK(a.mode)); + auto l = rv->readlink(re, "/by title/Insidious/Insidious: Chapter 2.mpg"); + BOOST_REQUIRE_EQUAL("/var/store/mythrecordings/1303_20151202205900.mpg", l); +} + BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3