aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-15 23:28:19 +0200
committerMax Kellermann <max@duempel.org>2012-08-16 00:04:14 +0200
commit3b8532f3fb379c7ecc6b64eecbbf9c824d18e875 (patch)
tree3313a43df3f120b74166749fdd75b07fa89846ba /src/db
parentf45616e5f6f7d6aa0fb5ca90a0599eacddf1166b (diff)
downloadmpd-3b8532f3fb379c7ecc6b64eecbbf9c824d18e875.tar.gz
mpd-3b8532f3fb379c7ecc6b64eecbbf9c824d18e875.tar.xz
mpd-3b8532f3fb379c7ecc6b64eecbbf9c824d18e875.zip
DatabasePlugin: add method ReturnSong()
Allow the plugin to allocate the GetSong() return value.
Diffstat (limited to 'src/db')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx12
-rw-r--r--src/db/SimpleDatabasePlugin.cxx20
-rw-r--r--src/db/SimpleDatabasePlugin.hxx6
3 files changed, 38 insertions, 0 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index 26e7b4b84..e27ca8291 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -56,6 +56,8 @@ public:
virtual void Close() override;
virtual struct song *GetSong(const char *uri_utf8,
GError **error_r) const override;
+ virtual void ReturnSong(struct song *song) const;
+
virtual bool Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,
@@ -191,6 +193,16 @@ ProxyDatabase::GetSong(const char *uri, GError **error_r) const
return nullptr;
}
+void
+ProxyDatabase::ReturnSong(struct song *song) const
+{
+ assert(song != nullptr);
+ assert(song_in_database(song));
+ assert(song_is_detached(song));
+
+ song_free(song);
+}
+
static bool
Visit(struct mpd_connection *connection, const char *uri,
bool recursive, VisitDirectory visit_directory, VisitSong visit_song,
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index c1de70d3e..94318f4e9 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -184,6 +184,10 @@ SimpleDatabase::Open(GError **error_r)
root = directory_new_root();
mtime = 0;
+#ifndef NDEBUG
+ borrowed_song_count = 0;
+#endif
+
GError *error = NULL;
if (!Load(&error)) {
directory_free(root);
@@ -204,6 +208,7 @@ void
SimpleDatabase::Close()
{
assert(root != NULL);
+ assert(borrowed_song_count == 0);
directory_free(root);
}
@@ -219,10 +224,25 @@ SimpleDatabase::GetSong(const char *uri, GError **error_r) const
if (song == NULL)
g_set_error(error_r, db_quark(), DB_NOT_FOUND,
"No such song: %s", uri);
+#ifndef NDEBUG
+ else
+ ++const_cast<unsigned &>(borrowed_song_count);
+#endif
return song;
}
+void
+SimpleDatabase::ReturnSong(gcc_unused struct song *song) const
+{
+ assert(song != nullptr);
+
+#ifndef NDEBUG
+ assert(borrowed_song_count > 0);
+ --const_cast<unsigned &>(borrowed_song_count);
+#endif
+}
+
G_GNUC_PURE
const struct directory *
SimpleDatabase::LookupDirectory(const char *uri) const
diff --git a/src/db/SimpleDatabasePlugin.hxx b/src/db/SimpleDatabasePlugin.hxx
index 7e3f5d2db..2ea5c4925 100644
--- a/src/db/SimpleDatabasePlugin.hxx
+++ b/src/db/SimpleDatabasePlugin.hxx
@@ -38,6 +38,10 @@ class SimpleDatabase : public Database {
time_t mtime;
+#ifndef NDEBUG
+ unsigned borrowed_song_count;
+#endif
+
public:
gcc_pure
struct directory *GetRoot() {
@@ -61,6 +65,8 @@ public:
virtual struct song *GetSong(const char *uri_utf8,
GError **error_r) const override;
+ virtual void ReturnSong(struct song *song) const;
+
virtual bool Visit(const DatabaseSelection &selection,
VisitDirectory visit_directory,
VisitSong visit_song,