summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mythfs/service/inodes/filterByTitleDirectory.cpp42
-rw-r--r--mythfs/service/inodes/filterByTitleDirectory.h23
-rw-r--r--mythfs/service/inodes/filteringDirectory.cpp27
-rw-r--r--mythfs/service/inodes/filteringDirectory.h24
-rw-r--r--mythfs/service/inodes/groupingByDateDirectory.h (renamed from mythfs/service/inodes/byDateDirectory.h)0
-rw-r--r--mythfs/service/inodes/groupingByTitleDirectory.cpp (renamed from mythfs/service/inodes/byTitleDirectory.cpp)8
-rw-r--r--mythfs/service/inodes/groupingByTitleDirectory.h (renamed from mythfs/service/inodes/byTitleDirectory.h)0
-rw-r--r--mythfs/service/recordingsVolume.cpp2
-rw-r--r--mythfs/unittests/testMain.cpp33
9 files changed, 154 insertions, 5 deletions
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 <buffer.h>
+#include <exceptions.h>
+
+namespace MythFS {
+ FilterByTitleDirectory::FilterByTitleDirectory(DBPrx db, const std::string & t) :
+ FilteringDirectory<std::string>(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 <myth-models.h>
+#include <myth-db.h>
+
+namespace MythFS {
+ class FilterByTitleDirectory : public FilteringDirectory<std::string> {
+ 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 <algorithm>
+
+namespace MythFS {
+ template<typename T>
+ FilteringDirectory<T>::FilteringDirectory(DBPrx d) :
+ db(d)
+ {
+ }
+
+ template<typename T>
+ NetFS::NameList
+ FilteringDirectory<T>::getContents() const
+ {
+ NetFS::NameList values;
+ for (auto r : db->getRecorded()) {
+ if (matches(r)) {
+ values.push_back(attribute(r));
+ }
+ }
+ return values;
+ }
+
+ template class FilteringDirectory<std::string>;
+}
+
+
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 <myth-models.h>
+#include <myth-db.h>
+
+namespace MythFS {
+ template <typename T>
+ 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/byDateDirectory.h b/mythfs/service/inodes/groupingByDateDirectory.h
index 945a9d0..945a9d0 100644
--- a/mythfs/service/inodes/byDateDirectory.h
+++ b/mythfs/service/inodes/groupingByDateDirectory.h
diff --git a/mythfs/service/inodes/byTitleDirectory.cpp b/mythfs/service/inodes/groupingByTitleDirectory.cpp
index 148f441..4ab4134 100644
--- a/mythfs/service/inodes/byTitleDirectory.cpp
+++ b/mythfs/service/inodes/groupingByTitleDirectory.cpp
@@ -1,5 +1,5 @@
-#include "byTitleDirectory.h"
-#include "symlink.h"
+#include "groupingByTitleDirectory.h"
+#include "filterByTitleDirectory.h"
namespace MythFS {
ByTitleDirectory::ByTitleDirectory(DBPrx db) :
@@ -14,9 +14,9 @@ namespace MythFS {
}
Node::PointerType
- ByTitleDirectory::getChild(const std::string & ) const
+ ByTitleDirectory::getChild(const std::string & t) const
{
- return new Symlink("/");
+ return new FilterByTitleDirectory(db, t);
}
}
diff --git a/mythfs/service/inodes/byTitleDirectory.h b/mythfs/service/inodes/groupingByTitleDirectory.h
index 2d88b80..2d88b80 100644
--- a/mythfs/service/inodes/byTitleDirectory.h
+++ b/mythfs/service/inodes/groupingByTitleDirectory.h
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 <Ice/ObjectAdapter.h>
#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();