aboutsummaryrefslogtreecommitdiffstats
path: root/src/sticker
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-29 17:45:07 +0100
committerMax Kellermann <max@duempel.org>2014-01-29 17:45:07 +0100
commitff87145537f1d71388be8759688235a75fccf373 (patch)
tree252ef8a5faec7ead1ee2c817815a67571022a5da /src/sticker
parent667481c3719bfb1639d330154f82b58b16f26343 (diff)
downloadmpd-ff87145537f1d71388be8759688235a75fccf373.tar.gz
mpd-ff87145537f1d71388be8759688235a75fccf373.tar.xz
mpd-ff87145537f1d71388be8759688235a75fccf373.zip
sticker: don't use classes Directory and Song
Don't depend on the "simple" database plugin. This fixes an assertion failure / crash and allows using stickers with other plugins.
Diffstat (limited to 'src/sticker')
-rw-r--r--src/sticker/SongSticker.cxx24
-rw-r--r--src/sticker/SongSticker.hxx4
2 files changed, 17 insertions, 11 deletions
diff --git a/src/sticker/SongSticker.cxx b/src/sticker/SongSticker.cxx
index 3431a1702..4bcc8979f 100644
--- a/src/sticker/SongSticker.cxx
+++ b/src/sticker/SongSticker.cxx
@@ -21,8 +21,9 @@
#include "SongSticker.hxx"
#include "StickerDatabase.hxx"
#include "db/LightSong.hxx"
-#include "db/Song.hxx"
-#include "db/Directory.hxx"
+#include "db/DatabaseGlue.hxx"
+#include "db/DatabasePlugin.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -66,7 +67,7 @@ sticker_song_get(const LightSong &song)
}
struct sticker_song_find_data {
- Directory *directory;
+ const Database *db;
const char *base_uri;
size_t base_uri_length;
@@ -85,24 +86,29 @@ sticker_song_find_cb(const char *uri, const char *value, void *user_data)
/* should not happen, ignore silently */
return;
- Song *song = data->directory->LookupSong(uri + data->base_uri_length);
- if (song != nullptr)
- data->func(song->Export(), value, data->user_data);
+ const Database *db = data->db;
+ const LightSong *song = db->GetSong(uri, IgnoreError());
+ if (song != nullptr) {
+ data->func(*song, value, data->user_data);
+ db->ReturnSong(song);
+ }
}
bool
-sticker_song_find(Directory &directory, const char *name,
+sticker_song_find(const char *base_uri, const char *name,
void (*func)(const LightSong &song, const char *value,
void *user_data),
void *user_data)
{
struct sticker_song_find_data data;
- data.directory = &directory;
+ data.db = GetDatabase();
+ assert(data.db != nullptr);
+
data.func = func;
data.user_data = user_data;
char *allocated;
- data.base_uri = directory.GetPath();
+ data.base_uri = base_uri;
if (*data.base_uri != 0)
/* append slash to base_uri */
data.base_uri = allocated =
diff --git a/src/sticker/SongSticker.hxx b/src/sticker/SongSticker.hxx
index 2f977bd21..a49674150 100644
--- a/src/sticker/SongSticker.hxx
+++ b/src/sticker/SongSticker.hxx
@@ -72,13 +72,13 @@ sticker_song_get(const LightSong &song);
*
* Caller must lock the #db_mutex.
*
- * @param directory the base directory to search in
+ * @param base_uri the base directory to search in
* @param name the name of the sticker
* @return true on success (even if no sticker was found), false on
* failure
*/
bool
-sticker_song_find(Directory &directory, const char *name,
+sticker_song_find(const char *base_uri, const char *name,
void (*func)(const LightSong &song, const char *value,
void *user_data),
void *user_data);