aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-22 22:40:42 +0100
committerMax Kellermann <max@duempel.org>2014-01-22 23:01:32 +0100
commita42f9e4ee30bf0d4a09dc5baa5aa9ba9da022988 (patch)
tree8cdb38cc68839c8610936c80de36bae81b530947 /src/db
parentf16db6cd8054bb4722ec6e80fe529b5f2390880f (diff)
downloadmpd-a42f9e4ee30bf0d4a09dc5baa5aa9ba9da022988.tar.gz
mpd-a42f9e4ee30bf0d4a09dc5baa5aa9ba9da022988.tar.xz
mpd-a42f9e4ee30bf0d4a09dc5baa5aa9ba9da022988.zip
LightDirectory: new struct replacing Directory in the DB API
Diffstat (limited to '')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx27
-rw-r--r--src/db/SimpleDatabasePlugin.cxx3
-rw-r--r--src/db/UpnpDatabasePlugin.cxx13
3 files changed, 18 insertions, 25 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index f65e4f3d0..1b5c3e374 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -23,7 +23,8 @@
#include "DatabaseListener.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseError.hxx"
-#include "Directory.hxx"
+#include "PlaylistInfo.hxx"
+#include "LightDirectory.hxx"
#include "LightSong.hxx"
#include "SongFilter.hxx"
#include "Compiler.h"
@@ -71,7 +72,6 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
unsigned port;
struct mpd_connection *connection;
- Directory *root;
/* this is mutable because GetStats() must be "const" */
mutable time_t update_stamp;
@@ -328,7 +328,6 @@ ProxyDatabase::Open(Error &error)
if (!Connect(error))
return false;
- root = Directory::NewRoot();
update_stamp = 0;
return true;
@@ -337,8 +336,6 @@ ProxyDatabase::Open(Error &error)
void
ProxyDatabase::Close()
{
- delete root;
-
if (connection != nullptr)
Disconnect();
}
@@ -515,13 +512,13 @@ ProxyDatabase::ReturnSong(const LightSong *_song) const
}
static bool
-Visit(struct mpd_connection *connection, Directory &root, const char *uri,
+Visit(struct mpd_connection *connection, const char *uri,
bool recursive, const SongFilter *filter,
VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error);
static bool
-Visit(struct mpd_connection *connection, Directory &root,
+Visit(struct mpd_connection *connection,
bool recursive, const SongFilter *filter,
const struct mpd_directory *directory,
VisitDirectory visit_directory, VisitSong visit_song,
@@ -530,11 +527,11 @@ Visit(struct mpd_connection *connection, Directory &root,
const char *path = mpd_directory_get_path(directory);
if (visit_directory &&
- !visit_directory(Directory(path, &root), error))
+ !visit_directory(LightDirectory(path, 0), error))
return false;
if (recursive &&
- !Visit(connection, root, path, recursive, filter,
+ !Visit(connection, path, recursive, filter,
visit_directory, visit_song, visit_playlist, error))
return false;
@@ -561,7 +558,7 @@ Visit(const SongFilter *filter,
}
static bool
-Visit(const struct mpd_playlist *playlist, Directory &root,
+Visit(const struct mpd_playlist *playlist,
VisitPlaylist visit_playlist, Error &error)
{
if (!visit_playlist)
@@ -570,7 +567,7 @@ Visit(const struct mpd_playlist *playlist, Directory &root,
PlaylistInfo p(mpd_playlist_get_path(playlist),
mpd_playlist_get_last_modified(playlist));
- return visit_playlist(p, root, error);
+ return visit_playlist(p, LightDirectory::Root(), error);
}
class ProxyEntity {
@@ -612,7 +609,7 @@ ReceiveEntities(struct mpd_connection *connection)
}
static bool
-Visit(struct mpd_connection *connection, Directory &root, const char *uri,
+Visit(struct mpd_connection *connection, const char *uri,
bool recursive, const SongFilter *filter,
VisitDirectory visit_directory, VisitSong visit_song,
VisitPlaylist visit_playlist, Error &error)
@@ -630,7 +627,7 @@ Visit(struct mpd_connection *connection, Directory &root, const char *uri,
break;
case MPD_ENTITY_TYPE_DIRECTORY:
- if (!Visit(connection, root, recursive, filter,
+ if (!Visit(connection, recursive, filter,
mpd_entity_get_directory(entity),
visit_directory, visit_song, visit_playlist,
error))
@@ -645,7 +642,7 @@ Visit(struct mpd_connection *connection, Directory &root, const char *uri,
break;
case MPD_ENTITY_TYPE_PLAYLIST:
- if (!Visit(mpd_entity_get_playlist(entity), root,
+ if (!Visit(mpd_entity_get_playlist(entity),
visit_playlist, error))
return false;
break;
@@ -702,7 +699,7 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
return ::SearchSongs(connection, selection, visit_song, error);
/* fall back to recursive walk (slow!) */
- return ::Visit(connection, *root, selection.uri.c_str(),
+ return ::Visit(connection, selection.uri.c_str(),
selection.recursive, selection.filter,
visit_directory, visit_song, visit_playlist,
error);
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index 3d947c042..f77d98ea5 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -21,6 +21,7 @@
#include "SimpleDatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseHelpers.hxx"
+#include "LightDirectory.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "SongFilter.hxx"
@@ -265,7 +266,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
}
if (selection.recursive && visit_directory &&
- !visit_directory(*directory, error))
+ !visit_directory(directory->Export(), error))
return false;
return directory->Walk(selection.recursive, selection.filter,
diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx
index 75d3890ed..844a061c8 100644
--- a/src/db/UpnpDatabasePlugin.cxx
+++ b/src/db/UpnpDatabasePlugin.cxx
@@ -29,8 +29,7 @@
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseError.hxx"
-#include "PlaylistVector.hxx"
-#include "Directory.hxx"
+#include "LightDirectory.hxx"
#include "LightSong.hxx"
#include "ConfigData.hxx"
#include "tag/TagBuilder.hxx"
@@ -71,7 +70,6 @@ public:
class UpnpDatabase : public Database {
LibUPnP *m_lib;
UPnPDeviceDirectory *m_superdir;
- Directory *m_root;
public:
static Database *Create(EventLoop &loop, DatabaseListener &listener,
@@ -190,7 +188,6 @@ UpnpDatabase::Open(Error &error)
return false;
}
- m_root = Directory::NewRoot();
// Wait for device answers. This should be consistent with the value set
// in the lib (currently 2)
sleep(2);
@@ -200,7 +197,6 @@ UpnpDatabase::Open(Error &error)
void
UpnpDatabase::Close()
{
- delete m_root;
delete m_superdir;
delete m_lib;
}
@@ -602,9 +598,8 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
case UPnPDirObject::Type::CONTAINER:
if (visit_directory) {
- Directory d((selection.uri + "/" +
- dirent.name).c_str(),
- m_root);
+ const std::string uri = selection.uri + "/" + dirent.name;
+ const LightDirectory d(uri.c_str(), 0);
if (!visit_directory(d, error))
return false;
}
@@ -673,7 +668,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
// pseudo-directory from the list of servers.
if (visit_directory) {
for (auto& server : servers) {
- Directory d(server.getFriendlyName(), m_root);
+ const LightDirectory d(server.getFriendlyName(), 0);
if (!visit_directory(d, error))
return false;
}